Repository navigation
fix: stop unset data variables resolving to another key's value - #708
Open
stencil-harness[bot] wants to merge 1 commit into
Open
stencil-harness[bot] wants to merge 1 commit into
stencil-harness[bot] wants to merge 1 commit into
Conversation
FixedSizeDictionary.AdjustIndexes restamped every source index with the destination's version, including empty and stale ones. In a child frame an unset @index/@key/@first/@last then pointed at whatever entry sat in that slot, e.g. a data-object key hashing to slot 0, so {{#with this}}{{@index}}{{/with}} rendered that key's value. Only carry over indexes that are live in the source. Also clear BindingContext.WellKnownVariables when a context goes back to the pool, so indexes from a previous use cannot look current again after the data dictionary's byte version wraps. Refs #707 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
This branch has not been deployed
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.



Closes #707
Problem
Each
BindingContextcachesEntryIndexvalues for its data variables (@root,@index,@key,@first,@last, …) inWellKnownVariables. Two things could leave a wrong index in that array:FixedSizeDictionary.AdjustIndexesrestamped every index, including empty and stale ones, with the child dictionary's version. An empty index (slot 0) or a stale one left by an earlier use then looked current in the child, and returned whatever entry sat in that slot under a different key.BindingContextPolicy.Returnnever clearedWellKnownVariables, so a pooled context kept indexes from its last use. Once the dictionary'sbyteversion wraps, those indexes can look current again.Point 1 needs no version wrap. It shows up on the first render whenever a data-object key hashes to slot 0 (string hashes are randomized per process, so which key does this varies from run to run):
Change
FixedSizeDictionary.AdjustIndexes(source/Handlebars/Collections/FixedSizeDictionary.cs) only carries over indexes that are non-empty and current in the source dictionary. All others becomedefault. Readers then fall back to a lookup by key (DataValues), or miss (TryGetValue(in EntryIndex)with version 0).BindingContextPolicy.Return(source/Handlebars/Pools/BindingContext.Pool.cs) clearsWellKnownVariableswithArray.Clear. That costs one 8-element struct clear per returned context.Live indexes are carried over exactly as before.
@index,@keyand the other data variables set by#each, and@rootand@parent, behave the same. No public signatures change. The only behaviour change in the publicAdjustIndexesmethod is that empty or stale indexes no longer turn into "current" ones that point at an unrelated entry.This doesn't depend on #704 or #706 and doesn't conflict with them: it touches different lines.
Tests
DataVariableTests(new, named by capability):UnsetDataVariableInChildFrameDoesNotResolveToAnotherDataKeyreproduces the example above. It picks the slot-0 key at runtime, so the test is deterministic.UnsetDataVariableNeverResolvesToAnotherDataKeyAcrossPooledReuseruns 2000 renders that interleave{{#each}}with a probe template. The probe's data has keys in slot 0 and in@index's home slot.FixedSizeDictionaryTests:AdjustIndexesCarriesLiveIndexes,AdjustIndexesKeepsEmptyIndexesEmptyandAdjustIndexesDropsStaleIndexes.Before the fix, all four new failure-case tests failed:
[WRONG|WRONG|WRONG|WRONG],[][WRONG], and bothAdjustIndexesasserts. After the fix, the full suite passes (2354/2354).The
AdjustIndexeschange alone is enough to make these tests pass. The pool-return clear covers a root frame that reads a leftover index after a version wrap. That path can't be reproduced deterministically through the shared static pool, so no test exercises it directly.Release
This is a bug fix with no API change, so a patch release is enough.
🤖 Generated with Claude Code
Closes #707