fix(hooks): no-op stale property setter calls after dispose#316
Open
mfazekas wants to merge 2 commits into
Open
fix(hooks): no-op stale property setter calls after dispose#316mfazekas wants to merge 2 commits into
mfazekas wants to merge 2 commits into
Conversation
A setter returned by useRiveNumber/useRiveString/etc. can be captured in a stale closure (async callback, timeout) and fire after its property was disposed by a deps change or unmount. The write then hits the disposed hybrid and throws "Cannot set hybrid property ... NativeState is null" - fatal when uncaught in release. Route writes through the liveRef that useDisposableMemo already maintains (nulled at dispose time), the same guard useRiveTrigger uses, so stale writes become safe no-ops. Adds jest regression tests plus an on-device harness test that fails on the unguarded hook.
Mirror useRiveTrigger: instead of silently ignoring a setter call on a missing property, warn with the path and the likely cause (stale closure after unmount vs. instance still loading) so misuse stays visible without crashing. Also reformat with prettier 3.8.3 (the version main resolves; CI lint failed on formatting produced by 3.6.2).
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.
A setter returned by
useRiveNumber/useRiveString/etc. can be captured in a stale closure (async callback, timeout) and fire after its property was disposed by a deps change or unmount. The write then reaches the disposed hybrid and throwsCannot set hybrid property ... NativeState is null— fatal when uncaught in a release app.The fix routes writes through the
liveRefthatuseDisposableMemoalready maintains (nulled at dispose time) — the same guarduseRiveTriggeruses. A write after unmount warns and no-ops (with the path and likely cause) instead of throwing; a write captured before a deps change targets the hook's current property, matchinguseRiveTriggersemantics.propertystays in theuseCallbackdeps so the setter identity still changes with the property.Tests: jest cases for the after-unmount no-op+warn and the deps-change redirect, plus an on-device harness test (
staleSetterWrite.test.tsx) that fails on the unguarded hook — verified on the Android emulator on both backends.