fix: useProperty init sets default even when preventDefault is called#157
Merged
Conversation
When a parent uses lift() to listen to property changes without passing the property value to the child, useProperty's initialization event gets preventDefault'd, leaving the host property undefined. Add isInit flag to updater() so initialization bypasses the preventDefault veto while subsequent updates retain the full lift/preventDefault two-way binding semantics.
🦋 Changeset detectedLatest commit: 9ee4a75 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for pionjs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
cristinecula
approved these changes
Jul 2, 2026
Co-authored-by: Cristian Necula <VirusZ@gmail.com>
Contributor
Author
|
And I gotta add a changeset too. |
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.
Problem
When a parent component uses
lift()to listen to a child's property change event without passing the property value to the child (no.prop=${value}binding),useProperty's initialization is blocked bypreventDefault(), leaving the host propertyundefined.This causes
TypeError: Cannot read properties of undefined (reading 'length')crashes in components likecosmoz-omnitable'srenderFooterwhenselectedItemsis never initialized.Root cause
useProperty's constructor callsthis.updater(initialValue)to set the default.updaterdispatches a notification event, and if aliftlistener callsev.preventDefault(), the host property is never set:This is correct for subsequent updates (parent takes over via its own state), but wrong for initialization — the host should always get its default value.
Fix
Add an
isInitflag toupdater()that bypasses thepreventDefaultveto during initialization:Constructor passes
true:This ensures:
liftsyncs parent state)preventDefault/lifttwo-way binding semanticsTest
Added a test reproducing the exact scenario: parent uses
liftwithout passing the property, verifying the child's host gets the default[].