Skip to content

fix: stop useRive returning a disposed view after an Activity reveal - #475

Open
mfazekas wants to merge 1 commit into
mainfrom
fix/use-rive-stale-view-473
Open

mfazekas wants to merge 1 commit into
mainfrom
fix/use-rive-stale-view-473

Conversation

@mfazekas

Copy link
Copy Markdown
Collaborator

Fixes #473

On iOS, Fabric creates a new native view when an <Activity> reveals a RiveView, and RiveView disposes the view it replaced. useRive kept returning that disposed view until the new one was ready (3–7 ms on the simulator), so an effect that re-ran in between threw TypeError: undefined is not a function on play(). Reproduced on an iOS 26.5 simulator in debug and release; Android keeps the same native view across hide and reveal, so it isn't affected.

useRive now resets riveViewRef to undefined as soon as a new node arrives, and ignores an awaitViewReady() result for a node that has since been replaced, which could otherwise publish the older view (or null) over the newer one.

example/__tests__/activity-reveal-view-ref.harness.tsx and the two new cases in useRive.test.ts fail on main and pass with the fix. The Issue473StaleViewRef example page shows it with hide/reveal buttons and a counter of calls on disposed views.

Code that reads the last-rendered riveViewRef in the same tick a new node arrives, before React re-renders, can still see the disposed view; making calls on a disposed view no-ops would close that and is left for a follow-up.

On iOS, Fabric creates a new native view when an <Activity> reveals a
RiveView, and RiveView disposes the view it replaced. useRive kept
returning that disposed view until the new one was ready, so an effect
that re-ran in between threw "undefined is not a function" on play().

useRive now resets riveViewRef to undefined as soon as a new node
arrives, and ignores an awaitViewReady() result for a node that has
since been replaced.

Fixes #473
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useRive keeps returning a disposed view after an <Activity> reveal until the new view is ready

1 participant