Skip to content
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

When ref is used in reanimated hook,"RangeError: Maximum call stack size exceeded, js engine: herme" will be triggered #4261

Closed
ThinkerLu opened this issue Mar 23, 2023 · 4 comments
Labels
Needs review Issue is ready to be reviewed by a maintainer Platform: Android This issue is specific to Android Repro provided A reproduction with a snippet of code, snack or repo is provided

Comments

@ThinkerLu
Copy link

ThinkerLu commented Mar 23, 2023

Description

When ref is used in reanimated hook,"RangeError: Maximum call stack size exceeded, js engine: herme" will be triggered.
Code is on https://snack.expo.dev/@thinkerlu/bad-soda

Steps to reproduce

just run it

Snack or a link to a repository

https://snack.expo.dev/@thinkerlu/bad-soda

Reanimated version

3.0.2

React Native version

0.71.1

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Fabric (New Architecture)

Build type

Debug mode

Device

None

Device model

Pixel 6

Acknowledgements

Yes

@ThinkerLu ThinkerLu added the Needs review Issue is ready to be reviewed by a maintainer label Mar 23, 2023
@github-actions github-actions bot added Platform: Android This issue is specific to Android Repro provided A reproduction with a snippet of code, snack or repo is provided labels Mar 23, 2023
@piaskowyk
Copy link
Member

piaskowyk commented Mar 23, 2023

Is it necessary to pass whole object ref to worklet? It is because ref contains circular references.

@ThinkerLu
Copy link
Author

ThinkerLu commented Mar 30, 2023

Is it necessary to pass whole object ref to worklet? It is because ref contains circular references.

But how to reset the offset of scollView synchronously?
https://snack.expo.dev/@thinkerlu/resetoffset

@skam22
Copy link

skam22 commented Apr 5, 2023

@ThinkerLu

You need to pass a callback function defined outside of the worklet for it to work:

export default () => {
  const ref = useRef<FlatList>(null);

  const resetOffset = useCallback(() => {
     ref.current?.scrollToOffset({animated: false, offset: 0});
  },[ref])

  const scrollHandler = useAnimatedScrollHandler({
    onScroll: (event, context) => {
      //reset offset
     runOnJS(resetOffset)()
    },
  });

  return (
    <Reanimated.FlatList
      data={Array(100).fill(0)}
      renderItem={({index}) => (
        <Text style={{backgroundColor: 'white', height: 28}}>{index}</Text>
      )}
      keyExtractor={(_: number, index: number) => index.toString()}
      onScroll={scrollHandler}
      ref={ref}
    />
  );
};

@piaskowyk
Copy link
Member

This issue should be fixed by #4367

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs review Issue is ready to be reviewed by a maintainer Platform: Android This issue is specific to Android Repro provided A reproduction with a snippet of code, snack or repo is provided
Projects
None yet
Development

No branches or pull requests

3 participants