Skip to content

cherry-pick(worklets-0.10-stable): tie RNR remote function lifetime to TurboModule invalidate status (#9789)#9800

Merged
tjzel merged 1 commit into
worklets-0.10-stablefrom
@tjzel/worklets-0.10-stable/cherry-pick-#9789
Jul 1, 2026
Merged

cherry-pick(worklets-0.10-stable): tie RNR remote function lifetime to TurboModule invalidate status (#9789)#9800
tjzel merged 1 commit into
worklets-0.10-stablefrom
@tjzel/worklets-0.10-stable/cherry-pick-#9789

Conversation

@tjzel

@tjzel tjzel commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Cherry-picking #9789

…date status (#9789)

## Summary

Fixes #9751

Changing (again) how RN Runtime remote functions (RFs) are managed,
since changes from #9673 and #9272 were actually insufficient and the
map approach won't work.

It's impossible to keep both the actual callback and cached serialized
callback value alive without a memory cycle, so I'm dropping cache
consistency. This might result in multiple serializations of a given RF
the GC triggered and the serialized value wasn't saved, but the
serialization of a RF is actually cheap.

I'm dropping the map approach entirely in favor of the behavior where
destructor invocation is based upon the information if the runtime is
still alive. We can't directly check it, so I'm depending on the
`invalidate()` method of Turbo Modules - which is supposed to be called
when the runtime is still alive.

## Test plan

You can test it on
[df3e344](df3e344)
commit - there's a special registry there that artificially extends the
lifetime of Remote Functions - click some buttons on the provided
example, then reload the app with R button. The callbacks with persist
and will crash on destructor invocation without the check for `isDead`.

(cherry picked from commit 325a644)
@tjzel tjzel merged commit 7dc7ff6 into worklets-0.10-stable Jul 1, 2026
21 checks passed
@tjzel tjzel deleted the @tjzel/worklets-0.10-stable/cherry-pick-#9789 branch July 1, 2026 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants