Backport: fix scanPrototypesFor cache when class init is in flight#38
Merged
Conversation
The memoization in 7d67a95 caches the merged prototype-chain values per (constructor, key) pair. When `customElements.define` upgrades a pre-existing element mid-class-body, the constructor runs before the subclass's `static <key> = ...` fields have initialized, so the first scan caches a result missing the subclass's own value. All subsequent instances then inherit the wrong merged metadata (e.g. empty assignableAttributes). Track the constructor's own-property status alongside each cached entry and recompute when it flips. Plugin-style in-place mutations to the cached arrays still propagate. Add a regression test in test/supportTest.js. Co-authored-by: Claude Opus 4.7 (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.
Summary
scanPrototypesForentry alongside the constructor'shasOwnProperty(key)status, and invalidates when it flips. Without this, an instance constructed mid-class-init (e.g.customElements.defineupgrading a pre-existing element before the subclass'sstatic <key> = ...field has run) locks in a result missing the subclass's own value, and every subsequent instance inherits the wrong merged metadata.test/supportTest.js.CHANGELOG.mdhunk to match the prior 1.x backports (Memoize scanPrototypesFor to avoid per-instance prototype walks #30, fix KompElement.include dedupe colliding on default-export plugins #35).Test plan
npm test— full suite passes (36 passing), including the four newscanPrototypesForcases.🤖 Generated with Claude Code