fix: shadow properties on dispose to prevent React DEV crash#1298
Draft
mfazekas wants to merge 1 commit intomrousavy:mainfrom
Draft
fix: shadow properties on dispose to prevent React DEV crash#1298mfazekas wants to merge 1 commit intomrousavy:mainfrom
mfazekas wants to merge 1 commit intomrousavy:mainfrom
Conversation
When a HybridObject used as a view prop is disposed, React's DEV-mode profiling (logComponentRender/addObjectDiffToProperties) iterates the object's properties via for...in, accessing getters that throw because NativeState was nulled. The throw during commitPassiveMountEffects corrupts Fabric's scheduler, freezing the app. Before nulling NativeState, shadow all enumerable prototype properties with non-enumerable own properties so for...in skips them. Also define __disposed=true for debugger visibility. On frozen objects (from deepFreezeAndThrowOnMutationInDev), shadowing fails but setNativeState(nullptr) also fails, so property access remains safe. Fixes mrousavy#1296, mitigates mrousavy#1083
|
@mfazekas is attempting to deploy a commit to the Margelo Team on Vercel. A member of the Team first needs to authorize it. |
5 tasks
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.
Before nulling NativeState in dispose(), shadow all enumerable prototype properties with non-enumerable own properties and define `__disposed = true`. This prevents React DEV tooling (`for...in` iteration in `addObjectDiffToProperties` and `deepFreezeAndThrowOnMutationInDev`) from accessing getters on a disposed object, which would throw and crash Fabric's scheduler.
On frozen objects the shadowing fails silently, which is consistent — `setNativeState(nullptr)` also fails on frozen objects, so NativeState stays valid and property access remains safe.
Fixes #1296
Library-level workaround: Libraries can work around this without waiting for this fix by shadowing properties from JS before calling `dispose()`. See rive-app/rive-nitro-react-native#227 for an example `callDispose()` helper.