react-native-bottom-sheet: [Bug]: Bottom sheet does not always open when React's Strict Mode is enabled
Version
v5
Reanimated Version
v3
Gesture Handler Version
v2
Platforms
iOS, Android
What happened?
When React’s Strict Mode is enabled, the bottom sheet does not always open.
This is unrelated – they are thrown at the same time but do not cause the issue described here. ~The following errors are also thrown, which may be related (more details in https://github.com/software-mansion/react-native-reanimated/issues/6997):~
ERROR Warning: findHostInstance_DEPRECATED is deprecated in StrictMode. findHostInstance_DEPRECATED
was passed an instance of AnimatedComponent(Wrap) which is inside StrictMode. Instead, add a
ref directly to the element you want to reference. Learn more about using refs safely here:
https://react.dev/link/strict-mode-find-node
ERROR Warning: findNodeHandle is deprecated in StrictMode. findNodeHandle was passed an instance of
Wrap which is inside StrictMode. Instead, add a ref directly to the element you want to reference.
Learn more about using refs safely here: https://react.dev/link/strict-mode-find-node
https://github.com/user-attachments/assets/676abe68-94c2-43a8-91ab-c8ce32eba26b
Reproduction steps
Using reproduction repository
- Clone the repository.
- Install dependencies (
yarn install). - Build and run the app (e.g.
yarn ios). - Press on button to open bottom sheet modal.
The bottom sheet modal does not open (most of the time). findHostInstance_DEPRECATED is deprecated in StrictMode and findNodeHandle is deprecated in StrictMode errors are reported.
Self-reproduction
Enable React’s Strict Mode (wrap app components with <StrictMode>...</StrictMode>).
Reproduction sample
https://github.com/winghouchan/react-native-bottom-sheet-strict-mode-mcve
Ignore as Snack is broken, see #2131, but issue needs it other it will be auto-closed
https://snack.expo.dev/@gorhom/bottom-sheet---issue-reproduction-template
Relevant log output
LOG [BottomSheetContainer::handleContainerLayout] height:852
LOG [handlePresent]
LOG [handlePortalOnUnmount] minimized:false forcedDismissed:false
ERROR Warning: findHostInstance_DEPRECATED is deprecated in StrictMode. findHostInstance_DEPRECATED was passed an instance of AnimatedComponent(Wrap) which is inside StrictMode. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: https://react.dev/link/strict-mode-find-node
ERROR Warning: findNodeHandle is deprecated in StrictMode. findNodeHandle was passed an instance of Wrap which is inside StrictMode. Instead, add a ref directly to the element you want to reference. Learn more about using refs safely here: https://react.dev/link/strict-mode-find-node
LOG [BottomSheetView::handleLayout] height:426
LOG [BottomSheetHandleContainer::handleContainerLayout] height:24
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 2
- Comments: 15 (2 by maintainers)
Commits related to this issue
- feat(library): add menu to create collection or note on library screen Notable: - `@gorhom/bottom-sheet` patched to workaround an issue where the sheet would not open. See this issue on GitHub: ht... — committed to winghouchan/hibi by winghouchan 2 years ago
- feat(library): add menu to create collection or note on library screen Notable: - `@gorhom/bottom-sheet` patched to workaround an issue where the sheet would not open. See this issue on GitHub: ht... — committed to winghouchan/hibi by winghouchan 2 years ago
- refactor(devtools): allow opening of storybook via expo dev menu Improvement over the current setup as it was only possible to have either the app or Storybook open at one time. To switch between the... — committed to winghouchan/hibi by winghouchan 2 years ago
thanks for diving into this, i’ll look into it shortly
In my previous comment, I said:
I’ve found this is only partially true. What is true is
animatedHandleHeightbeing theINITIAL_HANDLE_HEIGHT(-999) which causesisHandleHeightCalculatedto remainfalseand thereforeisLayoutCalculatedto befalse. However, it’s not because the value doesn’t change.I added some more logs to reveal more of what is going on. Here are the logs when Strict Mode is disabled:
The log starting with
[BottomSheetHandleContainer::handleContainerLayout]is whereanimatedHandleHeightgets a value set. Note that when deriving the new values inuseAnimatedSnapPoints,handleHeightis still-999. It turns out, there’s another pass of deriving the new values inuseAnimatedSnapPointswhich does have the updatedhandleHeight. When Strict Mode is enabled the second pass does not occur (the logs stop at the first[fun::useAnimatedReaction::MaybeSnapPointChange]).I don’t yet fully understand why the first time the values are derived in
useAnimatedSnapPointsafteranimatedHandleHeightis changed does not have the updatedanimatedHandleHeightand why it requires a second run to get the updated values; or why Strict Mode is affecting this. It may have something to do with how React works, React Native Reanimated doing different pieces of work on different threads and the JS event loop.It may be an issue that’s the responsibility of React Native Reanimated. I’m trying to create an MCVE that’s only uses React Native Reanimated but haven’t successfully done so and am unsure if I will because I’ve found a workaround which means I’ll be de-prioritising further investigation.
The workaround I’ve found is patching
BottomSheetHandleContainerto set theanimatedHandleHeightvalue in a new macro-task by usingsetTimeout(..., 0):Will drop more comments if I continue investigating and find something new. Hope the comments so far have been useful.
@gorhom I’m seeing the same error in the following environment, could you kindly look into this? 🙏
Hmm, the
setTimeoutworkaround doesn’t seem to be foolproof. IfenableDynamicSizingistrueit doesn’t always work (~10% of the time) and a different issue where the sheet takes the height of the screen happens (~30% of the time). Also, attempting to ignore the deprecated API error logs usingLogBox.ignoreLogswhenenableDynamicSizingistruestops the workaround from working at all 😵💫Found there’s a logger 😄
Here are the logs:
Interesting that the portal’s unmount handler is run. Suspect this is a consequence of Strict Mode running Effects twice.