fix scanPrototypesFor cache when class init is in flight#37
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>
1 task
bemky
added a commit
that referenced
this pull request
May 7, 2026
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>
4 tasks
bemky
added a commit
that referenced
this pull request
May 11, 2026
* main: fix scanPrototypesFor cache when class init is in flight (#37)
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
Fixes a regression introduced by 7d67a95 (
memoize scanPrototypesFor to avoid per-instance prototype walks). The memoization caches the merged prototype-chain values per(constructor, key)pair, but whencustomElements.define(called bystatic { this.define() }) upgrades a pre-existing element mid-class-body, the constructor fires before the subclass'sstatic <key> = ...field initializers run. The first scan caches a result missing the subclass's own value, and every subsequent instance then inherits the wrong merged metadata — e.g. an emptyassignableAttributes.Discovered when adding the new
Masonrycomponent (#36): if a<komp-masonry>element exists in the DOM at script load, the upgrade triggers the constructor beforestatic assignableAttributes = {...}runs, and the cache locks in[{}](justKompElement's default).The fix tracks
obj.hasOwnProperty(key)alongside each cached entry and invalidates when it flips. Plugin-style in-place mutations to the cached arrays still propagate, so the existingthis.events.push(...)pattern continues to work.Test plan
npm test— 37 passing, including newsupportTest.jsregression coverage<komp-masonry>rendered before the script imports), confirmassignableAttributesare now resolved on first instance🤖 Generated with Claude Code