-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix "Reading from _value
directly is only possible on the UI runtime." on fast refresh during library development
#5434
Conversation
_value
directly is only possible on the UI runtime."_value
directly is only possible on the UI runtime."
By the way, I had this same error when I would pass animated styles to a regular React Native view, maybe we can address this too? |
@terrysahaidak Yes, thanks for reminding me about this. I believe this was reported in #5117. We'll try to provide a meaningful error in this case as well. |
_value
directly is only possible on the UI runtime."_value
directly is only possible on the UI runtime." on fast refresh during development
_value
directly is only possible on the UI runtime." on fast refresh during development_value
directly is only possible on the UI runtime." on fast refresh during library development
_value
directly is only possible on the UI runtime." on fast refresh during library development_value\
directly is only possible on the UI runtime." on fast refresh during library development
_value\
directly is only possible on the UI runtime." on fast refresh during library development_value
directly is only possible on the UI runtime." on fast refresh during library development
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🫡
Ha,Ha,Ha,Ha,Ha,Ha,Ha,Ha If you come across this question, please check your code automatically import |
Summary
This PR fixes one of the most annoying errors in Reanimated that often appears during development of the library as well as sometimes in client apps.
Investigation
When mutable is created, we call
registerShareableMapping(mutable, handle)
to store the handle in_shareableCache
.When cloning a worklet, for each mutable in its closure, in
makeShareableCloneRecursive
we obtain the handle using_shareableCache.get
method and skip the execution of the rest of the function body.During a fast refresh, React holds the same instance of the mutable (that's guaranteed by
useRef
) but for some reason_shareableCache
is regenerated and becomes an empty WeakMap.Because of it,
makeShareableCloneRecursive
can't find the handle in_shareableCache
and tries to clone the mutable as if it was a regular JS object.We use
Object.entries
to iterate over the keys which throws an error when_value
property is accessed.Solution
The proposed solution is to simply move the definition of
_shareableCache
to a separate file. During a fast refresh, the contents of this file usually doesn't change (unless you modify this exact file on purpose) so the cache is not recreated which solves the issue.Remarks
I also replaced all calls to
_shareableCache.set
withregisterShareableMapping
which does exactly the same.Test plan
PlatformChecker.ts
return true;
in the implementation ofisReducedMotion()