Skip to content

Make compatibility fixes opt-out: block-scoped inline partials by default, opt-outs named in exceptions - #692

Merged
stencil-harness[bot] merged 4 commits into
masterfrom
robot/issue-690
Nov 22, 2026
Merged

stencil-harness[bot] merged 4 commits into
masterfrom
robot/issue-690

Conversation

@stencil-harness

@stencil-harness stencil-harness Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes #690

Summary

Per #690, for the next minor release every compatibility flag that gates a bug fix is now an opt-out: the fixed (handlebars.js) behavior is the default, and the flag restores the old behavior. Where the fixed behavior throws, the exception message names the opt-out.

Flag In 2.4.4 After this PR
LegacyStandaloneCaretBehavior (#672) Already opt-out (fix is the default) Default unchanged. The one new exception it can cause now names the flag (see below).
BlockScopedInlinePartials (#673, #688) Opt-in, default false Default true. Set it to false to opt out. The missing-partial exception names the opt-out.
RelaxedHelperNaming Opt-in to a non-handlebars.js extension Unchanged. It isn't a bug fix.
SupportLastInObjectIterations Obsolete, always on Unchanged

Why the existing flag is kept

An earlier revision of this PR replaced BlockScopedInlinePartials with a new LegacyInlinePartialScoping. Since then #688 merged, and 2.4.4 shipped BlockScopedInlinePartials as public API. Removing it now would break code that sets it at compile time. So this PR keeps that property and only flips its default:

  • Code that set BlockScopedInlinePartials = true on 2.4.4 keeps compiling and gets the same behavior.
  • Code that never set it gets handlebars.js scoping.
  • Setting it to false restores the 2.4.x behavior.

What changes for existing users

Output of the templates below with no flag set on 2.4.4, then on this branch with no flag set and with the opt-out:

Template 2.4.4 This branch (default) This branch with BlockScopedInlinePartials = false
{{#*inline "p"}}outer{{/inline}}{{#with .}}{{#*inline "p"}}inner{{/inline}}{{> p}}{{/with}} {{> p}} inner inner inner outer inner inner
{{#with .}}{{#*inline "myPartial"}}success{{/inline}}{{/with}}{{> myPartial}} success throws (message below) success
{{> macros}}{{> button label="OK"}}, where partial macros declares {{#*inline "button"}} <button>OK</button> throws <button>OK</button>

The new exception text:

Referenced partial name 'myPartial' could not be resolved. If you registered the partial on the static Handlebars class, … If 'myPartial' is declared with {{#*inline}} inside a block or another partial, it is only visible within that block; move the declaration to the top level of the template, or set Configuration.Compatibility.BlockScopedInlinePartials = false to restore the previous behavior.

The sentence about the opt-out is added only while scoping is on. If a MissingPartialTemplateHandler is configured, that handler runs instead, as before.

{{^}} exception message

When {{^}} is the inverse separator, {{#if x}}a{{^}}b{{^}}c{{/if}} (or {{#unless x}}a{{else}}b{{^}}c{{/unless}}) fails to compile, where it rendered before the {{^}} fix. The message now reads:

'{{else}}' cannot follow another '{{else}}' in the same 'if' block. A bare '{{^}}' is the inverse separator, equivalent to '{{else}}'; to restore the previous behavior, where it rendered the current context, set Configuration.Compatibility.LegacyStandaloneCaretBehavior = true

This sentence is added only when the second separator really was a {{^}}. A {{else}} after {{else}} keeps the old message. To support this, HelperExpression has a new internal IsStandaloneCaret marker. InverseSeparatorConverter sets it and HelperArgumentAccumulator carries it forward. No other block type throws on a repeated {{^}}.

Migration for users who hit the change

  • Move inline partials that are called after their block to the top level of the template, or register them with RegisterTemplate. Both work in every mode.
  • Or set handlebars.Configuration.Compatibility.BlockScopedInlinePartials = false to get exactly the 2.4.x default behavior. The flag is read at compile time, so set it before calling Compile.
  • To roll back after upgrading: set the flag. No other change is needed.

Release

This is the intentional behavior change #690 asks for, and it goes in the next minor release (2.5.0). Every affected template can get the old behavior back with one flag. Suggested release-notes entries:

Tests

  • InlinePartialTests:
    • The default is now true.
    • Scoping by default: the declaring block only, outer definition restored, visible to nested blocks, #each, last definition wins, custom decorator between inlines, {{#> layout}} partial blocks, repeated renders, and partials declared in an included partial.
    • Legacy behavior is pinned under false.
    • The exception message is checked in both modes.
  • HandlebarsSpecCoverageTests: a repeated {{^}} in #if and #unless names the opt-out and compiles under the legacy flag; a repeated {{else}} does not mention it.
  • After merging master, the full suite passes (2291/2291 on net10.0). The library builds for all target frameworks.

🤖 Generated with Claude Code

Closes #690

stencil-harness Bot and others added 3 commits November 21, 2026 15:34
…inePartialScoping opt-out

Brings in the block-scoped inline partial implementation from #688 (which
added it as the opt-in Compatibility.BlockScopedInlinePartials) and inverts
it: handlebars.js scoping is now the default, and the earlier behavior is
restored with Compatibility.LegacyInlinePartialScoping = true.

The "Referenced partial name '...' could not be resolved" exception now
names the opt-out when it is not set.

Refs #673, #690

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hen {{^}} caused it

With {{^}} treated as the inverse separator, {{#if x}}a{{^}}b{{^}}c{{/if}}
now fails with "'{{else}}' cannot follow another '{{else}}'". When the
offending separator was a bare {{^}}, the message now explains that and
names Compatibility.LegacyStandaloneCaretBehavior as the opt-out.

Refs #690

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rexm

rexm commented Nov 22, 2026

Copy link
Copy Markdown
Member

Resolve merge conflicts

…to true

#688 merged and shipped in 2.4.4 with Compatibility.BlockScopedInlinePartials
as an opt-in. Instead of replacing it with a new LegacyInlinePartialScoping
flag (which would remove a released public property), keep the released
property and flip its default to true. Setting it to false is the opt-out,
and the unresolved-partial exception names that.

Refs #690

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@stencil-harness

Copy link
Copy Markdown
Contributor Author

Merge conflicts are resolved. I merged master into the branch and pushed. pr.view now reports the PR as MERGEABLE; the merge state is BLOCKED while the required checks run.

The conflicts came from #688, which merged and then shipped in 2.4.4 with Compatibility.BlockScopedInlinePartials as a public opt-in. Replacing it with my unreleased LegacyInlinePartialScoping would have removed a released public property. Instead:

  • I kept BlockScopedInlinePartials and changed its default to true. Setting it to false is the opt-out.
  • I dropped LegacyInlinePartialScoping.
  • The "could not be resolved" exception now names Configuration.Compatibility.BlockScopedInlinePartials = false.

Code that set the flag to true on 2.4.4 still compiles and behaves the same. I updated the README, the XML docs, the tests and the PR description to match. After the merge, all 2291 tests pass, and the library builds for all target frameworks.

@sonarqubecloud

Copy link
Copy Markdown

@stencil-harness
stencil-harness Bot merged commit 1cc7339 into master Nov 22, 2026
7 checks passed
@stencil-harness
stencil-harness Bot deleted the robot/issue-690 branch November 22, 2026 19:50
@stencil-harness stencil-harness Bot mentioned this pull request Nov 22, 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.

Invert opt-ins for breaking bug fixes in next minor version release

1 participant