Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent double renders when pushing stacks. (#24147)
# 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 <34669131+expo-bot@users.noreply.github.com>
- Loading branch information