Skip to content

fix: reconstruct current_path when base template defers before blocks#1320

Draft
jasmith-hs wants to merge 1 commit into
masterfrom
jasmith/fix-current-path-reconstruction-when-base-defers
Draft

fix: reconstruct current_path when base template defers before blocks#1320
jasmith-hs wants to merge 1 commit into
masterfrom
jasmith/fix-current-path-reconstruction-when-base-defers

Conversation

@jasmith-hs

Copy link
Copy Markdown
Contributor

Description

When a Jinja template extends a base that defers a variable before its block definitions, the eager first-pass output was missing the {% set current_path = '...' %} preamble that all other eager extends scenarios include. Without it, the second pass has no base-template path reference, which would break relative path resolution (e.g., {% include %} calls) inside any such base template.

The pathSetter node — responsible for emitting the current_path reconstruction — was only written when resolveBlockStubs() added deferred tokens (i.e., deferred content inside block bodies). It was not written when the base template itself produced deferred tokens before its blocks (preserveBlocks = true). The fix is a one-character condition change: also set pathSetter when preserveBlocks is true.

This is the root cause of internal HubL issue https://github.com/HubSpotProductSupport/ProductSupport/issues/146621.

BRAVE

Backwards Compatibility

No API or behavioral change for non-deferred templates. The fix only applies when preserveBlocks is already true, which only happens in eager mode when the base template itself defers content.

Rollout and Rollback Plan

  • Library change — consumers pick it up on their next version bump
  • Rollback: revert the single condition change in JinjavaInterpreter.java

Automated Testing

  • itDefersSetInBaseBeforeBlock — verifies first-pass output now includes {% set current_path = '...' %}
  • itDefersSetInBaseBeforeBlockSecondPass — verifies the second pass renders correctly once the deferred value is resolved

Verification

  • Run EagerExtendsTagTest locally; both new tests pass

Expect Dependencies to Fail

None expected.


PR description authored by Claude Code

REVIEWERS: Please review both the code changes and the answers above, and validate that they match the expectations for BRAVE

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>
@jasmith-hs jasmith-hs self-assigned this Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant