Fix setAttribute() after mount not updating reflected props (closes #98)#117
Open
DmitrySharabin wants to merge 1 commit into
Open
Fix setAttribute() after mount not updating reflected props (closes #98)#117DmitrySharabin wants to merge 1 commit into
setAttribute() after mount not updating reflected props (closes #98)#117DmitrySharabin wants to merge 1 commit into
Conversation
…98) Port of #109 from `main`. Per the HTML spec, `customElements.define` only reads `Class.observedAttributes` if `attributeChangedCallback` is non-null on the prototype at registration time. The previous `first_constructor_static` hook wired ACB at *first instance construction*, which fires after registration — so the browser snapshotted a `null` ACB and never read `observedAttributes`. `setAttribute` after mount silently dropped its update. Fix: make ACB a regular entry in the props plugin's `provides`, so `addPlugins` lands it on `NudeElement.prototype` before any subclass calls `customElements.define`. Subclasses chain via super, matching the convention used for `connectedCallback` / `disconnectedCallback`. The eager static `observedAttributes` getter on `providesStatic` now runs `defineProps()` lazily — that's the registration-time path. The `setup` hook is gated by `!Object.hasOwn(this, observedAttributes)` so it doesn't re-install when the static getter has already done so. Bonus: this also flips "removeAttribute collapses a reflected prop to its default" green — same root cause. Baseline: 91 → 93 pass / 7 → 5 fail / 4 skip. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
6deab19 to
ed6b090
Compare
e202c15 to
cb8cb73
Compare
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.
Port of #109 from
main. Same root cause, same fix; tests are already in place.Per the HTML spec,
customElements.defineonly readsClass.observedAttributesifattributeChangedCallbackis non-null on the prototype at registration time. Pre-this-PR,first_constructor_staticwired ACB at first instance construction — after registration — so the browser snapshotted anullACB and never readobservedAttributes.setAttributeafter mount silently dropped its update.Fix: make ACB a regular entry in the props plugin's
providessoaddPluginslands it onNudeElement.prototypebefore any subclass callscustomElements.define. The eager staticobservedAttributesgetter onprovidesStaticrunsdefineProps()lazily. Subclasses chain viasuper.attributeChangedCallback(...)— same convention asconnectedCallback.Bonus: also flips "removeAttribute collapses a reflected prop to its default" green — same root cause.
Stacked on #116.
Test plan
npx htest test/index.js→ 93 pass / 5 fail / 4 skip (was 91/7/4)setAttribute()after mount does not update the property on plainreflectprops #98)" and "removeAttribute collapses a reflected prop to its default"🤖 Generated with Claude Code