New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block behaviour has changed in extensions between v2.0.0-beta6 and beta11 #2747
Comments
+1 |
See #2685 . head.pug
layout.pug
sub-layout.pug
page.pug
output page.html (version <= 2.0.0-beta7)
output page.html (version >= 2.0.0-beta8)
|
On my end I am able to fix by scoping the overwriting of nodes that happens in the newer version of the linker; in Unfortunately I am not confident committing a fix to this area, especially as the maintainers are finally making great progress with release candidates happening. On my team this does mean we'll either need to rewrite our uses of this nested-block-across-files approach or we will stick with beta7 for the long term until something happens. Happy to try and contribute a fix but weary because of the timeline. My hack to validate at least that scoping to a file fixes my core scenario:
This does break 3 tests, so likely has side effects; but the underlying issue is that with the rewritten/partially refactored declared block support that shipped in beta 8, the root parent's nodes are overwritten to the eventual children nodes, skipping anything in-between. The reason for the refactoring that the maintainers did was to support scenarios where the same block appears multiple times in a file, a long-time bug. Scenario:
In the multiple-block per file scenario, you legitimately want the nodes of both of these blocks to point at the resolved block nodes, but only because they are in the same file. Here is a comparison for the underlying work: https://github.com/pugjs/pug/compare/pug@2.0.0-beta7...pug%25402.0.0-beta8 Essentially the issue is when the
Since this overwrites the nodes, starting from the root of the tree for the specific block, the first block will end up pointing to the children, canceling out the intermediate nodes, if any, typically interesting content. Reading @ForbesLindesay comments in PR #2687, "The only trouble is, I'm not really sure the output was "wrong" to start with. The issue is that append and prepend only really make sense at the top level of a file. By supporting them in nested locations, we end up creating a block as well as appending to the existing block. The simplest solution would be to disallow append/prepend except at the top level. I'm not confident that won't break some people's use cases though.", the underlying concern here really is that there is undefined behavior supporting some concept of nested prepends and other magic. The scenario that @caikan has is similar to what our team uses it for; our view structure might look like this:
In Thoughts? |
This also speaks to a frustrating aspect of this project. No release / change log. |
The behaviour of blocks has changed and can't seem to find this change documented, so wanted to work out how to get the old behaviour.
When extending something with a block, previously I could declare the block and then reuse it infinitely - this was very useful when having a "content" block as each template would just declare an area where to put it.
This is my example:
base.pug
default.pug
index.pug
In
2.0.0-beta6
, this would get compiled to:However, in
2.0.0-beta11
, this gets compiled to:The text was updated successfully, but these errors were encountered: