-
Notifications
You must be signed in to change notification settings - Fork 113
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
Navigation twice on the first screen of a modal (only in production app) #847
Comments
I also have this same issue. Same exact thing you are experiencing where a modal sub route is mounted twice, which causes the user to see the initial layout correctly and then see the "slide-in" transition to the same screen. |
Also happens to me as well, the double mounting applies to both Android and iOS. |
#320 UPD: |
Please provide a minimal reproducible demo so I can fix. |
# Why Prevent double renders by cloning state to avoid leaking state between functions. - fix expo/router#838 - fix expo/router#733 - fix expo/router#320 - The issue expo/router#320 has multiple different things linked, but the original case appears to be fixed. - possibly also addresses expo/router#847 <!-- Please describe the motivation for this PR, and link to relevant GitHub issues, forums posts, or feature requests. --> # How - Prevent mutating the input state to avoid invalidating the nested state. # Test Plan - The testing library doesn't seem to support this case. @marklawlor has been tasked with ensuring the original branch can detect the error https://github.com/expo/expo/compare/%40evanbacon/router/fix-838 Just in case the testing library isn't fixed, I ran locally with: - `app/_layout.js`, `app/(a)/_layout.js`, `app/b/_layout.js` ```js import { Slot } from "expo-router"; export default function RootLayout() { return <Slot /> } ``` - `app/(a)/index.js` ```js import { router, useNavigation } from "expo-router"; import { View } from "react-native"; export default function App() { // const navigation = useNavigation(); setTimeout(() => { router.push("/b"); // navigation.push("b"); }); return ( <View /> ); } ``` - `app/b/index.js` ```js import { usePathname } from 'expo-router'; import { Text, View } from 'react-native'; let i = 0; export default function Page() { const path = usePathname(); i++; return ( <View style={{ flex: 1, backgroundColor: i > 1 ? "red" : "white" }}> <Text>Path: {path}</Text> </View> ); } ``` <!-- Please describe how you tested this change and how a reviewer could reproduce your test, especially if this PR does not include automated tests! If possible, please also provide terminal output and/or screenshots demonstrating your test/reproduction. --> # Checklist <!-- Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules. --> - [ ] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Expo Bot <[email protected]>
A possible fix was published in |
I can confirm this is fixed in |
please this issue still persists on v3.5.23 |
# Why Prevent double renders by cloning state to avoid leaking state between functions. - fix expo/router#838 - fix expo/router#733 - fix expo/router#320 - The issue expo/router#320 has multiple different things linked, but the original case appears to be fixed. - possibly also addresses expo/router#847 <!-- Please describe the motivation for this PR, and link to relevant GitHub issues, forums posts, or feature requests. --> # How - Prevent mutating the input state to avoid invalidating the nested state. # Test Plan - The testing library doesn't seem to support this case. @marklawlor has been tasked with ensuring the original branch can detect the error https://github.com/expo/expo/compare/%40evanbacon/router/fix-838 Just in case the testing library isn't fixed, I ran locally with: - `app/_layout.js`, `app/(a)/_layout.js`, `app/b/_layout.js` ```js import { Slot } from "expo-router"; export default function RootLayout() { return <Slot /> } ``` - `app/(a)/index.js` ```js import { router, useNavigation } from "expo-router"; import { View } from "react-native"; export default function App() { // const navigation = useNavigation(); setTimeout(() => { router.push("/b"); // navigation.push("b"); }); return ( <View /> ); } ``` - `app/b/index.js` ```js import { usePathname } from 'expo-router'; import { Text, View } from 'react-native'; let i = 0; export default function Page() { const path = usePathname(); i++; return ( <View style={{ flex: 1, backgroundColor: i > 1 ? "red" : "white" }}> <Text>Path: {path}</Text> </View> ); } ``` <!-- Please describe how you tested this change and how a reviewer could reproduce your test, especially if this PR does not include automated tests! If possible, please also provide terminal output and/or screenshots demonstrating your test/reproduction. --> # Checklist <!-- Please check the appropriate items below if they apply to your diff. This is required for changes to Expo modules. --> - [ ] Documentation is up to date to reflect these changes (eg: https://docs.expo.dev and README.md). - [ ] Conforms with the [Documentation Writing Style Guide](https://github.com/expo/expo/blob/main/guides/Expo%20Documentation%20Writing%20Style%20Guide.md) - [ ] This diff will work correctly for `npx expo prebuild` & EAS Build (eg: updated a module plugin). --------- Co-authored-by: Expo Bot <[email protected]>
Which package manager are you using? (Yarn is recommended)
yarn
Summary
As you can see in the video, when i open a modal that have a stack inside, i get a bug where it navigate twice to the first screen. It only happens in production/built app. I can't reproduce the problem locally to try and debug it so a bit stuck.
RPReplay_Final1692348709.mov
the structure is :
app option layout
the modal has this options:
and the Stack inside the modal:
Minimal reproducible example
can't reproduce in local dev so not sure what to show here. still is an issue tho :/
potentially linked to #838
UPDATE:
still trying to understand but managed to get something locally by removing the modal presentation.
I tried to remove the screenOptions on the Stack inside the modal (bug still happens)
if i use a Slot instead of Stack, it seems to fix the issue (at this point there is basically no more Stack inside the Stack since no modal and it's Slot so useless _layout in
accounts/wallets/create
from what i can understand locally (not much lol)
it looks like the screen
accounts/wallets/create/name
is mounted once, then the stackaccounts/wallets/create/_layout
get mounted which trigger to mountaccounts/wallets/create/name
again in the stack, which explain the double nav happening.in local, only happen if i remove the presentation: modal but on production app, the bug appear with the modal presentation on.
The text was updated successfully, but these errors were encountered: