diff --git a/packages/expo-router/CHANGELOG.md b/packages/expo-router/CHANGELOG.md index 3ed52a412bbc4..41c853b175cec 100644 --- a/packages/expo-router/CHANGELOG.md +++ b/packages/expo-router/CHANGELOG.md @@ -25,6 +25,7 @@ - Fix incorrect route generation of array shared groups with brackets ([#27459](https://github.com/expo/expo/pull/27459) by [@marklawlor](https://github.com/marklawlor)) - Remove `jest.fakeTimers()` from `expo-router/testing-library` ([#27512](https://github.com/expo/expo/pull/27512) by [@marklawlor](https://github.com/marklawlor)) - Fix incorrect initial URL on web when using baseUrl ([#27287](https://github.com/expo/expo/pull/27287) by [@marklawlor](https://github.com/marklawlor)) +- Cancel ExpoRouter SplashScreen during test teardown ([#27620](https://github.com/expo/expo/pull/27620) by [@marklawlor](https://github.com/marklawlor)) ### 💡 Others diff --git a/packages/expo-router/build/global-state/router-store.d.ts b/packages/expo-router/build/global-state/router-store.d.ts index 4ea2ebcc51f12..ae7b2783bdf02 100644 --- a/packages/expo-router/build/global-state/router-store.d.ts +++ b/packages/expo-router/build/global-state/router-store.d.ts @@ -19,6 +19,7 @@ export declare class RouterStore { rootState?: ResultState; nextState?: ResultState; routeInfo?: UrlObject; + splashScreenAnimationFrame?: number; navigationRef: NavigationContainerRefWithCurrent; navigationRefSubscription: () => void; rootStateSubscribers: Set<() => void>; @@ -44,6 +45,7 @@ export declare class RouterStore { snapshot: () => this; rootStateSnapshot: () => ResultState; routeInfoSnapshot: () => UrlObject; + cleanup(): void; } export declare const store: RouterStore; export declare function useExpoRouter(): RouterStore; diff --git a/packages/expo-router/build/global-state/router-store.d.ts.map b/packages/expo-router/build/global-state/router-store.d.ts.map index fbef5e2e14a23..25757ced5cf7f 100644 --- a/packages/expo-router/build/global-state/router-store.d.ts.map +++ b/packages/expo-router/build/global-state/router-store.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"router-store.d.ts","sourceRoot":"","sources":["../../src/global-state/router-store.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EAGlC,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D,YAAY,CAAC,KAAK,EAAE,WAAW;IAgB/B,kBAAkB;IAIlB,uEAAuE;IACvE,oBAAoB,eAAgB,MAAM,IAAI,mBAG5C;IACF,gBAAgB,eAAgB,MAAM,IAAI,mBAGxC;IACF,QAAQ,aAEN;IACF,iBAAiB,oBAEf;IACF,iBAAiB,kBAEf;CACH;AAED,eAAO,MAAM,KAAK,aAAoB,CAAC;AAEvC,wBAAgB,aAAa,gBAE5B;AAYD,wBAAgB,iBAAiB,gBAOhC;AAED,wBAAgB,iBAAiB,cAOhC;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,GAAG,GAAG,SAAS,eAQhG"} \ No newline at end of file +{"version":3,"file":"router-store.d.ts","sourceRoot":"","sources":["../../src/global-state/router-store.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EAGlC,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAiC,aAAa,EAAY,MAAM,OAAO,CAAC;AAe/E,OAAO,EAAE,SAAS,EAAyB,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAoB,MAAM,qBAAqB,CAAC;AAE3E,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C;;;;GAIG;AACH,qBAAa,WAAW;IACtB,SAAS,EAAG,SAAS,GAAG,IAAI,CAAC;IAC7B,aAAa,EAAG,aAAa,CAAC;IAC9B,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,OAAO,CAAC,wBAAwB,CAAkB;IAElD,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,0BAA0B,CAAC,EAAE,MAAM,CAAC;IAEpC,aAAa,EAAG,iCAAiC,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC;IACjF,yBAAyB,EAAG,MAAM,IAAI,CAAC;IAEvC,oBAAoB,YAAiB,IAAI,EAAI;IAC7C,gBAAgB,YAAiB,IAAI,EAAI;IAEzC,MAAM,MAAqB;IAC3B,eAAe,MAA8B;IAC7C,MAAM,MAAqB;IAC3B,SAAS,MAAwB;IACjC,IAAI,MAAmB;IACvB,OAAO,MAAsB;IAC7B,OAAO,MAAsB;IAC7B,UAAU,MAAyB;IACnC,UAAU,MAAyB;IACnC,SAAS,MAAwB;IACjC,QAAQ,MAAuB;IAE/B,UAAU,CACR,OAAO,EAAE,cAAc,EACvB,aAAa,EAAE,iCAAiC,CAAC,eAAe,CAAC,aAAa,CAAC,EAC/E,eAAe,CAAC,EAAE,GAAG;IAgGvB,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,SAAS,cAAQ;IAWjD,YAAY,CAAC,KAAK,EAAE,WAAW;IAgB/B,kBAAkB;IAIlB,uEAAuE;IACvE,oBAAoB,eAAgB,MAAM,IAAI,mBAG5C;IACF,gBAAgB,eAAgB,MAAM,IAAI,mBAGxC;IACF,QAAQ,aAEN;IACF,iBAAiB,oBAEf;IACF,iBAAiB,kBAEf;IAEF,OAAO;CAKR;AAED,eAAO,MAAM,KAAK,aAAoB,CAAC;AAEvC,wBAAgB,aAAa,gBAE5B;AAYD,wBAAgB,iBAAiB,gBAOhC;AAED,wBAAgB,iBAAiB,cAOhC;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,GAAG,GAAG,SAAS,eAQhG"} \ No newline at end of file diff --git a/packages/expo-router/build/global-state/router-store.js b/packages/expo-router/build/global-state/router-store.js index 3ed00c71ebd7a..6da083096071a 100644 --- a/packages/expo-router/build/global-state/router-store.js +++ b/packages/expo-router/build/global-state/router-store.js @@ -48,6 +48,7 @@ class RouterStore { rootState; nextState; routeInfo; + splashScreenAnimationFrame; navigationRef; navigationRefSubscription; rootStateSubscribers = new Set(); @@ -118,9 +119,10 @@ class RouterStore { if (!this.hasAttemptedToHideSplash) { this.hasAttemptedToHideSplash = true; // NOTE(EvanBacon): `navigationRef.isReady` is sometimes not true when state is called initially. - requestAnimationFrame(() => - // @ts-expect-error: This function is native-only and for internal-use only. - SplashScreen._internal_maybeHideAsync?.()); + this.splashScreenAnimationFrame = requestAnimationFrame(() => { + // @ts-expect-error: This function is native-only and for internal-use only. + SplashScreen._internal_maybeHideAsync?.(); + }); } let shouldUpdateSubscribers = this.nextState === state; this.nextState = undefined; @@ -182,6 +184,11 @@ class RouterStore { routeInfoSnapshot = () => { return this.routeInfo; }; + cleanup() { + if (this.splashScreenAnimationFrame) { + cancelAnimationFrame(this.splashScreenAnimationFrame); + } + } } exports.RouterStore = RouterStore; exports.store = new RouterStore(); diff --git a/packages/expo-router/build/global-state/router-store.js.map b/packages/expo-router/build/global-state/router-store.js.map index ebcd65d3e33de..5255f95cab2bc 100644 --- a/packages/expo-router/build/global-state/router-store.js.map +++ b/packages/expo-router/build/global-state/router-store.js.map @@ -1 +1 @@ -{"version":3,"file":"router-store.js","sourceRoot":"","sources":["../../src/global-state/router-store.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAIkC;AAClC,iEAAmD;AACnD,iCAA+E;AAE/E,uCAWmB;AACnB,+CAAgD;AAChD,0DAAuE;AAEvE,+DAA2E;AAE3E,0DAA2E;AAC3E,4CAAyC;AAEzC,8CAA2D;AAE3D;;;;GAIG;AACH,MAAa,WAAW;IACtB,SAAS,CAAoB;IAC7B,aAAa,CAAiB;IAC9B,OAAO,CAAsB;IACrB,wBAAwB,GAAY,KAAK,CAAC;IAElD,YAAY,CAAe;IAC3B,SAAS,CAAe;IACxB,SAAS,CAAe;IACxB,SAAS,CAAa;IAEtB,aAAa,CAAoE;IACjF,yBAAyB,CAAc;IAEvC,oBAAoB,GAAG,IAAI,GAAG,EAAc,CA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AEvC,SAAgB,aAAa;IAC3B,OAAO,IAAA,4BAAoB,EAAC,aAAK,CAAC,gBAAgB,EAAE,aAAK,CAAC,QAAQ,EAAE,aAAK,CAAC,QAAQ,CAAC,CAAC;AACtF,CAAC;AAFD,sCAEC;AAED,SAAS,kBAAkB;IACzB,IAAI,aAAK,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE;QACjC,MAAM,YAAY,GAAG,aAAK,CAAC,aAAa,CAAC,YAAY,EAA4B,CAAC;QAElF,IAAI,aAAK,CAAC,SAAS,KAAK,YAAY,EAAE;YACpC,aAAK,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;SACjC;KACF;AACH,CAAC;AAED,SAAgB,iBAAiB;IAC/B,kBAAkB,EAAE,CAAC;IACrB,OAAO,IAAA,4BAAoB,EACzB,aAAK,CAAC,oBAAoB,EAC1B,aAAK,CAAC,iBAAiB,EACvB,aAAK,CAAC,iBAAiB,CACxB,CAAC;AACJ,CAAC;AAPD,8CAOC;AAED,SAAgB,iBAAiB;IAC/B,kBAAkB,EAAE,CAAC;IACrB,OAAO,IAAA,4BAAoB,EACzB,aAAK,CAAC,oBAAoB,EAC1B,aAAK,CAAC,iBAAiB,EACvB,aAAK,CAAC,iBAAiB,CACxB,CAAC;AACJ,CAAC;AAPD,8CAOC;AAED,SAAgB,uBAAuB,CAAC,OAAuB,EAAE,eAAgC;IAC/F,MAAM,aAAa,GAAG,IAAA,kCAAyB,GAAE,CAAC;IAClD,IAAA,eAAO,EACL,GAAG,EAAE,CAAC,aAAK,CAAC,UAAU,CAAC,OAAO,EAAE,aAAa,EAAE,eAAe,CAAC,EAC/D,CAAC,OAAO,EAAE,eAAe,CAAC,CAC3B,CAAC;IACF,aAAa,EAAE,CAAC;IAChB,OAAO,aAAK,CAAC;AACf,CAAC;AARD,0DAQC","sourcesContent":["import {\n NavigationContainerRefWithCurrent,\n getPathFromState,\n useNavigationContainerRef,\n} from '@react-navigation/native';\nimport * as SplashScreen from 'expo-splash-screen';\nimport { useSyncExternalStore, useMemo, ComponentType, Fragment } from 'react';\n\nimport {\n canGoBack,\n canDismiss,\n goBack,\n linkTo,\n navigate,\n dismiss,\n dismissAll,\n push,\n replace,\n setParams,\n} from './routing';\nimport { getSortedRoutes } from './sort-routes';\nimport { UrlObject, getRouteInfoFromState } from '../LocationProvider';\nimport { RouteNode } from '../Route';\nimport { deepEqual, getPathDataFromState } from '../fork/getPathFromState';\nimport { ResultState } from '../fork/getStateFromPath';\nimport { ExpoLinkingOptions, getLinkingConfig } from '../getLinkingConfig';\nimport { getRoutes } from '../getRoutes';\nimport { RequireContext } from '../types';\nimport { getQualifiedRouteComponent } from '../useScreens';\n\n/**\n * This is the global state for the router. It is used to keep track of the current route, and to provide a way to navigate to other routes.\n *\n * There should only be one instance of this class and be initialized via `useInitializeExpoRouter`\n */\nexport class RouterStore {\n routeNode!: RouteNode | null;\n rootComponent!: ComponentType;\n linking?: ExpoLinkingOptions;\n private hasAttemptedToHideSplash: boolean = false;\n\n initialState?: ResultState;\n rootState?: ResultState;\n nextState?: ResultState;\n routeInfo?: UrlObject;\n\n navigationRef!: NavigationContainerRefWithCurrent;\n navigationRefSubscription!: () => void;\n\n rootStateSubscribers = new Set<() => void>();\n storeSubscribers = new Set<() => void>();\n\n linkTo = linkTo.bind(this);\n getSortedRoutes = getSortedRoutes.bind(this);\n goBack = goBack.bind(this);\n canGoBack = canGoBack.bind(this);\n push = push.bind(this);\n dismiss = dismiss.bind(this);\n replace = replace.bind(this);\n dismissAll = dismissAll.bind(this);\n canDismiss = canDismiss.bind(this);\n setParams = setParams.bind(this);\n navigate = navigate.bind(this);\n\n initialize(\n context: RequireContext,\n navigationRef: NavigationContainerRefWithCurrent,\n initialLocation?: URL\n ) {\n // Clean up any previous state\n this.initialState = undefined;\n this.rootState = undefined;\n this.nextState = undefined;\n this.routeInfo = undefined;\n this.linking = undefined;\n this.navigationRefSubscription?.();\n this.rootStateSubscribers.clear();\n this.storeSubscribers.clear();\n\n this.routeNode = getRoutes(context, { ignoreEntryPoints: true });\n\n this.rootComponent = this.routeNode ? getQualifiedRouteComponent(this.routeNode) : Fragment;\n\n // Only error in production, in development we will show the onboarding screen\n if (!this.routeNode && process.env.NODE_ENV === 'production') {\n throw new Error('No routes found');\n }\n\n this.navigationRef = navigationRef;\n\n if (this.routeNode) {\n this.linking = getLinkingConfig(this.routeNode!);\n\n if (initialLocation) {\n this.linking.getInitialURL = () => initialLocation.toString();\n this.initialState = this.linking.getStateFromPath?.(\n initialLocation.pathname + initialLocation.search,\n this.linking.config\n );\n }\n }\n\n // There is no routeNode, so we will be showing the onboarding screen\n // In the meantime, just mock the routeInfo\n if (this.initialState) {\n this.rootState = this.initialState;\n this.routeInfo = this.getRouteInfo(this.initialState);\n } else {\n this.routeInfo = {\n unstable_globalHref: '',\n pathname: '',\n isIndex: false,\n params: {},\n segments: [],\n };\n }\n\n /**\n * Counter intuitively - this fires AFTER both React Navigation's state changes and the subsequent paint.\n * This poses a couple of issues for Expo Router,\n * - Ensuring hooks (e.g. useSearchParams()) have data in the initial render\n * - Reacting to state changes after a navigation event\n *\n * This is why the initial render renders a Fragment and we wait until `onReady()` is called\n * Additionally, some hooks compare the state from both the store and the navigationRef. If the store it stale,\n * that hooks will manually update the store.\n *\n */\n this.navigationRefSubscription = navigationRef.addListener('state', (data) => {\n const state = data.data.state as ResultState;\n\n if (!this.hasAttemptedToHideSplash) {\n this.hasAttemptedToHideSplash = true;\n // NOTE(EvanBacon): `navigationRef.isReady` is sometimes not true when state is called initially.\n requestAnimationFrame(\n () =>\n // @ts-expect-error: This function is native-only and for internal-use only.\n SplashScreen._internal_maybeHideAsync?.()\n );\n }\n\n let shouldUpdateSubscribers = this.nextState === state;\n this.nextState = undefined;\n\n // This can sometimes be undefined when an error is thrown in the Root Layout Route.\n // Additionally that state may already equal the rootState if it was updated within a hook\n if (state && state !== this.rootState) {\n store.updateState(state, undefined);\n shouldUpdateSubscribers = true;\n }\n\n // If the state has changed, or was changed inside a hook we need to update the subscribers\n if (shouldUpdateSubscribers) {\n for (const subscriber of this.rootStateSubscribers) {\n subscriber();\n }\n }\n });\n\n for (const subscriber of this.storeSubscribers) {\n subscriber();\n }\n }\n\n updateState(state: ResultState, nextState = state) {\n store.rootState = state;\n store.nextState = nextState;\n\n const nextRouteInfo = store.getRouteInfo(state);\n\n if (!deepEqual(this.routeInfo, nextRouteInfo)) {\n store.routeInfo = nextRouteInfo;\n }\n }\n\n getRouteInfo(state: ResultState) {\n return getRouteInfoFromState(\n (state: Parameters[0], asPath: boolean) => {\n return getPathDataFromState(state, {\n screens: [],\n ...this.linking?.config,\n preserveDynamicRoutes: asPath,\n preserveGroups: asPath,\n });\n },\n state\n );\n }\n\n // This is only used in development, to show the onboarding screen\n // In production we should have errored during the initialization\n shouldShowTutorial() {\n return !this.routeNode && process.env.NODE_ENV === 'development';\n }\n\n /** Make sure these are arrow functions so `this` is correctly bound */\n subscribeToRootState = (subscriber: () => void) => {\n this.rootStateSubscribers.add(subscriber);\n return () => this.rootStateSubscribers.delete(subscriber);\n };\n subscribeToStore = (subscriber: () => void) => {\n this.storeSubscribers.add(subscriber);\n return () => this.storeSubscribers.delete(subscriber);\n };\n snapshot = () => {\n return this;\n };\n rootStateSnapshot = () => {\n return this.rootState!;\n };\n routeInfoSnapshot = () => {\n return this.routeInfo!;\n };\n}\n\nexport const store = new RouterStore();\n\nexport function useExpoRouter() {\n return useSyncExternalStore(store.subscribeToStore, store.snapshot, store.snapshot);\n}\n\nfunction syncStoreRootState() {\n if (store.navigationRef.isReady()) {\n const currentState = store.navigationRef.getRootState() as unknown as ResultState;\n\n if (store.rootState !== currentState) {\n store.updateState(currentState);\n }\n }\n}\n\nexport function useStoreRootState() {\n syncStoreRootState();\n return useSyncExternalStore(\n store.subscribeToRootState,\n store.rootStateSnapshot,\n store.rootStateSnapshot\n );\n}\n\nexport function useStoreRouteInfo() {\n syncStoreRootState();\n return useSyncExternalStore(\n store.subscribeToRootState,\n store.routeInfoSnapshot,\n store.routeInfoSnapshot\n );\n}\n\nexport function useInitializeExpoRouter(context: RequireContext, initialLocation: URL | undefined) {\n const navigationRef = useNavigationContainerRef();\n useMemo(\n () => store.initialize(context, navigationRef, initialLocation),\n [context, initialLocation]\n );\n useExpoRouter();\n return store;\n}\n"]} \ No newline at end of file +{"version":3,"file":"router-store.js","sourceRoot":"","sources":["../../src/global-state/router-store.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAIkC;AAClC,iEAAmD;AACnD,iCAA+E;AAE/E,uCAWmB;AACnB,+CAAgD;AAChD,0DAAuE;AAEvE,+DAA2E;AAE3E,0DAA2E;AAC3E,4CAAyC;AAEzC,8CAA2D;AAE3D;;;;GAIG;AACH,MAAa,WAAW;IACtB,SAAS,CAAoB;IAC7B,aAAa,CAAiB;IAC9B,OAAO,CAAsB;IACrB,wBAAwB,GAAY,KAAK,CAAC;IAElD,YAAY,CAAe;IAC3B,SAAS,CAAe;IACxB,SAAS,CAAe;IACxB,SAAS,CAAa;IACtB,0BAA0B,CAAU;IAEpC,aAAa,CAAoE;IACjF,yBAAyB,CAAc;IAEvC,oBAAoB,GAAG,IAAI,GAAG,EAAc,CAAC;IAC7C,gBAAgB,GAAG,IAAI,GAAG,EAAc,CAAC;IAEzC,MAAM,GAAG,gBAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,eAAe,GAAG,6BAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7C,MAAM,GAAG,gBAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,SAAS,GAAG,mBAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvB,OAAO,GAAG,iBAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,OAAO,GAAG,iBAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,UA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,SAAS,KAAK,YAAY,EAAE;YACpC,aAAK,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;SACjC;KACF;AACH,CAAC;AAED,SAAgB,iBAAiB;IAC/B,kBAAkB,EAAE,CAAC;IACrB,OAAO,IAAA,4BAAoB,EACzB,aAAK,CAAC,oBAAoB,EAC1B,aAAK,CAAC,iBAAiB,EACvB,aAAK,CAAC,iBAAiB,CACxB,CAAC;AACJ,CAAC;AAPD,8CAOC;AAED,SAAgB,iBAAiB;IAC/B,kBAAkB,EAAE,CAAC;IACrB,OAAO,IAAA,4BAAoB,EACzB,aAAK,CAAC,oBAAoB,EAC1B,aAAK,CAAC,iBAAiB,EACvB,aAAK,CAAC,iBAAiB,CACxB,CAAC;AACJ,CAAC;AAPD,8CAOC;AAED,SAAgB,uBAAuB,CAAC,OAAuB,EAAE,eAAgC;IAC/F,MAAM,aAAa,GAAG,IAAA,kCAAyB,GAAE,CAAC;IAClD,IAAA,eAAO,EACL,GAAG,EAAE,CAAC,aAAK,CAAC,UAAU,CAAC,OAAO,EAAE,aAAa,EAAE,eAAe,CAAC,EAC/D,CAAC,OAAO,EAAE,eAAe,CAAC,CAC3B,CAAC;IACF,aAAa,EAAE,CAAC;IAChB,OAAO,aAAK,CAAC;AACf,CAAC;AARD,0DAQC","sourcesContent":["import {\n NavigationContainerRefWithCurrent,\n getPathFromState,\n useNavigationContainerRef,\n} from '@react-navigation/native';\nimport * as SplashScreen from 'expo-splash-screen';\nimport { useSyncExternalStore, useMemo, ComponentType, Fragment } from 'react';\n\nimport {\n canGoBack,\n canDismiss,\n goBack,\n linkTo,\n navigate,\n dismiss,\n dismissAll,\n push,\n replace,\n setParams,\n} from './routing';\nimport { getSortedRoutes } from './sort-routes';\nimport { UrlObject, getRouteInfoFromState } from '../LocationProvider';\nimport { RouteNode } from '../Route';\nimport { deepEqual, getPathDataFromState } from '../fork/getPathFromState';\nimport { ResultState } from '../fork/getStateFromPath';\nimport { ExpoLinkingOptions, getLinkingConfig } from '../getLinkingConfig';\nimport { getRoutes } from '../getRoutes';\nimport { RequireContext } from '../types';\nimport { getQualifiedRouteComponent } from '../useScreens';\n\n/**\n * This is the global state for the router. It is used to keep track of the current route, and to provide a way to navigate to other routes.\n *\n * There should only be one instance of this class and be initialized via `useInitializeExpoRouter`\n */\nexport class RouterStore {\n routeNode!: RouteNode | null;\n rootComponent!: ComponentType;\n linking?: ExpoLinkingOptions;\n private hasAttemptedToHideSplash: boolean = false;\n\n initialState?: ResultState;\n rootState?: ResultState;\n nextState?: ResultState;\n routeInfo?: UrlObject;\n splashScreenAnimationFrame?: number;\n\n navigationRef!: NavigationContainerRefWithCurrent;\n navigationRefSubscription!: () => void;\n\n rootStateSubscribers = new Set<() => void>();\n storeSubscribers = new Set<() => void>();\n\n linkTo = linkTo.bind(this);\n getSortedRoutes = getSortedRoutes.bind(this);\n goBack = goBack.bind(this);\n canGoBack = canGoBack.bind(this);\n push = push.bind(this);\n dismiss = dismiss.bind(this);\n replace = replace.bind(this);\n dismissAll = dismissAll.bind(this);\n canDismiss = canDismiss.bind(this);\n setParams = setParams.bind(this);\n navigate = navigate.bind(this);\n\n initialize(\n context: RequireContext,\n navigationRef: NavigationContainerRefWithCurrent,\n initialLocation?: URL\n ) {\n // Clean up any previous state\n this.initialState = undefined;\n this.rootState = undefined;\n this.nextState = undefined;\n this.routeInfo = undefined;\n this.linking = undefined;\n this.navigationRefSubscription?.();\n this.rootStateSubscribers.clear();\n this.storeSubscribers.clear();\n\n this.routeNode = getRoutes(context, { ignoreEntryPoints: true });\n\n this.rootComponent = this.routeNode ? getQualifiedRouteComponent(this.routeNode) : Fragment;\n\n // Only error in production, in development we will show the onboarding screen\n if (!this.routeNode && process.env.NODE_ENV === 'production') {\n throw new Error('No routes found');\n }\n\n this.navigationRef = navigationRef;\n\n if (this.routeNode) {\n this.linking = getLinkingConfig(this.routeNode!);\n\n if (initialLocation) {\n this.linking.getInitialURL = () => initialLocation.toString();\n this.initialState = this.linking.getStateFromPath?.(\n initialLocation.pathname + initialLocation.search,\n this.linking.config\n );\n }\n }\n\n // There is no routeNode, so we will be showing the onboarding screen\n // In the meantime, just mock the routeInfo\n if (this.initialState) {\n this.rootState = this.initialState;\n this.routeInfo = this.getRouteInfo(this.initialState);\n } else {\n this.routeInfo = {\n unstable_globalHref: '',\n pathname: '',\n isIndex: false,\n params: {},\n segments: [],\n };\n }\n\n /**\n * Counter intuitively - this fires AFTER both React Navigation's state changes and the subsequent paint.\n * This poses a couple of issues for Expo Router,\n * - Ensuring hooks (e.g. useSearchParams()) have data in the initial render\n * - Reacting to state changes after a navigation event\n *\n * This is why the initial render renders a Fragment and we wait until `onReady()` is called\n * Additionally, some hooks compare the state from both the store and the navigationRef. If the store it stale,\n * that hooks will manually update the store.\n *\n */\n this.navigationRefSubscription = navigationRef.addListener('state', (data) => {\n const state = data.data.state as ResultState;\n\n if (!this.hasAttemptedToHideSplash) {\n this.hasAttemptedToHideSplash = true;\n // NOTE(EvanBacon): `navigationRef.isReady` is sometimes not true when state is called initially.\n this.splashScreenAnimationFrame = requestAnimationFrame(() => {\n // @ts-expect-error: This function is native-only and for internal-use only.\n SplashScreen._internal_maybeHideAsync?.();\n });\n }\n\n let shouldUpdateSubscribers = this.nextState === state;\n this.nextState = undefined;\n\n // This can sometimes be undefined when an error is thrown in the Root Layout Route.\n // Additionally that state may already equal the rootState if it was updated within a hook\n if (state && state !== this.rootState) {\n store.updateState(state, undefined);\n shouldUpdateSubscribers = true;\n }\n\n // If the state has changed, or was changed inside a hook we need to update the subscribers\n if (shouldUpdateSubscribers) {\n for (const subscriber of this.rootStateSubscribers) {\n subscriber();\n }\n }\n });\n\n for (const subscriber of this.storeSubscribers) {\n subscriber();\n }\n }\n\n updateState(state: ResultState, nextState = state) {\n store.rootState = state;\n store.nextState = nextState;\n\n const nextRouteInfo = store.getRouteInfo(state);\n\n if (!deepEqual(this.routeInfo, nextRouteInfo)) {\n store.routeInfo = nextRouteInfo;\n }\n }\n\n getRouteInfo(state: ResultState) {\n return getRouteInfoFromState(\n (state: Parameters[0], asPath: boolean) => {\n return getPathDataFromState(state, {\n screens: [],\n ...this.linking?.config,\n preserveDynamicRoutes: asPath,\n preserveGroups: asPath,\n });\n },\n state\n );\n }\n\n // This is only used in development, to show the onboarding screen\n // In production we should have errored during the initialization\n shouldShowTutorial() {\n return !this.routeNode && process.env.NODE_ENV === 'development';\n }\n\n /** Make sure these are arrow functions so `this` is correctly bound */\n subscribeToRootState = (subscriber: () => void) => {\n this.rootStateSubscribers.add(subscriber);\n return () => this.rootStateSubscribers.delete(subscriber);\n };\n subscribeToStore = (subscriber: () => void) => {\n this.storeSubscribers.add(subscriber);\n return () => this.storeSubscribers.delete(subscriber);\n };\n snapshot = () => {\n return this;\n };\n rootStateSnapshot = () => {\n return this.rootState!;\n };\n routeInfoSnapshot = () => {\n return this.routeInfo!;\n };\n\n cleanup() {\n if (this.splashScreenAnimationFrame) {\n cancelAnimationFrame(this.splashScreenAnimationFrame);\n }\n }\n}\n\nexport const store = new RouterStore();\n\nexport function useExpoRouter() {\n return useSyncExternalStore(store.subscribeToStore, store.snapshot, store.snapshot);\n}\n\nfunction syncStoreRootState() {\n if (store.navigationRef.isReady()) {\n const currentState = store.navigationRef.getRootState() as unknown as ResultState;\n\n if (store.rootState !== currentState) {\n store.updateState(currentState);\n }\n }\n}\n\nexport function useStoreRootState() {\n syncStoreRootState();\n return useSyncExternalStore(\n store.subscribeToRootState,\n store.rootStateSnapshot,\n store.rootStateSnapshot\n );\n}\n\nexport function useStoreRouteInfo() {\n syncStoreRootState();\n return useSyncExternalStore(\n store.subscribeToRootState,\n store.routeInfoSnapshot,\n store.routeInfoSnapshot\n );\n}\n\nexport function useInitializeExpoRouter(context: RequireContext, initialLocation: URL | undefined) {\n const navigationRef = useNavigationContainerRef();\n useMemo(\n () => store.initialize(context, navigationRef, initialLocation),\n [context, initialLocation]\n );\n useExpoRouter();\n return store;\n}\n"]} \ No newline at end of file diff --git a/packages/expo-router/build/testing-library/index.d.ts.map b/packages/expo-router/build/testing-library/index.d.ts.map index a8f77f4067b0d..0c97a64f8de70 100644 --- a/packages/expo-router/build/testing-library/index.d.ts.map +++ b/packages/expo-router/build/testing-library/index.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing-library/index.tsx"],"names":[],"mappings":"AACA,OAAO,UAAU,CAAC;AAElB,OAAO,EAAO,MAAM,EAAwB,MAAM,+BAA+B,CAAC;AAGlF,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AASjF,cAAc,+BAA+B,CAAC;AAE9C,KAAK,mBAAmB,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG;IACxD,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,KAAK,MAAM,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,GAAG;IACxC,WAAW,IAAI,MAAM,CAAC;IACtB,qBAAqB,IAAI,MAAM,CAAC;IAChC,WAAW,IAAI,MAAM,EAAE,CAAC;IACxB,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;CACtD,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC;AAE5D,wBAAgB,YAAY,CAC1B,OAAO,GAAE,iBAA2B,EACpC,EAAE,UAAgB,EAAE,GAAG,OAAO,EAAE,GAAE,mBAAwB,GACzD,MAAM,CAoCR;AAED,eAAO,MAAM,UAAU;IACrB,yDAAyD;mBAC1C,MAAM;IAIrB,yDAAyD;eAC9C,MAAM;IAIjB,6DAA6D;kBAC/C,MAAM;IAIpB,oDAAoD;gBACxC,MAAM;IAOlB,qEAAqE;;IAIrE,wEAAwE;uBACrD,OAAO,MAAM,EAAE,MAAM,CAAC,SAAS,MAAM;IAMxD,qEAAqE;;CAItE,CAAC"} \ No newline at end of file +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing-library/index.tsx"],"names":[],"mappings":"AACA,OAAO,UAAU,CAAC;AAElB,OAAO,EAAO,MAAM,EAAwB,MAAM,+BAA+B,CAAC;AAGlF,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AASjF,cAAc,+BAA+B,CAAC;AAM9C,KAAK,mBAAmB,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG;IACxD,UAAU,CAAC,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,KAAK,MAAM,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,GAAG;IACxC,WAAW,IAAI,MAAM,CAAC;IACtB,qBAAqB,IAAI,MAAM,CAAC;IAChC,WAAW,IAAI,MAAM,EAAE,CAAC;IACxB,eAAe,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;CACtD,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC;AAE5D,wBAAgB,YAAY,CAC1B,OAAO,GAAE,iBAA2B,EACpC,EAAE,UAAgB,EAAE,GAAG,OAAO,EAAE,GAAE,mBAAwB,GACzD,MAAM,CAoCR;AAED,eAAO,MAAM,UAAU;IACrB,yDAAyD;mBAC1C,MAAM;IAIrB,yDAAyD;eAC9C,MAAM;IAIjB,6DAA6D;kBAC/C,MAAM;IAIpB,oDAAoD;gBACxC,MAAM;IAOlB,qEAAqE;;IAIrE,wEAAwE;uBACrD,OAAO,MAAM,EAAE,MAAM,CAAC,SAAS,MAAM;IAMxD,qEAAqE;;CAItE,CAAC"} \ No newline at end of file diff --git a/packages/expo-router/build/testing-library/index.js b/packages/expo-router/build/testing-library/index.js index 6459a6535bff3..8dbeec1863bdc 100644 --- a/packages/expo-router/build/testing-library/index.js +++ b/packages/expo-router/build/testing-library/index.js @@ -33,6 +33,9 @@ const router_store_1 = require("../global-state/router-store"); const imperative_api_1 = require("../imperative-api"); // re-export everything __exportStar(require("@testing-library/react-native"), exports); +afterAll(() => { + router_store_1.store.cleanup(); +}); function renderRouter(context = './app', { initialUrl = '/', ...options } = {}) { const mockContext = (0, mock_config_1.getMockContext)(context); // Reset the initial URL diff --git a/packages/expo-router/build/testing-library/index.js.map b/packages/expo-router/build/testing-library/index.js.map index c7fffae6d3ddf..78c0b7e8eadde 100644 --- a/packages/expo-router/build/testing-library/index.js.map +++ b/packages/expo-router/build/testing-library/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing-library/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,0CAA0C;AAC1C,oBAAkB;AAElB,gEAAkF;AAClF,kDAA0B;AAE1B,+CAAiF;AAsBrD,8FAtBA,2BAAa,OAsBA;AAAE,+FAtBA,4BAAc,OAsBA;AArBzD,mCAAwC;AACxC,0CAAuC;AACvC,gFAAwD;AACxD,0DAAiD;AACjD,+DAAqD;AACrD,sDAA2C;AAE3C,uBAAuB;AACvB,gEAA8C;AAe9C,SAAgB,YAAY,CAC1B,UAA6B,OAAO,EACpC,EAAE,UAAU,GAAG,GAAG,EAAE,GAAG,OAAO,KAA0B,EAAE;IAE1D,MAAM,WAAW,GAAG,IAAA,4BAAc,EAAC,OAAO,CAAC,CAAC;IAE5C,wBAAwB;IACxB,IAAA,qBAAa,EAAC,UAAU,CAAC,CAAC;IAE1B,qCAAqC;IACrC,OAAO,CAAC,GAAG,CAAC,uBAAuB,GAAG,MAAM,CAAC;IAC7C,6BAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,IAAI,QAAyB,CAAC;IAE9B,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;QAClC,QAAQ,GAAG,IAAI,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;KAC3C;SAAM,IAAI,UAAU,YAAY,GAAG,EAAE;QACpC,QAAQ,GAAG,UA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AAC,CAAC;QAChC,MAAM,CAAC,qBAAM,CAAC,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IACD,oDAAoD;IACpD,IAAI,CAAC,IAAa;QAChB,MAAM,CAAC,uBAAM,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtC,IAAA,kBAAG,EAAC,GAAG,EAAE,CAAC,uBAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACzB,IAAI,IAAI,EAAE;YACR,MAAM,CAAC,qBAAM,CAAC,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;SAC/C;IACH,CAAC;IACD,qEAAqE;IACrE,SAAS;QACP,OAAO,uBAAM,CAAC,SAAS,EAAE,CAAC;IAC5B,CAAC;IACD,wEAAwE;IACxE,SAAS,CAAC,MAA+B,EAAE,IAAa;QACtD,uBAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACzB,IAAI,IAAI,EAAE;YACR,MAAM,CAAC,qBAAM,CAAC,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;SAC/C;IACH,CAAC;IACD,qEAAqE;IACrE,UAAU;QACR,IAAA,kBAAG,EAAC,GAAG,EAAE,CAAC,uBAAM,CAAC,UAAU,EAAE,CAAC,CAAC;IACjC,CAAC;CACF,CAAC","sourcesContent":["/// \nimport './expect';\n\nimport { act, render, RenderResult, screen } from '@testing-library/react-native';\nimport React from 'react';\n\nimport { MockContextConfig, getMockConfig, getMockContext } from './mock-config';\nimport { setInitialUrl } from './mocks';\nimport { ExpoRoot } from '../ExpoRoot';\nimport getPathFromState from '../fork/getPathFromState';\nimport { stateCache } from '../getLinkingConfig';\nimport { store } from '../global-state/router-store';\nimport { router } from '../imperative-api';\n\n// re-export everything\nexport * from '@testing-library/react-native';\n\ntype RenderRouterOptions = Parameters[1] & {\n initialUrl?: any;\n};\n\ntype Result = ReturnType & {\n getPathname(): string;\n getPathnameWithParams(): string;\n getSegments(): string[];\n getSearchParams(): Record;\n};\n\nexport { MockContextConfig, getMockConfig, getMockContext };\n\nexport function renderRouter(\n context: MockContextConfig = './app',\n { initialUrl = '/', ...options }: RenderRouterOptions = {}\n): Result {\n const mockContext = getMockContext(context);\n\n // Reset the initial URL\n setInitialUrl(initialUrl);\n\n // Force the render to be synchronous\n process.env.EXPO_ROUTER_IMPORT_MODE = 'sync';\n stateCache.clear();\n\n let location: URL | undefined;\n\n if (typeof initialUrl === 'string') {\n location = new URL(initialUrl, 'test://');\n } else if (initialUrl instanceof URL) {\n location = initialUrl;\n }\n\n const result = render(, {\n ...options,\n });\n\n return Object.assign(result, {\n getPathname(this: RenderResult): string {\n return store.routeInfoSnapshot().pathname;\n },\n getSegments(this: RenderResult): string[] {\n return store.routeInfoSnapshot().segments;\n },\n getSearchParams(this: RenderResult): Record {\n return store.routeInfoSnapshot().params;\n },\n getPathnameWithParams(this: RenderResult): string {\n return getPathFromState(store.rootState!, store.linking!.config);\n },\n });\n}\n\nexport const testRouter = {\n /** Navigate to the provided pathname and the pathname */\n navigate(path: string) {\n act(() => router.navigate(path));\n expect(screen).toHavePathnameWithParams(path);\n },\n /** Push the provided pathname and assert the pathname */\n push(path: string) {\n act(() => router.push(path));\n expect(screen).toHavePathnameWithParams(path);\n },\n /** Replace with provided pathname and assert the pathname */\n replace(path: string) {\n act(() => router.replace(path));\n expect(screen).toHavePathnameWithParams(path);\n },\n /** Go back in history and asset the new pathname */\n back(path?: string) {\n expect(router.canGoBack()).toBe(true);\n act(() => router.back());\n if (path) {\n expect(screen).toHavePathnameWithParams(path);\n }\n },\n /** If there's history that supports invoking the `back` function. */\n canGoBack() {\n return router.canGoBack();\n },\n /** Update the current route query params and assert the new pathname */\n setParams(params?: Record, path?: string) {\n router.setParams(params);\n if (path) {\n expect(screen).toHavePathnameWithParams(path);\n }\n },\n /** If there's history that supports invoking the `back` function. */\n dismissAll() {\n act(() => router.dismissAll());\n },\n};\n"]} \ No newline at end of file +{"version":3,"file":"index.js","source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AE,CAAC,CAAC;QACzB,IAAI,IAAI,EAAE;YACR,MAAM,CAAC,qBAAM,CAAC,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;SAC/C;IACH,CAAC;IACD,qEAAqE;IACrE,SAAS;QACP,OAAO,uBAAM,CAAC,SAAS,EAAE,CAAC;IAC5B,CAAC;IACD,wEAAwE;IACxE,SAAS,CAAC,MAA+B,EAAE,IAAa;QACtD,uBAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACzB,IAAI,IAAI,EAAE;YACR,MAAM,CAAC,qBAAM,CAAC,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;SAC/C;IACH,CAAC;IACD,qEAAqE;IACrE,UAAU;QACR,IAAA,kBAAG,EAAC,GAAG,EAAE,CAAC,uBAAM,CAAC,UAAU,EAAE,CAAC,CAAC;IACjC,CAAC;CACF,CAAC","sourcesContent":["/// \nimport './expect';\n\nimport { act, render, RenderResult, screen } from '@testing-library/react-native';\nimport React from 'react';\n\nimport { MockContextConfig, getMockConfig, getMockContext } from './mock-config';\nimport { setInitialUrl } from './mocks';\nimport { ExpoRoot } from '../ExpoRoot';\nimport getPathFromState from '../fork/getPathFromState';\nimport { stateCache } from '../getLinkingConfig';\nimport { store } from '../global-state/router-store';\nimport { router } from '../imperative-api';\n\n// re-export everything\nexport * from '@testing-library/react-native';\n\nafterAll(() => {\n store.cleanup();\n});\n\ntype RenderRouterOptions = Parameters[1] & {\n initialUrl?: any;\n};\n\ntype Result = ReturnType & {\n getPathname(): string;\n getPathnameWithParams(): string;\n getSegments(): string[];\n getSearchParams(): Record;\n};\n\nexport { MockContextConfig, getMockConfig, getMockContext };\n\nexport function renderRouter(\n context: MockContextConfig = './app',\n { initialUrl = '/', ...options }: RenderRouterOptions = {}\n): Result {\n const mockContext = getMockContext(context);\n\n // Reset the initial URL\n setInitialUrl(initialUrl);\n\n // Force the render to be synchronous\n process.env.EXPO_ROUTER_IMPORT_MODE = 'sync';\n stateCache.clear();\n\n let location: URL | undefined;\n\n if (typeof initialUrl === 'string') {\n location = new URL(initialUrl, 'test://');\n } else if (initialUrl instanceof URL) {\n location = initialUrl;\n }\n\n const result = render(, {\n ...options,\n });\n\n return Object.assign(result, {\n getPathname(this: RenderResult): string {\n return store.routeInfoSnapshot().pathname;\n },\n getSegments(this: RenderResult): string[] {\n return store.routeInfoSnapshot().segments;\n },\n getSearchParams(this: RenderResult): Record {\n return store.routeInfoSnapshot().params;\n },\n getPathnameWithParams(this: RenderResult): string {\n return getPathFromState(store.rootState!, store.linking!.config);\n },\n });\n}\n\nexport const testRouter = {\n /** Navigate to the provided pathname and the pathname */\n navigate(path: string) {\n act(() => router.navigate(path));\n expect(screen).toHavePathnameWithParams(path);\n },\n /** Push the provided pathname and assert the pathname */\n push(path: string) {\n act(() => router.push(path));\n expect(screen).toHavePathnameWithParams(path);\n },\n /** Replace with provided pathname and assert the pathname */\n replace(path: string) {\n act(() => router.replace(path));\n expect(screen).toHavePathnameWithParams(path);\n },\n /** Go back in history and asset the new pathname */\n back(path?: string) {\n expect(router.canGoBack()).toBe(true);\n act(() => router.back());\n if (path) {\n expect(screen).toHavePathnameWithParams(path);\n }\n },\n /** If there's history that supports invoking the `back` function. */\n canGoBack() {\n return router.canGoBack();\n },\n /** Update the current route query params and assert the new pathname */\n setParams(params?: Record, path?: string) {\n router.setParams(params);\n if (path) {\n expect(screen).toHavePathnameWithParams(path);\n }\n },\n /** If there's history that supports invoking the `back` function. */\n dismissAll() {\n act(() => router.dismissAll());\n },\n};\n"]} \ No newline at end of file diff --git a/packages/expo-router/src/global-state/router-store.tsx b/packages/expo-router/src/global-state/router-store.tsx index c88b7c8259365..81d7565901f0e 100644 --- a/packages/expo-router/src/global-state/router-store.tsx +++ b/packages/expo-router/src/global-state/router-store.tsx @@ -43,6 +43,7 @@ export class RouterStore { rootState?: ResultState; nextState?: ResultState; routeInfo?: UrlObject; + splashScreenAnimationFrame?: number; navigationRef!: NavigationContainerRefWithCurrent; navigationRefSubscription!: () => void; @@ -132,11 +133,10 @@ export class RouterStore { if (!this.hasAttemptedToHideSplash) { this.hasAttemptedToHideSplash = true; // NOTE(EvanBacon): `navigationRef.isReady` is sometimes not true when state is called initially. - requestAnimationFrame( - () => - // @ts-expect-error: This function is native-only and for internal-use only. - SplashScreen._internal_maybeHideAsync?.() - ); + this.splashScreenAnimationFrame = requestAnimationFrame(() => { + // @ts-expect-error: This function is native-only and for internal-use only. + SplashScreen._internal_maybeHideAsync?.(); + }); } let shouldUpdateSubscribers = this.nextState === state; @@ -211,6 +211,12 @@ export class RouterStore { routeInfoSnapshot = () => { return this.routeInfo!; }; + + cleanup() { + if (this.splashScreenAnimationFrame) { + cancelAnimationFrame(this.splashScreenAnimationFrame); + } + } } export const store = new RouterStore(); diff --git a/packages/expo-router/src/testing-library/index.tsx b/packages/expo-router/src/testing-library/index.tsx index 74b6d256769f6..be76bd97f1e1a 100644 --- a/packages/expo-router/src/testing-library/index.tsx +++ b/packages/expo-router/src/testing-library/index.tsx @@ -15,6 +15,10 @@ import { router } from '../imperative-api'; // re-export everything export * from '@testing-library/react-native'; +afterAll(() => { + store.cleanup(); +}); + type RenderRouterOptions = Parameters[1] & { initialUrl?: any; };