software-mansion / react-native-reanimated

React Native's Animated library reimplemented
https://docs.swmansion.com/react-native-reanimated/
MIT License
8.59k stars 1.26k forks source link

`property is not configurable` when accessing props from worklet callback #6134

Closed kirillzyusko closed 1 week ago

kirillzyusko commented 1 week ago

Description

Hey πŸ‘‹

It seems like after 3.12 there was some breaking changes, so the code like:

import { forwardRef, useCallback } from "react";
import { useAnimatedReaction, useSharedValue } from "react-native-reanimated";

import type React from "react";
import type { ScrollView } from "react-native";

const CustomScrollView = forwardRef<ScrollView, React.PropsWithChildren<{}>>(
  ({ ...rest }, ref) => {
    const input = useSharedValue({ layout: {}, target: 1 });

    const a = useCallback(() => {
      "worklet";

      console.log(rest.snapToOffsets);
    }, [rest.snapToOffsets]);

    useAnimatedReaction(
      () => input.value,
      (current, previous) => {
        a();
      },
      [],
    );

    return null;
  },
);

export default CustomScrollView;

will throw an exception property is not configurable immediately πŸ˜•

I've seen similar issues with useAnimatedStyle hook and the suggestion was to not include static styles into useAnimatedStyle hook. Though my problem is a bit different and I don't see a straightforward solution for that.

Steps to reproduce

  1. Copy & paste code from description into example screen
  2. run example app and go to broken screen

Snack or a link to a repository

-

Reanimated version

3.12.0

React Native version

0.74.0

Platforms

Android, iOS

JavaScript runtime

Hermes

Workflow

React Native

Architecture

Paper (Old Architecture)

Build type

Debug app & dev bundle

Device

iOS simulator

Device model

iPhone 15 Pro

Acknowledgements

Yes

github-actions[bot] commented 1 week ago

Hey! πŸ‘‹

It looks like you've omitted a few important sections from the issue template.

Please complete Snack or a link to a repository section.

github-actions[bot] commented 1 week 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?

kirillzyusko commented 1 week ago

@tjzel just discovered that it looks like it has been fixed in https://github.com/software-mansion/react-native-reanimated/pull/6098 right?

May I kindly ask you to prepare a new patch release for 3.12? (3.12.1 I guess) πŸ™ I think it's a very critical one πŸ˜“

I see that fix was published under 3.13 RC, but I think this issue may affect many projects, that's why I'm asking to prepare a hotfix release. I hope it makes sense what I'm saying πŸ˜…

tjzel commented 1 week ago

Yeah, I think that's a reasonable request. We released it in an RC version because I'm not absolutely certain it works in all scenarios. Have you tried the RC release to see if it works for you?

tjzel commented 1 week ago

Duplicate of #6066

kirillzyusko commented 1 week ago

Have you tried the RC release to see if it works for you?

@tjzel No, not yet. But it was in my To Do list πŸ™ƒ

Though it's worth to note, that I created a patch from your PR and it fixed a problem in my case (but I haven't tested a new RC yet).

We released it in an RC version because I'm not absolutely certain it works in all scenarios.

Well, even if it works not in all scenarios, then later on you can release a new version with additional fixes 😁

I understand, that you want to keep as small as possible releases and don't publish an official release for each new important bug fix, but this commit is actually very important, because it break a compatibility with all old versions (basic functionality works for sure, but I think many people were relying on capturing external objects in closures) πŸ˜”

tjzel commented 1 week ago

No, that's actually not the case here. I'd normally release it in a patch immediately, but I had some reasons regarding the changes in our repo structure that made me postpone it.

However, when I went over them right now it turns out they are actually invalid. I will try to publish the patch later today πŸ˜ƒ

tjzel commented 1 week ago

3.12.1 containing the fix is out!