fix: reconstruct current_path when base template defers before blocks#1321
Draft
jasmith-hs wants to merge 2 commits into
Draft
fix: reconstruct current_path when base template defers before blocks#1321jasmith-hs wants to merge 2 commits into
jasmith-hs wants to merge 2 commits into
Conversation
When a base template defers a variable before its block definitions, the
eager first pass produced output without {% set current_path = '...' %},
leaving the second pass without a base-template path reference. This would
break relative path resolution for any base template using includes or
other path-dependent tags.
The pathSetter was only written when resolveBlockStubs() added deferred
tokens (deferred content inside block bodies). It was not written when
the base template itself produced deferred tokens before its blocks
(preserveBlocks = true). Fix: also set pathSetter when preserveBlocks
is true.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The prior commit widened the path-setter condition to fire whenever
preserveBlocks was true. But preserveBlocks was unsound outside the
extends loop: numDeferredTokensBefore is initialized to 0 and only
advanced inside the `while (!extendParentRoots.isEmpty())` loop, so when
a template had no extend parents the loop never ran and preserveBlocks
collapsed to `deferredTokens.size() > 0`. Any deferred template (for,
import, set, include, ...) then injected a spurious
`{% set current_path = null %}`, breaking 279 tests.
Gate preserveBlocks on an extends having actually been processed
(processedExtendRoots) so the path setter only fires in the
base-template-defers-before-blocks case it was meant for. The
no-extends path falls back to the original resolveBlockStubs growth
check, restoring prior behavior.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
PR description authored by Claude Code.
Base templates that
extendsandseta deferred variable before their blockdefinitions were losing the
current_pathreference across eager passes. The eagerfirst pass emitted output without
{% set current_path = '...' %}, so the second passhad no base-template path to resolve relative includes against, breaking path-dependent
tags in any such base template.
The path setter was only written when
resolveBlockStubs()added deferred tokens(deferred content inside block bodies), not when the base template itself deferred
tokens before its blocks.
This PR contains two commits:
reconstruct current_path when base template defers before blocks— widens thepath-setter condition so it also fires when the base template defers before its blocks.
only reconstruct current_path when an extends actually deferred— fixes aregression from the first commit.
preserveBlockswas unsound outside the extendsloop:
numDeferredTokensBeforestarts at0and is only advanced inside thewhile (!extendParentRoots.isEmpty())loop, so a template with no extend parentsnever entered the loop and
preserveBlockscollapsed todeferredTokens.size() > 0.Any deferred template (
for,import,set,include, ...) then injected a spurious{% set current_path = null %}. The fix gatespreserveBlockson an extends havingactually been processed, so the path setter only fires in the intended
base-template-defers-before-blocks case.
BRAVE
Backwards Compatibility
resolveBlockStubsgrowth check, restoring pre-first-commit behavior.current_pathsetter.Rollout and Rollback Plan
Automated Testing
itDefersSetInBaseBeforeBlock/itDefersSetInBaseBeforeBlockSecondPasscovering the base-defers-before-block case.Verification
{% set current_path = null %}no longer appears in the previously-failing eager tag tests (EagerForTag,EagerImportTag,EagerSetTag,EagerIncludeTag,EagerFromTag, etc.).Expect Dependencies to Fail
REVIEWERS: Please review both the code changes and the answers above, and validate that they match the expectations for BRAVE