Open gaearon opened 12 months ago
Hey! 👋
The issue doesn't seem to contain a minimal reproduction.
Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?
I did :)
This is a known issue, probably we can't solve it. We were considering releasing a set of eslint rules to simplify working with reanimated instead cc @tjzel
Curious, can you share more about what's tricky about it?
Currently, worklets need to be transpiled by Reanimated Babel plugin which, as a side effect, converts all function declarations (function foo() { /* ... */ }
) into following function factories:
var foo = function () {
var _e = [new global.Error(), 1, -27];
var foo = function foo(x) { /* ... */ };
foo.__closure = {};
foo.__initData = _worklet_9810417751380_init_data;
foo.__workletHash = 9810417751380;
foo.__stackDetails = _e;
return foo;
}();
Unfortunately, this breaks hoisting. More details here: https://github.com/software-mansion/react-native-reanimated/issues/4509#issuecomment-1569781301
Hmm, I don't think my issue is about hoisting per se. Let's forget the function declaration and just have this:
const onStuff = () => {
'worklet'
console.log(foo.value)
}
const foo = useSharedValue(0)
This breaks.
However, this works:
const foo = useSharedValue(0)
const onStuff = () => {
'worklet'
console.log(foo.value)
}
I don't quite see why this wouldn't be possible to support yet.
If it's due to the closure, can that be lazy?
E.g. instead of
onStuff.__closure = { foo }
can it be
onStuff.__closure = () => ({ foo })
?
Then by the time it's called it'll be defined.
This seems like an interesting idea. We'll definitely look into it!
Description
This works:
This doesn't:
However, from the perspective of the code inside
onScroll
, this code should be equivalent — the variables have already been declared before it was called.If the Reanimated plugin can't handle it, I think this should be a build error or something. Right now they're just
undefined
.Steps to reproduce
Expected: it works
Actual:
This is definitely broken on Android and iOS. Not sure about web cause I can't get
onScroll
there to fire at all in this example.Snack or a link to a repository
https://github.com/bluesky-social/social-app/tree/reanimated-order-bug
Reanimated version
3.4.2
React Native version
0.72.5
Platforms
Android, iOS
JavaScript runtime
Hermes
Workflow
None
Architecture
Paper (Old Architecture)
Build type
None
Device
None
Device model
No response
Acknowledgements
Yes