feat: add reflect option to useProperty for property-attribute reflection#100
Draft
cristinecula wants to merge 2 commits into
Draft
feat: add reflect option to useProperty for property-attribute reflection#100cristinecula wants to merge 2 commits into
cristinecula wants to merge 2 commits into
Conversation
…tion
- Add reflectingSymbol to symbols.ts for loop guard
- Modify attributeChangedCallback in component.ts to check reflectingSymbol
guard and convert null (attribute removal) to false
- Extend useProperty with optional { reflect: true } third argument that
enables bidirectional property-attribute sync
- Add 9 new tests for reflect behavior (boolean/string reflection, loop
prevention, attribute-to-property sync, initial attribute, preventDefault,
backward compat, lift integration)
- Add 1 new test for attribute removal producing false
✅ Deploy Preview for pionjs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
This was referenced Feb 16, 2026
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
Adds a
reflectoption tousePropertythat enables bidirectional property-attribute synchronization with built-in loop prevention.usePropertywith optional{ reflect: true }third argumentreflectingSymboltosymbols.tsfor loop guardattributeChangedCallbackincomponent.tsto respect the guard and convertnull(attribute removal) tofalseCloses NEO-1055
API
Behavior:
setAttribute/removeAttribute)attributeChangedCallback), sync to the propertySymbol("haunted.reflecting")flag on the host preventsattributeChangedCallbackfrom re-setting the property during reflectionfalse/null/undefined→ remove attribute;true→ set empty string attribute; other values →setAttribute(name, String(value))Changes
1.
src/symbols.ts— NewreflectingSymbolFollows existing
Symbol("haunted.xyz")convention. Symbol keys are handled by the proxy as non-reactive plain properties.2.
src/component.ts—attributeChangedCallbackchangesreflectingSymbolguard: WhenusePropertyreflects a property to an attribute, it setshost[reflectingSymbol] = true. The callback checks this and skips processing, preventing the feedback loop.null → false: Attribute removal now producesfalseinstead ofnull. Verified safe across all existing consumers.3.
src/use-property.ts—reflectoptionUsePropertyOptionsinterface with optionalreflect: booleanattrName,reflect, andlastReflectedfields on the Hook classreflectToAttribute(value)method wrappingsetAttribute/removeAttributeinreflectingSymbolguardupdateProp(): after setting property, callreflectToAttribute()if reflectingupdate(): reflect on re-render when value changed externally (e.g. parent sets property via binding)4. Tests
10 new test cases:
observedAttributes)falseusePropertyunchanged)lift()integrationnull → falseinattributeChangedCallback(in attrs.test.ts)Consumer Migration
Before (manual reflection with feedback loop risk):
After:
Notes
observedAttributesfor attribute → property sync (web platform limitation:observedAttributesis static)observedAttributesreflectingSymbolis set synchronously aroundsetAttribute/removeAttributecalls, so there's no async timing concern