@tanstack/react-router 1.168.13 → 1.168.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Asset.cjs +1 -0
- package/dist/cjs/Asset.cjs.map +1 -1
- package/dist/cjs/CatchBoundary.cjs +1 -0
- package/dist/cjs/CatchBoundary.cjs.map +1 -1
- package/dist/cjs/ClientOnly.cjs +1 -0
- package/dist/cjs/ClientOnly.cjs.map +1 -1
- package/dist/cjs/HeadContent.cjs +1 -0
- package/dist/cjs/HeadContent.cjs.map +1 -1
- package/dist/cjs/HeadContent.dev.cjs +1 -0
- package/dist/cjs/HeadContent.dev.cjs.map +1 -1
- package/dist/cjs/Match.cjs +9 -8
- package/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/Matches.cjs +6 -5
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/RouterProvider.cjs +1 -0
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/Scripts.cjs +5 -4
- package/dist/cjs/Scripts.cjs.map +1 -1
- package/dist/cjs/Transitioner.cjs +9 -8
- package/dist/cjs/Transitioner.cjs.map +1 -1
- package/dist/cjs/headContentUtils.cjs +6 -6
- package/dist/cjs/headContentUtils.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/index.dev.cjs +1 -0
- package/dist/cjs/link.cjs +2 -1
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/matchContext.cjs +1 -0
- package/dist/cjs/matchContext.cjs.map +1 -1
- package/dist/cjs/not-found.cjs +1 -1
- package/dist/cjs/not-found.cjs.map +1 -1
- package/dist/cjs/routerContext.cjs +1 -0
- package/dist/cjs/routerContext.cjs.map +1 -1
- package/dist/cjs/routerStores.cjs +2 -2
- package/dist/cjs/routerStores.cjs.map +1 -1
- package/dist/cjs/ssr/RouterClient.cjs +1 -1
- package/dist/cjs/ssr/RouterClient.cjs.map +1 -1
- package/dist/cjs/ssr/renderRouterToStream.cjs +2 -2
- package/dist/cjs/ssr/renderRouterToStream.cjs.map +1 -1
- package/dist/cjs/ssr/renderRouterToString.cjs +1 -1
- package/dist/cjs/ssr/renderRouterToString.cjs.map +1 -1
- package/dist/cjs/useBlocker.cjs +1 -0
- package/dist/cjs/useBlocker.cjs.map +1 -1
- package/dist/cjs/useCanGoBack.cjs +1 -1
- package/dist/cjs/useCanGoBack.cjs.map +1 -1
- package/dist/cjs/useLocation.cjs +1 -1
- package/dist/cjs/useLocation.cjs.map +1 -1
- package/dist/cjs/useMatch.cjs +4 -4
- package/dist/cjs/useMatch.cjs.map +1 -1
- package/dist/cjs/useNavigate.cjs +1 -0
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/cjs/useRouter.cjs +1 -0
- package/dist/cjs/useRouter.cjs.map +1 -1
- package/dist/cjs/useRouterState.cjs +2 -1
- package/dist/cjs/useRouterState.cjs.map +1 -1
- package/dist/cjs/utils.cjs +1 -0
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/esm/Asset.js +1 -0
- package/dist/esm/Asset.js.map +1 -1
- package/dist/esm/CatchBoundary.js +1 -0
- package/dist/esm/CatchBoundary.js.map +1 -1
- package/dist/esm/ClientOnly.js +1 -0
- package/dist/esm/ClientOnly.js.map +1 -1
- package/dist/esm/HeadContent.dev.js +1 -0
- package/dist/esm/HeadContent.dev.js.map +1 -1
- package/dist/esm/HeadContent.js +1 -0
- package/dist/esm/HeadContent.js.map +1 -1
- package/dist/esm/Match.js +9 -8
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Matches.js +6 -5
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/RouterProvider.js +1 -0
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/Scripts.js +5 -4
- package/dist/esm/Scripts.js.map +1 -1
- package/dist/esm/Transitioner.js +9 -8
- package/dist/esm/Transitioner.js.map +1 -1
- package/dist/esm/headContentUtils.js +6 -6
- package/dist/esm/headContentUtils.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.dev.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/link.js +2 -1
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/matchContext.js +1 -0
- package/dist/esm/matchContext.js.map +1 -1
- package/dist/esm/not-found.js +1 -1
- package/dist/esm/not-found.js.map +1 -1
- package/dist/esm/routerContext.js +1 -0
- package/dist/esm/routerContext.js.map +1 -1
- package/dist/esm/routerStores.js +3 -3
- package/dist/esm/routerStores.js.map +1 -1
- package/dist/esm/ssr/RouterClient.js +1 -1
- package/dist/esm/ssr/RouterClient.js.map +1 -1
- package/dist/esm/ssr/renderRouterToStream.js +2 -2
- package/dist/esm/ssr/renderRouterToStream.js.map +1 -1
- package/dist/esm/ssr/renderRouterToString.js +1 -1
- package/dist/esm/ssr/renderRouterToString.js.map +1 -1
- package/dist/esm/useBlocker.js +1 -0
- package/dist/esm/useBlocker.js.map +1 -1
- package/dist/esm/useCanGoBack.js +1 -1
- package/dist/esm/useCanGoBack.js.map +1 -1
- package/dist/esm/useLocation.js +1 -1
- package/dist/esm/useLocation.js.map +1 -1
- package/dist/esm/useMatch.js +4 -4
- package/dist/esm/useMatch.js.map +1 -1
- package/dist/esm/useNavigate.js +1 -0
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/esm/useRouter.js +1 -0
- package/dist/esm/useRouter.js.map +1 -1
- package/dist/esm/useRouterState.js +2 -1
- package/dist/esm/useRouterState.js.map +1 -1
- package/dist/esm/utils.js +1 -0
- package/dist/esm/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/Asset.tsx +2 -0
- package/src/CatchBoundary.tsx +2 -0
- package/src/ClientOnly.tsx +2 -0
- package/src/HeadContent.dev.tsx +2 -0
- package/src/HeadContent.tsx +2 -0
- package/src/Match.tsx +11 -9
- package/src/Matches.tsx +8 -6
- package/src/RouterProvider.tsx +2 -0
- package/src/Scripts.tsx +5 -10
- package/src/Transitioner.tsx +13 -16
- package/src/headContentUtils.tsx +6 -6
- package/src/index.dev.tsx +2 -0
- package/src/index.tsx +5 -0
- package/src/link.tsx +3 -1
- package/src/matchContext.tsx +2 -0
- package/src/not-found.tsx +2 -2
- package/src/routerContext.tsx +2 -0
- package/src/routerStores.ts +3 -3
- package/src/ssr/RouterClient.tsx +1 -1
- package/src/ssr/renderRouterToStream.tsx +2 -2
- package/src/ssr/renderRouterToString.tsx +1 -1
- package/src/useBlocker.tsx +2 -0
- package/src/useCanGoBack.ts +1 -1
- package/src/useLocation.tsx +1 -1
- package/src/useMatch.tsx +6 -5
- package/src/useNavigate.tsx +2 -0
- package/src/useRouter.tsx +2 -0
- package/src/useRouterState.tsx +3 -1
- package/src/utils.ts +1 -0
package/dist/esm/Match.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Match.js","names":[],"sources":["../../src/Match.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport {\n createControlledPromise,\n getLocationChangeInfo,\n invariant,\n isNotFound,\n isRedirect,\n rootRouteId,\n} from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouter } from './useRouter'\nimport { CatchNotFound } from './not-found'\nimport { matchContext } from './matchContext'\nimport { SafeFragment } from './SafeFragment'\nimport { renderRouteNotFound } from './renderRouteNotFound'\nimport { ScrollRestoration } from './scroll-restoration'\nimport { ClientOnly } from './ClientOnly'\nimport { useLayoutEffect } from './utils'\nimport type { AnyRoute, RootRouteOptions } from '@tanstack/router-core'\n\nexport const Match = React.memo(function MatchImpl({\n matchId,\n}: {\n matchId: string\n}) {\n const router = useRouter()\n\n if (isServer ?? router.isServer) {\n const match = router.stores.activeMatchStoresById.get(matchId)?.state\n if (!match) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find match for matchId \"${matchId}\". Please file an issue!`,\n )\n }\n\n invariant()\n }\n\n const routeId = match.routeId as string\n const parentRouteId = (router.routesById[routeId] as AnyRoute).parentRoute\n ?.id\n\n return (\n <MatchView\n router={router}\n matchId={matchId}\n resetKey={router.stores.loadedAt.state}\n matchState={{\n routeId,\n ssr: match.ssr,\n _displayPending: match._displayPending,\n parentRouteId,\n }}\n />\n )\n }\n\n // Subscribe directly to the match store from the pool.\n // The matchId prop is stable for this component's lifetime (set by Outlet),\n // and reconcileMatchPool reuses stores for the same matchId.\n\n const matchStore = router.stores.activeMatchStoresById.get(matchId)\n if (!matchStore) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find match for matchId \"${matchId}\". Please file an issue!`,\n )\n }\n\n invariant()\n }\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const resetKey = useStore(router.stores.loadedAt, (loadedAt) => loadedAt)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const match = useStore(matchStore, (value) => value)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const matchState = React.useMemo(() => {\n const routeId = match.routeId as string\n const parentRouteId = (router.routesById[routeId] as AnyRoute).parentRoute\n ?.id\n\n return {\n routeId,\n ssr: match.ssr,\n _displayPending: match._displayPending,\n parentRouteId: parentRouteId as string | undefined,\n } satisfies MatchViewState\n }, [match._displayPending, match.routeId, match.ssr, router.routesById])\n\n return (\n <MatchView\n router={router}\n matchId={matchId}\n resetKey={resetKey}\n matchState={matchState}\n />\n )\n})\n\ntype MatchViewState = {\n routeId: string\n ssr: boolean | 'data-only' | undefined\n _displayPending: boolean | undefined\n parentRouteId: string | undefined\n}\n\nfunction MatchView({\n router,\n matchId,\n resetKey,\n matchState,\n}: {\n router: ReturnType<typeof useRouter>\n matchId: string\n resetKey: number\n matchState: MatchViewState\n}) {\n const route: AnyRoute = router.routesById[matchState.routeId]\n\n const PendingComponent =\n route.options.pendingComponent ?? router.options.defaultPendingComponent\n\n const pendingElement = PendingComponent ? <PendingComponent /> : null\n\n const routeErrorComponent =\n route.options.errorComponent ?? router.options.defaultErrorComponent\n\n const routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch\n\n const routeNotFoundComponent = route.isRoot\n ? // If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component\n (route.options.notFoundComponent ??\n router.options.notFoundRoute?.options.component)\n : route.options.notFoundComponent\n\n const resolvedNoSsr =\n matchState.ssr === false || matchState.ssr === 'data-only'\n const ResolvedSuspenseBoundary =\n // If we're on the root route, allow forcefully wrapping in suspense\n (!route.isRoot || route.options.wrapInSuspense || resolvedNoSsr) &&\n (route.options.wrapInSuspense ??\n PendingComponent ??\n ((route.options.errorComponent as any)?.preload || resolvedNoSsr))\n ? React.Suspense\n : SafeFragment\n\n const ResolvedCatchBoundary = routeErrorComponent\n ? CatchBoundary\n : SafeFragment\n\n const ResolvedNotFoundBoundary = routeNotFoundComponent\n ? CatchNotFound\n : SafeFragment\n\n const ShellComponent = route.isRoot\n ? ((route.options as RootRouteOptions).shellComponent ?? SafeFragment)\n : SafeFragment\n return (\n <ShellComponent>\n <matchContext.Provider value={matchId}>\n <ResolvedSuspenseBoundary fallback={pendingElement}>\n <ResolvedCatchBoundary\n getResetKey={() => resetKey}\n errorComponent={routeErrorComponent || ErrorComponent}\n onCatch={(error, errorInfo) => {\n // Forward not found errors (we don't want to show the error component for these)\n if (isNotFound(error)) {\n error.routeId ??= matchState.routeId as any\n throw error\n }\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`Warning: Error in route match: ${matchId}`)\n }\n routeOnCatch?.(error, errorInfo)\n }}\n >\n <ResolvedNotFoundBoundary\n fallback={(error) => {\n error.routeId ??= matchState.routeId as any\n\n // If the current not found handler doesn't exist or it has a\n // route ID which doesn't match the current route, rethrow the error\n if (\n !routeNotFoundComponent ||\n (error.routeId && error.routeId !== matchState.routeId) ||\n (!error.routeId && !route.isRoot)\n )\n throw error\n\n return React.createElement(routeNotFoundComponent, error as any)\n }}\n >\n {resolvedNoSsr || matchState._displayPending ? (\n <ClientOnly fallback={pendingElement}>\n <MatchInner matchId={matchId} />\n </ClientOnly>\n ) : (\n <MatchInner matchId={matchId} />\n )}\n </ResolvedNotFoundBoundary>\n </ResolvedCatchBoundary>\n </ResolvedSuspenseBoundary>\n </matchContext.Provider>\n {matchState.parentRouteId === rootRouteId ? (\n <>\n <OnRendered resetKey={resetKey} />\n {router.options.scrollRestoration && (isServer ?? router.isServer) ? (\n <ScrollRestoration />\n ) : null}\n </>\n ) : null}\n </ShellComponent>\n )\n}\n\n// On Rendered can't happen above the root layout because it needs to run after\n// the route subtree has committed below the root layout. Keeping it here lets\n// us fire onRendered even after a hydration mismatch above the root layout\n// (like bad head/link tags, which is common).\nfunction OnRendered({ resetKey }: { resetKey: number }) {\n const router = useRouter()\n\n if (isServer ?? router.isServer) {\n return null\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const prevHrefRef = React.useRef<string | undefined>(undefined)\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useLayoutEffect(() => {\n const currentHref = router.latestLocation.href\n\n if (\n prevHrefRef.current === undefined ||\n prevHrefRef.current !== currentHref\n ) {\n router.emit({\n type: 'onRendered',\n ...getLocationChangeInfo(\n router.stores.location.state,\n router.stores.resolvedLocation.state,\n ),\n })\n prevHrefRef.current = currentHref\n }\n }, [router.latestLocation.state.__TSR_key, resetKey, router])\n\n return null\n}\n\nexport const MatchInner = React.memo(function MatchInnerImpl({\n matchId,\n}: {\n matchId: string\n}): any {\n const router = useRouter()\n\n const getMatchPromise = (\n match: {\n id: string\n _nonReactive: {\n displayPendingPromise?: Promise<void>\n minPendingPromise?: Promise<void>\n loadPromise?: Promise<void>\n }\n },\n key: 'displayPendingPromise' | 'minPendingPromise' | 'loadPromise',\n ) => {\n return (\n router.getMatch(match.id)?._nonReactive[key] ?? match._nonReactive[key]\n )\n }\n\n if (isServer ?? router.isServer) {\n const match = router.stores.activeMatchStoresById.get(matchId)?.state\n if (!match) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find match for matchId \"${matchId}\". Please file an issue!`,\n )\n }\n\n invariant()\n }\n\n const routeId = match.routeId as string\n const route = router.routesById[routeId] as AnyRoute\n const remountFn =\n (router.routesById[routeId] as AnyRoute).options.remountDeps ??\n router.options.defaultRemountDeps\n const remountDeps = remountFn?.({\n routeId,\n loaderDeps: match.loaderDeps,\n params: match._strictParams,\n search: match._strictSearch,\n })\n const key = remountDeps ? JSON.stringify(remountDeps) : undefined\n const Comp = route.options.component ?? router.options.defaultComponent\n const out = Comp ? <Comp key={key} /> : <Outlet />\n\n if (match._displayPending) {\n throw getMatchPromise(match, 'displayPendingPromise')\n }\n\n if (match._forcePending) {\n throw getMatchPromise(match, 'minPendingPromise')\n }\n\n if (match.status === 'pending') {\n throw getMatchPromise(match, 'loadPromise')\n }\n\n if (match.status === 'notFound') {\n if (!isNotFound(match.error)) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Invariant failed: Expected a notFound error')\n }\n\n invariant()\n }\n return renderRouteNotFound(router, route, match.error)\n }\n\n if (match.status === 'redirected') {\n if (!isRedirect(match.error)) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Invariant failed: Expected a redirect error')\n }\n\n invariant()\n }\n throw getMatchPromise(match, 'loadPromise')\n }\n\n if (match.status === 'error') {\n const RouteErrorComponent =\n (route.options.errorComponent ??\n router.options.defaultErrorComponent) ||\n ErrorComponent\n return (\n <RouteErrorComponent\n error={match.error as any}\n reset={undefined as any}\n info={{\n componentStack: '',\n }}\n />\n )\n }\n\n return out\n }\n\n const matchStore = router.stores.activeMatchStoresById.get(matchId)\n if (!matchStore) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find match for matchId \"${matchId}\". Please file an issue!`,\n )\n }\n\n invariant()\n }\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const match = useStore(matchStore, (value) => value)\n const routeId = match.routeId as string\n const route = router.routesById[routeId] as AnyRoute\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const key = React.useMemo(() => {\n const remountFn =\n (router.routesById[routeId] as AnyRoute).options.remountDeps ??\n router.options.defaultRemountDeps\n const remountDeps = remountFn?.({\n routeId,\n loaderDeps: match.loaderDeps,\n params: match._strictParams,\n search: match._strictSearch,\n })\n return remountDeps ? JSON.stringify(remountDeps) : undefined\n }, [\n routeId,\n match.loaderDeps,\n match._strictParams,\n match._strictSearch,\n router.options.defaultRemountDeps,\n router.routesById,\n ])\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const out = React.useMemo(() => {\n const Comp = route.options.component ?? router.options.defaultComponent\n if (Comp) {\n return <Comp key={key} />\n }\n return <Outlet />\n }, [key, route.options.component, router.options.defaultComponent])\n\n if (match._displayPending) {\n throw getMatchPromise(match, 'displayPendingPromise')\n }\n\n if (match._forcePending) {\n throw getMatchPromise(match, 'minPendingPromise')\n }\n\n // see also hydrate() in packages/router-core/src/ssr/ssr-client.ts\n if (match.status === 'pending') {\n // We're pending, and if we have a minPendingMs, we need to wait for it\n const pendingMinMs =\n route.options.pendingMinMs ?? router.options.defaultPendingMinMs\n if (pendingMinMs) {\n const routerMatch = router.getMatch(match.id)\n if (routerMatch && !routerMatch._nonReactive.minPendingPromise) {\n // Create a promise that will resolve after the minPendingMs\n if (!(isServer ?? router.isServer)) {\n const minPendingPromise = createControlledPromise<void>()\n\n routerMatch._nonReactive.minPendingPromise = minPendingPromise\n\n setTimeout(() => {\n minPendingPromise.resolve()\n // We've handled the minPendingPromise, so we can delete it\n routerMatch._nonReactive.minPendingPromise = undefined\n }, pendingMinMs)\n }\n }\n }\n throw getMatchPromise(match, 'loadPromise')\n }\n\n if (match.status === 'notFound') {\n if (!isNotFound(match.error)) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Invariant failed: Expected a notFound error')\n }\n\n invariant()\n }\n return renderRouteNotFound(router, route, match.error)\n }\n\n if (match.status === 'redirected') {\n // A match can be observed as redirected during an in-flight transition,\n // especially when pending UI is already rendering. Suspend on the match's\n // load promise so React can abandon this stale render and continue the\n // redirect transition.\n if (!isRedirect(match.error)) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Invariant failed: Expected a redirect error')\n }\n\n invariant()\n }\n\n throw getMatchPromise(match, 'loadPromise')\n }\n\n if (match.status === 'error') {\n // If we're on the server, we need to use React's new and super\n // wonky api for throwing errors from a server side render inside\n // of a suspense boundary. This is the only way to get\n // renderToPipeableStream to not hang indefinitely.\n // We'll serialize the error and rethrow it on the client.\n if (isServer ?? router.isServer) {\n const RouteErrorComponent =\n (route.options.errorComponent ??\n router.options.defaultErrorComponent) ||\n ErrorComponent\n return (\n <RouteErrorComponent\n error={match.error as any}\n reset={undefined as any}\n info={{\n componentStack: '',\n }}\n />\n )\n }\n\n throw match.error\n }\n\n return out\n})\n\n/**\n * Render the next child match in the route tree. Typically used inside\n * a route component to render nested routes.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/outletComponent\n */\nexport const Outlet = React.memo(function OutletImpl() {\n const router = useRouter()\n const matchId = React.useContext(matchContext)\n\n let routeId: string | undefined\n let parentGlobalNotFound = false\n let childMatchId: string | undefined\n\n if (isServer ?? router.isServer) {\n const matches = router.stores.activeMatchesSnapshot.state\n const parentIndex = matchId\n ? matches.findIndex((match) => match.id === matchId)\n : -1\n const parentMatch = parentIndex >= 0 ? matches[parentIndex] : undefined\n routeId = parentMatch?.routeId as string | undefined\n parentGlobalNotFound = parentMatch?.globalNotFound ?? false\n childMatchId =\n parentIndex >= 0 ? (matches[parentIndex + 1]?.id as string) : undefined\n } else {\n // Subscribe directly to the match store from the pool instead of\n // the two-level byId → matchStore pattern.\n const parentMatchStore = matchId\n ? router.stores.activeMatchStoresById.get(matchId)\n : undefined\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n ;[routeId, parentGlobalNotFound] = useStore(parentMatchStore, (match) => [\n match?.routeId as string | undefined,\n match?.globalNotFound ?? false,\n ])\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n childMatchId = useStore(router.stores.matchesId, (ids) => {\n const index = ids.findIndex((id) => id === matchId)\n return ids[index + 1]\n })\n }\n\n const route = routeId ? router.routesById[routeId] : undefined\n\n const pendingElement = router.options.defaultPendingComponent ? (\n <router.options.defaultPendingComponent />\n ) : null\n\n if (parentGlobalNotFound) {\n if (!route) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n 'Invariant failed: Could not resolve route for Outlet render',\n )\n }\n\n invariant()\n }\n return renderRouteNotFound(router, route, undefined)\n }\n\n if (!childMatchId) {\n return null\n }\n\n const nextMatch = <Match matchId={childMatchId} />\n\n if (routeId === rootRouteId) {\n return (\n <React.Suspense fallback={pendingElement}>{nextMatch}</React.Suspense>\n )\n }\n\n return nextMatch\n})\n"],"mappings":";;;;;;;;;;;;;;;AAsBA,IAAa,QAAQ,QAAM,KAAK,SAAS,UAAU,EACjD,WAGC;CACD,MAAM,SAAS,WAAW;AAE1B,KAAI,YAAY,OAAO,UAAU;EAC/B,MAAM,QAAQ,OAAO,OAAO,sBAAsB,IAAI,QAAQ,EAAE;AAChE,MAAI,CAAC,OAAO;AACV,OAAA,QAAA,IAAA,aAA6B,aAC3B,OAAM,IAAI,MACR,uDAAuD,QAAQ,0BAChE;AAGH,cAAW;;EAGb,MAAM,UAAU,MAAM;EACtB,MAAM,gBAAiB,OAAO,WAAW,SAAsB,aAC3D;AAEJ,SACE,oBAAC,WAAD;GACU;GACC;GACT,UAAU,OAAO,OAAO,SAAS;GACjC,YAAY;IACV;IACA,KAAK,MAAM;IACX,iBAAiB,MAAM;IACvB;IACD;GACD,CAAA;;CAQN,MAAM,aAAa,OAAO,OAAO,sBAAsB,IAAI,QAAQ;AACnE,KAAI,CAAC,YAAY;AACf,MAAA,QAAA,IAAA,aAA6B,aAC3B,OAAM,IAAI,MACR,uDAAuD,QAAQ,0BAChE;AAGH,aAAW;;CAGb,MAAM,WAAW,SAAS,OAAO,OAAO,WAAW,aAAa,SAAS;CAEzE,MAAM,QAA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AAe,IAAI,QAAQ,eAAe,KAAA;AAC9D,YAAU,aAAa;AACvB,yBAAuB,aAAa,kBAAkB;AACtD,iBACE,eAAe,IAAK,QAAQ,cAAc,IAAI,KAAgB,KAAA;QAC3D;EAGL,MAAM,mBAAmB,UACrB,OAAO,OAAO,sBAAsB,IAAI,QAAQ,GAChD,KAAA;AAGH,GAAC,SAAS,wBAAwB,SAAS,mBAAmB,UAAU,CACvE,OAAO,SACP,OAAO,kBAAkB,MAC1B,CAAC;AAGF,iBAAe,SAAS,OAAO,OAAO,YAAY,QAAQ;AAExD,UAAO,IADO,IAAI,WAAW,OAAO,OAAO,QAAQ,GAChC;IACnB;;CAGJ,MAAM,QAAQ,UAAU,OAAO,WAAW,WAAW,KAAA;CAErD,MAAM,iBAAiB,OAAO,QAAQ,0BACpC,oBAAC,OAAO,QAAQ,yBAAhB,EAA0C,CAAA,GACxC;AAEJ,KAAI,sBAAsB;AACxB,MAAI,CAAC,OAAO;AACV,OAAA,QAAA,IAAA,aAA6B,aAC3B,OAAM,IAAI,MACR,8DACD;AAGH,cAAW;;AAEb,SAAO,oBAAoB,QAAQ,OAAO,KAAA,EAAU;;AAGtD,KAAI,CAAC,aACH,QAAO;CAGT,MAAM,YAAY,oBAAC,OAAD,EAAO,SAAS,cAAgB,CAAA;AAElD,KAAI,YAAY,YACd,QACE,oBAAC,QAAM,UAAP;EAAgB,UAAU;YAAiB;EAA2B,CAAA;AAI1E,QAAO;EACP"}
|
|
1
|
+
{"version":3,"file":"Match.js","names":[],"sources":["../../src/Match.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport {\n createControlledPromise,\n getLocationChangeInfo,\n invariant,\n isNotFound,\n isRedirect,\n rootRouteId,\n} from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouter } from './useRouter'\nimport { CatchNotFound } from './not-found'\nimport { matchContext } from './matchContext'\nimport { SafeFragment } from './SafeFragment'\nimport { renderRouteNotFound } from './renderRouteNotFound'\nimport { ScrollRestoration } from './scroll-restoration'\nimport { ClientOnly } from './ClientOnly'\nimport { useLayoutEffect } from './utils'\nimport type { AnyRoute, RootRouteOptions } from '@tanstack/router-core'\n\nexport const Match = React.memo(function MatchImpl({\n matchId,\n}: {\n matchId: string\n}) {\n const router = useRouter()\n\n if (isServer ?? router.isServer) {\n const match = router.stores.matchStores.get(matchId)?.get()\n if (!match) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find match for matchId \"${matchId}\". Please file an issue!`,\n )\n }\n\n invariant()\n }\n\n const routeId = match.routeId as string\n const parentRouteId = (router.routesById[routeId] as AnyRoute).parentRoute\n ?.id\n\n return (\n <MatchView\n router={router}\n matchId={matchId}\n resetKey={router.stores.loadedAt.get()}\n matchState={{\n routeId,\n ssr: match.ssr,\n _displayPending: match._displayPending,\n parentRouteId,\n }}\n />\n )\n }\n\n // Subscribe directly to the match store from the pool.\n // The matchId prop is stable for this component's lifetime (set by Outlet),\n // and reconcileMatchPool reuses stores for the same matchId.\n\n const matchStore = router.stores.matchStores.get(matchId)\n if (!matchStore) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find match for matchId \"${matchId}\". Please file an issue!`,\n )\n }\n\n invariant()\n }\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const resetKey = useStore(router.stores.loadedAt, (loadedAt) => loadedAt)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const match = useStore(matchStore, (value) => value)\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const matchState = React.useMemo(() => {\n const routeId = match.routeId as string\n const parentRouteId = (router.routesById[routeId] as AnyRoute).parentRoute\n ?.id\n\n return {\n routeId,\n ssr: match.ssr,\n _displayPending: match._displayPending,\n parentRouteId: parentRouteId as string | undefined,\n } satisfies MatchViewState\n }, [match._displayPending, match.routeId, match.ssr, router.routesById])\n\n return (\n <MatchView\n router={router}\n matchId={matchId}\n resetKey={resetKey}\n matchState={matchState}\n />\n )\n})\n\ntype MatchViewState = {\n routeId: string\n ssr: boolean | 'data-only' | undefined\n _displayPending: boolean | undefined\n parentRouteId: string | undefined\n}\n\nfunction MatchView({\n router,\n matchId,\n resetKey,\n matchState,\n}: {\n router: ReturnType<typeof useRouter>\n matchId: string\n resetKey: number\n matchState: MatchViewState\n}) {\n const route: AnyRoute = router.routesById[matchState.routeId]\n\n const PendingComponent =\n route.options.pendingComponent ?? router.options.defaultPendingComponent\n\n const pendingElement = PendingComponent ? <PendingComponent /> : null\n\n const routeErrorComponent =\n route.options.errorComponent ?? router.options.defaultErrorComponent\n\n const routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch\n\n const routeNotFoundComponent = route.isRoot\n ? // If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component\n (route.options.notFoundComponent ??\n router.options.notFoundRoute?.options.component)\n : route.options.notFoundComponent\n\n const resolvedNoSsr =\n matchState.ssr === false || matchState.ssr === 'data-only'\n const ResolvedSuspenseBoundary =\n // If we're on the root route, allow forcefully wrapping in suspense\n (!route.isRoot || route.options.wrapInSuspense || resolvedNoSsr) &&\n (route.options.wrapInSuspense ??\n PendingComponent ??\n ((route.options.errorComponent as any)?.preload || resolvedNoSsr))\n ? React.Suspense\n : SafeFragment\n\n const ResolvedCatchBoundary = routeErrorComponent\n ? CatchBoundary\n : SafeFragment\n\n const ResolvedNotFoundBoundary = routeNotFoundComponent\n ? CatchNotFound\n : SafeFragment\n\n const ShellComponent = route.isRoot\n ? ((route.options as RootRouteOptions).shellComponent ?? SafeFragment)\n : SafeFragment\n return (\n <ShellComponent>\n <matchContext.Provider value={matchId}>\n <ResolvedSuspenseBoundary fallback={pendingElement}>\n <ResolvedCatchBoundary\n getResetKey={() => resetKey}\n errorComponent={routeErrorComponent || ErrorComponent}\n onCatch={(error, errorInfo) => {\n // Forward not found errors (we don't want to show the error component for these)\n if (isNotFound(error)) {\n error.routeId ??= matchState.routeId as any\n throw error\n }\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`Warning: Error in route match: ${matchId}`)\n }\n routeOnCatch?.(error, errorInfo)\n }}\n >\n <ResolvedNotFoundBoundary\n fallback={(error) => {\n error.routeId ??= matchState.routeId as any\n\n // If the current not found handler doesn't exist or it has a\n // route ID which doesn't match the current route, rethrow the error\n if (\n !routeNotFoundComponent ||\n (error.routeId && error.routeId !== matchState.routeId) ||\n (!error.routeId && !route.isRoot)\n )\n throw error\n\n return React.createElement(routeNotFoundComponent, error as any)\n }}\n >\n {resolvedNoSsr || matchState._displayPending ? (\n <ClientOnly fallback={pendingElement}>\n <MatchInner matchId={matchId} />\n </ClientOnly>\n ) : (\n <MatchInner matchId={matchId} />\n )}\n </ResolvedNotFoundBoundary>\n </ResolvedCatchBoundary>\n </ResolvedSuspenseBoundary>\n </matchContext.Provider>\n {matchState.parentRouteId === rootRouteId ? (\n <>\n <OnRendered resetKey={resetKey} />\n {router.options.scrollRestoration && (isServer ?? router.isServer) ? (\n <ScrollRestoration />\n ) : null}\n </>\n ) : null}\n </ShellComponent>\n )\n}\n\n// On Rendered can't happen above the root layout because it needs to run after\n// the route subtree has committed below the root layout. Keeping it here lets\n// us fire onRendered even after a hydration mismatch above the root layout\n// (like bad head/link tags, which is common).\nfunction OnRendered({ resetKey }: { resetKey: number }) {\n const router = useRouter()\n\n if (isServer ?? router.isServer) {\n return null\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const prevHrefRef = React.useRef<string | undefined>(undefined)\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useLayoutEffect(() => {\n const currentHref = router.latestLocation.href\n\n if (\n prevHrefRef.current === undefined ||\n prevHrefRef.current !== currentHref\n ) {\n router.emit({\n type: 'onRendered',\n ...getLocationChangeInfo(\n router.stores.location.get(),\n router.stores.resolvedLocation.get(),\n ),\n })\n prevHrefRef.current = currentHref\n }\n }, [router.latestLocation.state.__TSR_key, resetKey, router])\n\n return null\n}\n\nexport const MatchInner = React.memo(function MatchInnerImpl({\n matchId,\n}: {\n matchId: string\n}): any {\n const router = useRouter()\n\n const getMatchPromise = (\n match: {\n id: string\n _nonReactive: {\n displayPendingPromise?: Promise<void>\n minPendingPromise?: Promise<void>\n loadPromise?: Promise<void>\n }\n },\n key: 'displayPendingPromise' | 'minPendingPromise' | 'loadPromise',\n ) => {\n return (\n router.getMatch(match.id)?._nonReactive[key] ?? match._nonReactive[key]\n )\n }\n\n if (isServer ?? router.isServer) {\n const match = router.stores.matchStores.get(matchId)?.get()\n if (!match) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find match for matchId \"${matchId}\". Please file an issue!`,\n )\n }\n\n invariant()\n }\n\n const routeId = match.routeId as string\n const route = router.routesById[routeId] as AnyRoute\n const remountFn =\n (router.routesById[routeId] as AnyRoute).options.remountDeps ??\n router.options.defaultRemountDeps\n const remountDeps = remountFn?.({\n routeId,\n loaderDeps: match.loaderDeps,\n params: match._strictParams,\n search: match._strictSearch,\n })\n const key = remountDeps ? JSON.stringify(remountDeps) : undefined\n const Comp = route.options.component ?? router.options.defaultComponent\n const out = Comp ? <Comp key={key} /> : <Outlet />\n\n if (match._displayPending) {\n throw getMatchPromise(match, 'displayPendingPromise')\n }\n\n if (match._forcePending) {\n throw getMatchPromise(match, 'minPendingPromise')\n }\n\n if (match.status === 'pending') {\n throw getMatchPromise(match, 'loadPromise')\n }\n\n if (match.status === 'notFound') {\n if (!isNotFound(match.error)) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Invariant failed: Expected a notFound error')\n }\n\n invariant()\n }\n return renderRouteNotFound(router, route, match.error)\n }\n\n if (match.status === 'redirected') {\n if (!isRedirect(match.error)) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Invariant failed: Expected a redirect error')\n }\n\n invariant()\n }\n throw getMatchPromise(match, 'loadPromise')\n }\n\n if (match.status === 'error') {\n const RouteErrorComponent =\n (route.options.errorComponent ??\n router.options.defaultErrorComponent) ||\n ErrorComponent\n return (\n <RouteErrorComponent\n error={match.error as any}\n reset={undefined as any}\n info={{\n componentStack: '',\n }}\n />\n )\n }\n\n return out\n }\n\n const matchStore = router.stores.matchStores.get(matchId)\n if (!matchStore) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n `Invariant failed: Could not find match for matchId \"${matchId}\". Please file an issue!`,\n )\n }\n\n invariant()\n }\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const match = useStore(matchStore, (value) => value)\n const routeId = match.routeId as string\n const route = router.routesById[routeId] as AnyRoute\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const key = React.useMemo(() => {\n const remountFn =\n (router.routesById[routeId] as AnyRoute).options.remountDeps ??\n router.options.defaultRemountDeps\n const remountDeps = remountFn?.({\n routeId,\n loaderDeps: match.loaderDeps,\n params: match._strictParams,\n search: match._strictSearch,\n })\n return remountDeps ? JSON.stringify(remountDeps) : undefined\n }, [\n routeId,\n match.loaderDeps,\n match._strictParams,\n match._strictSearch,\n router.options.defaultRemountDeps,\n router.routesById,\n ])\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const out = React.useMemo(() => {\n const Comp = route.options.component ?? router.options.defaultComponent\n if (Comp) {\n return <Comp key={key} />\n }\n return <Outlet />\n }, [key, route.options.component, router.options.defaultComponent])\n\n if (match._displayPending) {\n throw getMatchPromise(match, 'displayPendingPromise')\n }\n\n if (match._forcePending) {\n throw getMatchPromise(match, 'minPendingPromise')\n }\n\n // see also hydrate() in packages/router-core/src/ssr/ssr-client.ts\n if (match.status === 'pending') {\n // We're pending, and if we have a minPendingMs, we need to wait for it\n const pendingMinMs =\n route.options.pendingMinMs ?? router.options.defaultPendingMinMs\n if (pendingMinMs) {\n const routerMatch = router.getMatch(match.id)\n if (routerMatch && !routerMatch._nonReactive.minPendingPromise) {\n // Create a promise that will resolve after the minPendingMs\n if (!(isServer ?? router.isServer)) {\n const minPendingPromise = createControlledPromise<void>()\n\n routerMatch._nonReactive.minPendingPromise = minPendingPromise\n\n setTimeout(() => {\n minPendingPromise.resolve()\n // We've handled the minPendingPromise, so we can delete it\n routerMatch._nonReactive.minPendingPromise = undefined\n }, pendingMinMs)\n }\n }\n }\n throw getMatchPromise(match, 'loadPromise')\n }\n\n if (match.status === 'notFound') {\n if (!isNotFound(match.error)) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Invariant failed: Expected a notFound error')\n }\n\n invariant()\n }\n return renderRouteNotFound(router, route, match.error)\n }\n\n if (match.status === 'redirected') {\n // A match can be observed as redirected during an in-flight transition,\n // especially when pending UI is already rendering. Suspend on the match's\n // load promise so React can abandon this stale render and continue the\n // redirect transition.\n if (!isRedirect(match.error)) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Invariant failed: Expected a redirect error')\n }\n\n invariant()\n }\n\n throw getMatchPromise(match, 'loadPromise')\n }\n\n if (match.status === 'error') {\n // If we're on the server, we need to use React's new and super\n // wonky api for throwing errors from a server side render inside\n // of a suspense boundary. This is the only way to get\n // renderToPipeableStream to not hang indefinitely.\n // We'll serialize the error and rethrow it on the client.\n if (isServer ?? router.isServer) {\n const RouteErrorComponent =\n (route.options.errorComponent ??\n router.options.defaultErrorComponent) ||\n ErrorComponent\n return (\n <RouteErrorComponent\n error={match.error as any}\n reset={undefined as any}\n info={{\n componentStack: '',\n }}\n />\n )\n }\n\n throw match.error\n }\n\n return out\n})\n\n/**\n * Render the next child match in the route tree. Typically used inside\n * a route component to render nested routes.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/outletComponent\n */\nexport const Outlet = React.memo(function OutletImpl() {\n const router = useRouter()\n const matchId = React.useContext(matchContext)\n\n let routeId: string | undefined\n let parentGlobalNotFound = false\n let childMatchId: string | undefined\n\n if (isServer ?? router.isServer) {\n const matches = router.stores.matches.get()\n const parentIndex = matchId\n ? matches.findIndex((match) => match.id === matchId)\n : -1\n const parentMatch = parentIndex >= 0 ? matches[parentIndex] : undefined\n routeId = parentMatch?.routeId as string | undefined\n parentGlobalNotFound = parentMatch?.globalNotFound ?? false\n childMatchId =\n parentIndex >= 0 ? (matches[parentIndex + 1]?.id as string) : undefined\n } else {\n // Subscribe directly to the match store from the pool instead of\n // the two-level byId → matchStore pattern.\n const parentMatchStore = matchId\n ? router.stores.matchStores.get(matchId)\n : undefined\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n ;[routeId, parentGlobalNotFound] = useStore(parentMatchStore, (match) => [\n match?.routeId as string | undefined,\n match?.globalNotFound ?? false,\n ])\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n childMatchId = useStore(router.stores.matchesId, (ids) => {\n const index = ids.findIndex((id) => id === matchId)\n return ids[index + 1]\n })\n }\n\n const route = routeId ? router.routesById[routeId] : undefined\n\n const pendingElement = router.options.defaultPendingComponent ? (\n <router.options.defaultPendingComponent />\n ) : null\n\n if (parentGlobalNotFound) {\n if (!route) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n 'Invariant failed: Could not resolve route for Outlet render',\n )\n }\n\n invariant()\n }\n return renderRouteNotFound(router, route, undefined)\n }\n\n if (!childMatchId) {\n return null\n }\n\n const nextMatch = <Match matchId={childMatchId} />\n\n if (routeId === rootRouteId) {\n return (\n <React.Suspense fallback={pendingElement}>{nextMatch}</React.Suspense>\n )\n }\n\n return nextMatch\n})\n"],"mappings":";;;;;;;;;;;;;;;;AAwBA,IAAa,QAAQ,QAAM,KAAK,SAAS,UAAU,EACjD,WAGC;CACD,MAAM,SAAS,WAAW;AAE1B,KAAI,YAAY,OAAO,UAAU;EAC/B,MAAM,QAAQ,OAAO,OAAO,YAAY,IAAI,QAAQ,EAAE,KAAK;AAC3D,MAAI,CAAC,OAAO;AACV,OAAA,QAAA,IAAA,aAA6B,aAC3B,OAAM,IAAI,MACR,uDAAuD,QAAQ,0BAChE;AAGH,cAAW;;EAGb,MAAM,UAAU,MAAM;EACtB,MAAM,gBAAiB,OAAO,WAAW,SAAsB,aAC3D;AAEJ,SACE,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UAAP;EAAgB,UAAU;YAAiB;EAA2B,CAAA;AAI1E,QAAO;EACP"}
|
package/dist/esm/Matches.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { CatchBoundary, ErrorComponent } from "./CatchBoundary.js";
|
|
2
3
|
import { matchContext } from "./matchContext.js";
|
|
3
4
|
import { useRouter } from "./useRouter.js";
|
|
@@ -27,8 +28,8 @@ function Matches() {
|
|
|
27
28
|
function MatchesInner() {
|
|
28
29
|
const router = useRouter();
|
|
29
30
|
const _isServer = isServer ?? router.isServer;
|
|
30
|
-
const matchId = _isServer ? router.stores.
|
|
31
|
-
const resetKey = _isServer ? router.stores.loadedAt.
|
|
31
|
+
const matchId = _isServer ? router.stores.firstId.get() : useStore(router.stores.firstId, (id) => id);
|
|
32
|
+
const resetKey = _isServer ? router.stores.loadedAt.get() : useStore(router.stores.loadedAt, (loadedAt) => loadedAt);
|
|
32
33
|
const matchComponent = matchId ? /* @__PURE__ */ jsx(Match, { matchId }) : null;
|
|
33
34
|
return /* @__PURE__ */ jsx(matchContext.Provider, {
|
|
34
35
|
value: matchId,
|
|
@@ -57,7 +58,7 @@ function MatchesInner() {
|
|
|
57
58
|
*/
|
|
58
59
|
function useMatchRoute() {
|
|
59
60
|
const router = useRouter();
|
|
60
|
-
if (!(isServer ?? router.isServer)) useStore(router.stores.
|
|
61
|
+
if (!(isServer ?? router.isServer)) useStore(router.stores.matchRouteDeps, (d) => d);
|
|
61
62
|
return React$1.useCallback((opts) => {
|
|
62
63
|
const { pending, caseSensitive, fuzzy, includeSearch, ...rest } = opts;
|
|
63
64
|
return router.matchRoute(rest, {
|
|
@@ -84,10 +85,10 @@ function useMatches(opts) {
|
|
|
84
85
|
const router = useRouter();
|
|
85
86
|
const previousResult = React$1.useRef(void 0);
|
|
86
87
|
if (isServer ?? router.isServer) {
|
|
87
|
-
const matches = router.stores.
|
|
88
|
+
const matches = router.stores.matches.get();
|
|
88
89
|
return opts?.select ? opts.select(matches) : matches;
|
|
89
90
|
}
|
|
90
|
-
return useStore(router.stores.
|
|
91
|
+
return useStore(router.stores.matches, (matches) => {
|
|
91
92
|
const selected = opts?.select ? opts.select(matches) : matches;
|
|
92
93
|
if (opts?.structuralSharing ?? router.options.defaultStructuralSharing) {
|
|
93
94
|
const shared = replaceEqualDeep(previousResult.current, selected);
|
package/dist/esm/Matches.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Matches.js","names":[],"sources":["../../src/Matches.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport { replaceEqualDeep, rootRouteId } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouter } from './useRouter'\nimport { Transitioner } from './Transitioner'\nimport { matchContext } from './matchContext'\nimport { Match } from './Match'\nimport { SafeFragment } from './SafeFragment'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type {\n AnyRoute,\n AnyRouter,\n DeepPartial,\n Expand,\n MakeOptionalPathParams,\n MakeOptionalSearchParams,\n MakeRouteMatchUnion,\n MaskOptions,\n MatchRouteOptions,\n RegisteredRouter,\n ResolveRoute,\n ToSubOptionsProps,\n} from '@tanstack/router-core'\n\ndeclare module '@tanstack/router-core' {\n export interface RouteMatchExtensions {\n meta?: Array<React.JSX.IntrinsicElements['meta'] | undefined>\n links?: Array<React.JSX.IntrinsicElements['link'] | undefined>\n scripts?: Array<React.JSX.IntrinsicElements['script'] | undefined>\n styles?: Array<React.JSX.IntrinsicElements['style'] | undefined>\n headScripts?: Array<React.JSX.IntrinsicElements['script'] | undefined>\n }\n}\n\n/**\n * Internal component that renders the router's active match tree with\n * suspense, error, and not-found boundaries. Rendered by `RouterProvider`.\n */\nexport function Matches() {\n const router = useRouter()\n const rootRoute: AnyRoute = router.routesById[rootRouteId]\n\n const PendingComponent =\n rootRoute.options.pendingComponent ?? router.options.defaultPendingComponent\n\n const pendingElement = PendingComponent ? <PendingComponent /> : null\n\n // Do not render a root Suspense during SSR or hydrating from SSR\n const ResolvedSuspense =\n (isServer ?? router.isServer) ||\n (typeof document !== 'undefined' && router.ssr)\n ? SafeFragment\n : React.Suspense\n\n const inner = (\n <ResolvedSuspense fallback={pendingElement}>\n {!(isServer ?? router.isServer) && <Transitioner />}\n <MatchesInner />\n </ResolvedSuspense>\n )\n\n return router.options.InnerWrap ? (\n <router.options.InnerWrap>{inner}</router.options.InnerWrap>\n ) : (\n inner\n )\n}\n\nfunction MatchesInner() {\n const router = useRouter()\n const _isServer = isServer ?? router.isServer\n const matchId = _isServer\n ? router.stores.firstMatchId.state\n : // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(router.stores.firstMatchId, (id) => id)\n const resetKey = _isServer\n ? router.stores.loadedAt.state\n : // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(router.stores.loadedAt, (loadedAt) => loadedAt)\n\n const matchComponent = matchId ? <Match matchId={matchId} /> : null\n\n return (\n <matchContext.Provider value={matchId}>\n {router.options.disableGlobalCatchBoundary ? (\n matchComponent\n ) : (\n <CatchBoundary\n getResetKey={() => resetKey}\n errorComponent={ErrorComponent}\n onCatch={\n process.env.NODE_ENV !== 'production'\n ? (error) => {\n console.warn(\n `Warning: The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!`,\n )\n console.warn(`Warning: ${error.message || error.toString()}`)\n }\n : undefined\n }\n >\n {matchComponent}\n </CatchBoundary>\n )}\n </matchContext.Provider>\n )\n}\n\nexport type UseMatchRouteOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n> = ToSubOptionsProps<TRouter, TFrom, TTo> &\n DeepPartial<MakeOptionalSearchParams<TRouter, TFrom, TTo>> &\n DeepPartial<MakeOptionalPathParams<TRouter, TFrom, TTo>> &\n MaskOptions<TRouter, TMaskFrom, TMaskTo> &\n MatchRouteOptions\n\n/**\n * Create a matcher function for testing locations against route definitions.\n *\n * The returned function accepts standard navigation options (`to`, `params`,\n * `search`, etc.) and returns either `false` (no match) or the matched params\n * object when the route matches the current or pending location.\n *\n * Useful for conditional rendering and active UI states.\n *\n * @returns A `matchRoute(options)` function that returns `false` or params.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchRouteHook\n */\nexport function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>() {\n const router = useRouter()\n\n if (!(isServer ?? router.isServer)) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(router.stores.matchRouteReactivity, (d) => d)\n }\n\n return React.useCallback(\n <\n const TFrom extends string = string,\n const TTo extends string | undefined = undefined,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n >(\n opts: UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n ):\n | false\n | Expand<ResolveRoute<TRouter, TFrom, TTo>['types']['allParams']> => {\n const { pending, caseSensitive, fuzzy, includeSearch, ...rest } = opts\n\n return router.matchRoute(rest as any, {\n pending,\n caseSensitive,\n fuzzy,\n includeSearch,\n })\n },\n [router],\n )\n}\n\nexport type MakeMatchRouteOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n> = UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns\n children?:\n | ((\n params?: Expand<\n ResolveRoute<TRouter, TFrom, TTo>['types']['allParams']\n >,\n ) => React.ReactNode)\n | React.ReactNode\n}\n\n/**\n * Component that conditionally renders its children based on whether a route\n * matches the provided `from`/`to` options. If `children` is a function, it\n * receives the matched params object.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/matchRouteComponent\n */\nexport function MatchRoute<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string = string,\n const TTo extends string | undefined = undefined,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(props: MakeMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): any {\n const matchRoute = useMatchRoute()\n const params = matchRoute(props as any) as boolean\n\n if (typeof props.children === 'function') {\n return (props.children as any)(params)\n }\n\n return params ? props.children : null\n}\n\nexport interface UseMatchesBaseOptions<\n TRouter extends AnyRouter,\n TSelected,\n TStructuralSharing,\n> {\n select?: (\n matches: Array<MakeRouteMatchUnion<TRouter>>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n}\n\nexport type UseMatchesResult<\n TRouter extends AnyRouter,\n TSelected,\n> = unknown extends TSelected ? Array<MakeRouteMatchUnion<TRouter>> : TSelected\n\nexport function useMatches<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n): UseMatchesResult<TRouter, TSelected> {\n const router = useRouter<TRouter>()\n const previousResult =\n React.useRef<ValidateSelected<TRouter, TSelected, TStructuralSharing>>(\n undefined,\n )\n\n if (isServer ?? router.isServer) {\n const matches = router.stores.activeMatchesSnapshot.state as Array<\n MakeRouteMatchUnion<TRouter>\n >\n return (opts?.select ? opts.select(matches) : matches) as UseMatchesResult<\n TRouter,\n TSelected\n >\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStore(router.stores.activeMatchesSnapshot, (matches) => {\n const selected = opts?.select\n ? opts.select(matches as Array<MakeRouteMatchUnion<TRouter>>)\n : (matches as any)\n\n if (opts?.structuralSharing ?? router.options.defaultStructuralSharing) {\n const shared = replaceEqualDeep(previousResult.current, selected)\n previousResult.current = shared\n return shared\n }\n\n return selected\n }) as UseMatchesResult<TRouter, TSelected>\n}\n\n/**\n * Read the full array of active route matches or select a derived subset.\n *\n * Useful for debugging, breadcrumbs, or aggregating metadata across matches.\n *\n * @returns The array of matches (or the selected value).\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchesHook\n */\n\n/**\n * Read the full array of active route matches or select a derived subset.\n *\n * Useful for debugging, breadcrumbs, or aggregating metadata across matches.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchesHook\n */\nexport function useParentMatches<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n): UseMatchesResult<TRouter, TSelected> {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches: Array<MakeRouteMatchUnion<TRouter>>) => {\n matches = matches.slice(\n 0,\n matches.findIndex((d) => d.id === contextMatchId),\n )\n return opts?.select ? opts.select(matches) : matches\n },\n structuralSharing: opts?.structuralSharing,\n } as any)\n}\n\n/**\n * Read the array of active route matches that are children of the current\n * match (or selected parent) in the match tree.\n */\nexport function useChildMatches<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n): UseMatchesResult<TRouter, TSelected> {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches: Array<MakeRouteMatchUnion<TRouter>>) => {\n matches = matches.slice(\n matches.findIndex((d) => d.id === contextMatchId) + 1,\n )\n return opts?.select ? opts.select(matches) : matches\n },\n structuralSharing: opts?.structuralSharing,\n } as any)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA2CA,SAAgB,UAAU;CACxB,MAAM,SAAS,WAAW;CAG1B,MAAM,mBAFsB,OAAO,WAAW,aAGlC,QAAQ,o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C1B,CAAQ"}
|
|
1
|
+
{"version":3,"file":"Matches.js","names":[],"sources":["../../src/Matches.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport { replaceEqualDeep, rootRouteId } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouter } from './useRouter'\nimport { Transitioner } from './Transitioner'\nimport { matchContext } from './matchContext'\nimport { Match } from './Match'\nimport { SafeFragment } from './SafeFragment'\nimport type {\n StructuralSharingOption,\n ValidateSelected,\n} from './structuralSharing'\nimport type {\n AnyRoute,\n AnyRouter,\n DeepPartial,\n Expand,\n MakeOptionalPathParams,\n MakeOptionalSearchParams,\n MakeRouteMatchUnion,\n MaskOptions,\n MatchRouteOptions,\n RegisteredRouter,\n ResolveRoute,\n ToSubOptionsProps,\n} from '@tanstack/router-core'\n\ndeclare module '@tanstack/router-core' {\n export interface RouteMatchExtensions {\n meta?: Array<React.JSX.IntrinsicElements['meta'] | undefined>\n links?: Array<React.JSX.IntrinsicElements['link'] | undefined>\n scripts?: Array<React.JSX.IntrinsicElements['script'] | undefined>\n styles?: Array<React.JSX.IntrinsicElements['style'] | undefined>\n headScripts?: Array<React.JSX.IntrinsicElements['script'] | undefined>\n }\n}\n\n/**\n * Internal component that renders the router's active match tree with\n * suspense, error, and not-found boundaries. Rendered by `RouterProvider`.\n */\nexport function Matches() {\n const router = useRouter()\n const rootRoute: AnyRoute = router.routesById[rootRouteId]\n\n const PendingComponent =\n rootRoute.options.pendingComponent ?? router.options.defaultPendingComponent\n\n const pendingElement = PendingComponent ? <PendingComponent /> : null\n\n // Do not render a root Suspense during SSR or hydrating from SSR\n const ResolvedSuspense =\n (isServer ?? router.isServer) ||\n (typeof document !== 'undefined' && router.ssr)\n ? SafeFragment\n : React.Suspense\n\n const inner = (\n <ResolvedSuspense fallback={pendingElement}>\n {!(isServer ?? router.isServer) && <Transitioner />}\n <MatchesInner />\n </ResolvedSuspense>\n )\n\n return router.options.InnerWrap ? (\n <router.options.InnerWrap>{inner}</router.options.InnerWrap>\n ) : (\n inner\n )\n}\n\nfunction MatchesInner() {\n const router = useRouter()\n const _isServer = isServer ?? router.isServer\n const matchId = _isServer\n ? router.stores.firstId.get()\n : // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(router.stores.firstId, (id) => id)\n const resetKey = _isServer\n ? router.stores.loadedAt.get()\n : // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(router.stores.loadedAt, (loadedAt) => loadedAt)\n\n const matchComponent = matchId ? <Match matchId={matchId} /> : null\n\n return (\n <matchContext.Provider value={matchId}>\n {router.options.disableGlobalCatchBoundary ? (\n matchComponent\n ) : (\n <CatchBoundary\n getResetKey={() => resetKey}\n errorComponent={ErrorComponent}\n onCatch={\n process.env.NODE_ENV !== 'production'\n ? (error) => {\n console.warn(\n `Warning: The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!`,\n )\n console.warn(`Warning: ${error.message || error.toString()}`)\n }\n : undefined\n }\n >\n {matchComponent}\n </CatchBoundary>\n )}\n </matchContext.Provider>\n )\n}\n\nexport type UseMatchRouteOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n> = ToSubOptionsProps<TRouter, TFrom, TTo> &\n DeepPartial<MakeOptionalSearchParams<TRouter, TFrom, TTo>> &\n DeepPartial<MakeOptionalPathParams<TRouter, TFrom, TTo>> &\n MaskOptions<TRouter, TMaskFrom, TMaskTo> &\n MatchRouteOptions\n\n/**\n * Create a matcher function for testing locations against route definitions.\n *\n * The returned function accepts standard navigation options (`to`, `params`,\n * `search`, etc.) and returns either `false` (no match) or the matched params\n * object when the route matches the current or pending location.\n *\n * Useful for conditional rendering and active UI states.\n *\n * @returns A `matchRoute(options)` function that returns `false` or params.\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchRouteHook\n */\nexport function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>() {\n const router = useRouter()\n\n if (!(isServer ?? router.isServer)) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(router.stores.matchRouteDeps, (d) => d)\n }\n\n return React.useCallback(\n <\n const TFrom extends string = string,\n const TTo extends string | undefined = undefined,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n >(\n opts: UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,\n ):\n | false\n | Expand<ResolveRoute<TRouter, TFrom, TTo>['types']['allParams']> => {\n const { pending, caseSensitive, fuzzy, includeSearch, ...rest } = opts\n\n return router.matchRoute(rest as any, {\n pending,\n caseSensitive,\n fuzzy,\n includeSearch,\n })\n },\n [router],\n )\n}\n\nexport type MakeMatchRouteOptions<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends string = string,\n TTo extends string | undefined = undefined,\n TMaskFrom extends string = TFrom,\n TMaskTo extends string = '',\n> = UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {\n // If a function is passed as a child, it will be given the `isActive` boolean to aid in further styling on the element it returns\n children?:\n | ((\n params?: Expand<\n ResolveRoute<TRouter, TFrom, TTo>['types']['allParams']\n >,\n ) => React.ReactNode)\n | React.ReactNode\n}\n\n/**\n * Component that conditionally renders its children based on whether a route\n * matches the provided `from`/`to` options. If `children` is a function, it\n * receives the matched params object.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/matchRouteComponent\n */\nexport function MatchRoute<\n TRouter extends AnyRouter = RegisteredRouter,\n const TFrom extends string = string,\n const TTo extends string | undefined = undefined,\n const TMaskFrom extends string = TFrom,\n const TMaskTo extends string = '',\n>(props: MakeMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): any {\n const matchRoute = useMatchRoute()\n const params = matchRoute(props as any) as boolean\n\n if (typeof props.children === 'function') {\n return (props.children as any)(params)\n }\n\n return params ? props.children : null\n}\n\nexport interface UseMatchesBaseOptions<\n TRouter extends AnyRouter,\n TSelected,\n TStructuralSharing,\n> {\n select?: (\n matches: Array<MakeRouteMatchUnion<TRouter>>,\n ) => ValidateSelected<TRouter, TSelected, TStructuralSharing>\n}\n\nexport type UseMatchesResult<\n TRouter extends AnyRouter,\n TSelected,\n> = unknown extends TSelected ? Array<MakeRouteMatchUnion<TRouter>> : TSelected\n\nexport function useMatches<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n): UseMatchesResult<TRouter, TSelected> {\n const router = useRouter<TRouter>()\n const previousResult =\n React.useRef<ValidateSelected<TRouter, TSelected, TStructuralSharing>>(\n undefined,\n )\n\n if (isServer ?? router.isServer) {\n const matches = router.stores.matches.get() as Array<\n MakeRouteMatchUnion<TRouter>\n >\n return (opts?.select ? opts.select(matches) : matches) as UseMatchesResult<\n TRouter,\n TSelected\n >\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStore(router.stores.matches, (matches) => {\n const selected = opts?.select\n ? opts.select(matches as Array<MakeRouteMatchUnion<TRouter>>)\n : (matches as any)\n\n if (opts?.structuralSharing ?? router.options.defaultStructuralSharing) {\n const shared = replaceEqualDeep(previousResult.current, selected)\n previousResult.current = shared\n return shared\n }\n\n return selected\n }) as UseMatchesResult<TRouter, TSelected>\n}\n\n/**\n * Read the full array of active route matches or select a derived subset.\n *\n * Useful for debugging, breadcrumbs, or aggregating metadata across matches.\n *\n * @returns The array of matches (or the selected value).\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchesHook\n */\n\n/**\n * Read the full array of active route matches or select a derived subset.\n *\n * Useful for debugging, breadcrumbs, or aggregating metadata across matches.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchesHook\n */\nexport function useParentMatches<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n): UseMatchesResult<TRouter, TSelected> {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches: Array<MakeRouteMatchUnion<TRouter>>) => {\n matches = matches.slice(\n 0,\n matches.findIndex((d) => d.id === contextMatchId),\n )\n return opts?.select ? opts.select(matches) : matches\n },\n structuralSharing: opts?.structuralSharing,\n } as any)\n}\n\n/**\n * Read the array of active route matches that are children of the current\n * match (or selected parent) in the match tree.\n */\nexport function useChildMatches<\n TRouter extends AnyRouter = RegisteredRouter,\n TSelected = unknown,\n TStructuralSharing extends boolean = boolean,\n>(\n opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> &\n StructuralSharingOption<TRouter, TSelected, TStructuralSharing>,\n): UseMatchesResult<TRouter, TSelected> {\n const contextMatchId = React.useContext(matchContext)\n\n return useMatches({\n select: (matches: Array<MakeRouteMatchUnion<TRouter>>) => {\n matches = matches.slice(\n matches.findIndex((d) => d.id === contextMatchId) + 1,\n )\n return opts?.select ? opts.select(matches) : matches\n },\n structuralSharing: opts?.structuralSharing,\n } as any)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA6CA,SAAgB,UAAU;CACxB,MAAM,SAAS,WAAW;CAG1B,MAAM,mBAFsB,OAAO,WAAW,aAGlC,QAAQ,oBAAoB,OAAO,QAAQ;CAEvD,MAAM,iBAAiB,mBAAmB,oBAAC,kBAAD,EAAoB,CAAA,GAAG;CASjE,MAAM,QACJ,sBANC,YAAY,OAAO,aACnB,OAAO,aAAa,eAAe,OAAO,MACvC,eACA,QAAM,UAGV;EAAkB,UAAU;YAA5B,CACG,EAAE,YAAY,OAAO,aAAa,oBAAC,cAAD,EAAgB,CAAA,EACnD,oBAAC,cAAD,EAAg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tC,MAAM,SAAS,WAAoB;CACnC,MAAM,iBACJ,QAAM,OACJ,KAAA,EACD;AAEH,KAAI,YAAY,OAAO,UAAU;EAC/B,MAAM,UAAU,OAAO,OAAO,QAAQ,KAAK;AAG3C,SAAQ,MAAM,SAAS,KAAK,OAAO,QAAQ,GAAG;;AAOhD,QAAO,SAAS,OAAO,OAAO,UAAU,YAAY;EAClD,MAAM,WAAW,MAAM,SACnB,KAAK,OAAO,QAA+C,GAC1D;AAEL,MAAI,MAAM,qBAAqB,OAAO,QAAQ,0BAA0B;GACtE,MAAM,SAAS,iBAAiB,eAAe,SAAS,SAAS;AACjE,kBAAe,UAAU;AACzB,UAAO;;AAGT,SAAO;GACP;;;;;;;;;;;;;;;;;AAmBJ,SAAgB,iBAKd,MAEsC;CACtC,MAAM,iBAAiB,QAAM,WAAW,aAAa;AAErD,QAAO,WAAW;EAChB,SAAS,YAAiD;AACxD,aAAU,QAAQ,MAChB,GACA,QAAQ,WAAW,MAAM,EAAE,OAAO,eAAe,CAClD;AACD,UAAO,MAAM,SAAS,KAAK,OAAO,QAAQ,GAAG;;EAE/C,mBAAmB,MAAM;EAC1B,CAAQ;;;;;;AAOX,SAAgB,gBAKd,MAEsC;CACtC,MAAM,iBAAiB,QAAM,WAAW,aAAa;AAErD,QAAO,WAAW;EAChB,SAAS,YAAiD;AACxD,aAAU,QAAQ,MAChB,QAAQ,WAAW,MAAM,EAAE,OAAO,eAAe,GAAG,EACrD;AACD,UAAO,MAAM,SAAS,KAAK,OAAO,QAAQ,GAAG;;EAE/C,mBAAmB,MAAM;EAC1B,CAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouterProvider.js","names":[],"sources":["../../src/RouterProvider.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"RouterProvider.js","names":[],"sources":["../../src/RouterProvider.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { Matches } from './Matches'\nimport { routerContext } from './routerContext'\nimport type {\n AnyRouter,\n RegisteredRouter,\n RouterOptions,\n} from '@tanstack/router-core'\n\n/**\n * Low-level provider that places the router into React context and optionally\n * updates router options from props. Most apps should use `RouterProvider`.\n */\nexport function RouterContextProvider<\n TRouter extends AnyRouter = RegisteredRouter,\n TDehydrated extends Record<string, any> = Record<string, any>,\n>({\n router,\n children,\n ...rest\n}: RouterProps<TRouter, TDehydrated> & {\n children: React.ReactNode\n}) {\n if (Object.keys(rest).length > 0) {\n // Allow the router to update options on the router instance\n router.update({\n ...router.options,\n ...rest,\n context: {\n ...router.options.context,\n ...rest.context,\n },\n })\n }\n\n const provider = (\n <routerContext.Provider value={router as AnyRouter}>\n {children}\n </routerContext.Provider>\n )\n\n if (router.options.Wrap) {\n return <router.options.Wrap>{provider}</router.options.Wrap>\n }\n\n return provider\n}\n\n/**\n * Top-level component that renders the active route matches and provides the\n * router to the React tree via context.\n *\n * Accepts the same options as `createRouter` via props to update the router\n * instance after creation.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/createRouterFunction\n */\nexport function RouterProvider<\n TRouter extends AnyRouter = RegisteredRouter,\n TDehydrated extends Record<string, any> = Record<string, any>,\n>({ router, ...rest }: RouterProps<TRouter, TDehydrated>) {\n return (\n <RouterContextProvider router={router} {...rest}>\n <Matches />\n </RouterContextProvider>\n )\n}\n\nexport type RouterProps<\n TRouter extends AnyRouter = RegisteredRouter,\n TDehydrated extends Record<string, any> = Record<string, any>,\n> = Omit<\n RouterOptions<\n TRouter['routeTree'],\n NonNullable<TRouter['options']['trailingSlash']>,\n NonNullable<TRouter['options']['defaultStructuralSharing']>,\n TRouter['history'],\n TDehydrated\n >,\n 'context'\n> & {\n router: TRouter\n context?: Partial<\n RouterOptions<\n TRouter['routeTree'],\n NonNullable<TRouter['options']['trailingSlash']>,\n NonNullable<TRouter['options']['defaultStructuralSharing']>,\n TRouter['history'],\n TDehydrated\n >['context']\n >\n}\n"],"mappings":";;;;;;;;;;AAeA,SAAgB,sBAGd,EACA,QACA,UACA,GAAG,QAGF;AACD,KAAI,OAAO,KAAK,KAAK,CAAC,SAAS,EAE7B,QAAO,OAAO;EACZ,GAAG,OAAO;EACV,GAAG;EACH,SAAS;GACP,GAAG,OAAO,QAAQ;GAClB,GAAG,KAAK;GACT;EACF,CAAC;CAGJ,MAAM,WACJ,oBAAC,cAAc,UAAf;EAAwB,OAAO;EAC5B;EACsB,CAAA;AAG3B,KAAI,OAAO,QAAQ,KACjB,QAAO,oBAAC,OAAO,QAAQ,MAAhB,EAAA,UAAsB,UAA+B,CAAA;AAG9D,QAAO;;;;;;;;;;;AAYT,SAAgB,eAGd,EAAE,QAAQ,GAAG,QAA2C;AACxD,QACE,oBAAC,uBAAD;EAA+B;EAAQ,GAAI;YACzC,oBAAC,SAAD,EAAW,CAAA;EACW,CAAA"}
|
package/dist/esm/Scripts.js
CHANGED
|
@@ -39,11 +39,12 @@ var Scripts = () => {
|
|
|
39
39
|
children
|
|
40
40
|
}));
|
|
41
41
|
if (isServer ?? router.isServer) {
|
|
42
|
-
const
|
|
43
|
-
|
|
42
|
+
const activeMatches = router.stores.matches.get();
|
|
43
|
+
const assetScripts = getAssetScripts(activeMatches);
|
|
44
|
+
return renderScripts(router, getScripts(activeMatches), assetScripts);
|
|
44
45
|
}
|
|
45
|
-
const assetScripts = useStore(router.stores.
|
|
46
|
-
return renderScripts(router, useStore(router.stores.
|
|
46
|
+
const assetScripts = useStore(router.stores.matches, getAssetScripts, deepEqual);
|
|
47
|
+
return renderScripts(router, useStore(router.stores.matches, getScripts, deepEqual), assetScripts);
|
|
47
48
|
};
|
|
48
49
|
function renderScripts(router, scripts, assetScripts) {
|
|
49
50
|
let serverBufferedScript = void 0;
|
package/dist/esm/Scripts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Scripts.js","names":[],"sources":["../../src/Scripts.tsx"],"sourcesContent":["import { useStore } from '@tanstack/react-store'\nimport { deepEqual } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { Asset } from './Asset'\nimport { useRouter } from './useRouter'\nimport type { RouterManagedTag } from '@tanstack/router-core'\n\n/**\n * Render body script tags collected from route matches and SSR manifests.\n * Should be placed near the end of the document body.\n */\nexport const Scripts = () => {\n const router = useRouter()\n const nonce = router.options.ssr?.nonce\n\n const getAssetScripts = (matches: Array<any>) => {\n const assetScripts: Array<RouterManagedTag> = []\n const manifest = router.ssr?.manifest\n\n if (!manifest) {\n return []\n }\n\n matches\n .map((match) => router.looseRoutesById[match.routeId]!)\n .forEach((route) =>\n manifest.routes[route.id]?.assets\n ?.filter((d) => d.tag === 'script')\n .forEach((asset) => {\n assetScripts.push({\n tag: 'script',\n attrs: { ...asset.attrs, nonce },\n children: asset.children,\n } as any)\n }),\n )\n\n return assetScripts\n }\n\n const getScripts = (matches: Array<any>): Array<RouterManagedTag> =>\n (\n matches\n .map((match) => match.scripts!)\n .flat(1)\n .filter(Boolean) as Array<RouterManagedTag>\n ).map(\n ({ children, ...script }) =>\n ({\n tag: 'script',\n attrs: {\n ...script,\n suppressHydrationWarning: true,\n nonce,\n },\n children,\n }) satisfies RouterManagedTag,\n )\n\n if (isServer ?? router.isServer) {\n const
|
|
1
|
+
{"version":3,"file":"Scripts.js","names":[],"sources":["../../src/Scripts.tsx"],"sourcesContent":["import { useStore } from '@tanstack/react-store'\nimport { deepEqual } from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { Asset } from './Asset'\nimport { useRouter } from './useRouter'\nimport type { RouterManagedTag } from '@tanstack/router-core'\n\n/**\n * Render body script tags collected from route matches and SSR manifests.\n * Should be placed near the end of the document body.\n */\nexport const Scripts = () => {\n const router = useRouter()\n const nonce = router.options.ssr?.nonce\n\n const getAssetScripts = (matches: Array<any>) => {\n const assetScripts: Array<RouterManagedTag> = []\n const manifest = router.ssr?.manifest\n\n if (!manifest) {\n return []\n }\n\n matches\n .map((match) => router.looseRoutesById[match.routeId]!)\n .forEach((route) =>\n manifest.routes[route.id]?.assets\n ?.filter((d) => d.tag === 'script')\n .forEach((asset) => {\n assetScripts.push({\n tag: 'script',\n attrs: { ...asset.attrs, nonce },\n children: asset.children,\n } as any)\n }),\n )\n\n return assetScripts\n }\n\n const getScripts = (matches: Array<any>): Array<RouterManagedTag> =>\n (\n matches\n .map((match) => match.scripts!)\n .flat(1)\n .filter(Boolean) as Array<RouterManagedTag>\n ).map(\n ({ children, ...script }) =>\n ({\n tag: 'script',\n attrs: {\n ...script,\n suppressHydrationWarning: true,\n nonce,\n },\n children,\n }) satisfies RouterManagedTag,\n )\n\n if (isServer ?? router.isServer) {\n const activeMatches = router.stores.matches.get()\n const assetScripts = getAssetScripts(activeMatches)\n const scripts = getScripts(activeMatches)\n return renderScripts(router, scripts, assetScripts)\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n const assetScripts = useStore(\n router.stores.matches,\n getAssetScripts,\n deepEqual,\n )\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n const scripts = useStore(router.stores.matches, getScripts, deepEqual)\n\n return renderScripts(router, scripts, assetScripts)\n}\n\nfunction renderScripts(\n router: ReturnType<typeof useRouter>,\n scripts: Array<RouterManagedTag>,\n assetScripts: Array<RouterManagedTag>,\n) {\n let serverBufferedScript: RouterManagedTag | undefined = undefined\n\n if (router.serverSsr) {\n serverBufferedScript = router.serverSsr.takeBufferedScripts()\n }\n\n const allScripts = [...scripts, ...assetScripts] as Array<RouterManagedTag>\n\n if (serverBufferedScript) {\n allScripts.unshift(serverBufferedScript)\n }\n\n return (\n <>\n {allScripts.map((asset, i) => (\n <Asset {...asset} key={`tsr-scripts-${asset.tag}-${i}`} />\n ))}\n </>\n )\n}\n"],"mappings":";;;;;;;;;;;;AAWA,IAAa,gBAAgB;CAC3B,MAAM,SAAS,WAAW;CAC1B,MAAM,QAAQ,OAAO,QAAQ,KAAK;CAElC,MAAM,mBAAmB,YAAwB;EAC/C,MAAM,eAAwC,EAAE;EAChD,MAAM,WAAW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
|
1
2
|
import { useLayoutEffect, usePrevious } from "./utils.js";
|
|
2
3
|
import { useRouter } from "./useRouter.js";
|
|
3
4
|
import { getLocationChangeInfo, handleHashScroll, trimPathRight } from "@tanstack/router-core";
|
|
@@ -12,11 +13,11 @@ function Transitioner() {
|
|
|
12
13
|
});
|
|
13
14
|
const [isTransitioning, setIsTransitioning] = React$1.useState(false);
|
|
14
15
|
const isLoading = useStore(router.stores.isLoading, (value) => value);
|
|
15
|
-
const
|
|
16
|
+
const hasPending = useStore(router.stores.hasPending, (value) => value);
|
|
16
17
|
const previousIsLoading = usePrevious(isLoading);
|
|
17
|
-
const isAnyPending = isLoading || isTransitioning ||
|
|
18
|
+
const isAnyPending = isLoading || isTransitioning || hasPending;
|
|
18
19
|
const previousIsAnyPending = usePrevious(isAnyPending);
|
|
19
|
-
const isPagePending = isLoading ||
|
|
20
|
+
const isPagePending = isLoading || hasPending;
|
|
20
21
|
const previousIsPagePending = usePrevious(isPagePending);
|
|
21
22
|
router.startTransition = (fn) => {
|
|
22
23
|
setIsTransitioning(true);
|
|
@@ -61,7 +62,7 @@ function Transitioner() {
|
|
|
61
62
|
useLayoutEffect(() => {
|
|
62
63
|
if (previousIsLoading && !isLoading) router.emit({
|
|
63
64
|
type: "onLoad",
|
|
64
|
-
...getLocationChangeInfo(router.stores.location.
|
|
65
|
+
...getLocationChangeInfo(router.stores.location.get(), router.stores.resolvedLocation.get())
|
|
65
66
|
});
|
|
66
67
|
}, [
|
|
67
68
|
previousIsLoading,
|
|
@@ -71,7 +72,7 @@ function Transitioner() {
|
|
|
71
72
|
useLayoutEffect(() => {
|
|
72
73
|
if (previousIsPagePending && !isPagePending) router.emit({
|
|
73
74
|
type: "onBeforeRouteMount",
|
|
74
|
-
...getLocationChangeInfo(router.stores.location.
|
|
75
|
+
...getLocationChangeInfo(router.stores.location.get(), router.stores.resolvedLocation.get())
|
|
75
76
|
});
|
|
76
77
|
}, [
|
|
77
78
|
isPagePending,
|
|
@@ -80,14 +81,14 @@ function Transitioner() {
|
|
|
80
81
|
]);
|
|
81
82
|
useLayoutEffect(() => {
|
|
82
83
|
if (previousIsAnyPending && !isAnyPending) {
|
|
83
|
-
const changeInfo = getLocationChangeInfo(router.stores.location.
|
|
84
|
+
const changeInfo = getLocationChangeInfo(router.stores.location.get(), router.stores.resolvedLocation.get());
|
|
84
85
|
router.emit({
|
|
85
86
|
type: "onResolved",
|
|
86
87
|
...changeInfo
|
|
87
88
|
});
|
|
88
89
|
batch(() => {
|
|
89
|
-
router.stores.status.
|
|
90
|
-
router.stores.resolvedLocation.
|
|
90
|
+
router.stores.status.set("idle");
|
|
91
|
+
router.stores.resolvedLocation.set(router.stores.location.get());
|
|
91
92
|
});
|
|
92
93
|
if (changeInfo.hrefChanged) handleHashScroll(router);
|
|
93
94
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transitioner.js","names":[],"sources":["../../src/Transitioner.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"Transitioner.js","names":[],"sources":["../../src/Transitioner.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport { batch, useStore } from '@tanstack/react-store'\nimport {\n getLocationChangeInfo,\n handleHashScroll,\n trimPathRight,\n} from '@tanstack/router-core'\nimport { useLayoutEffect, usePrevious } from './utils'\nimport { useRouter } from './useRouter'\n\nexport function Transitioner() {\n const router = useRouter()\n const mountLoadForRouter = React.useRef({ router, mounted: false })\n\n const [isTransitioning, setIsTransitioning] = React.useState(false)\n // Track pending state changes\n const isLoading = useStore(router.stores.isLoading, (value) => value)\n const hasPending = useStore(router.stores.hasPending, (value) => value)\n\n const previousIsLoading = usePrevious(isLoading)\n\n const isAnyPending = isLoading || isTransitioning || hasPending\n const previousIsAnyPending = usePrevious(isAnyPending)\n\n const isPagePending = isLoading || hasPending\n const previousIsPagePending = usePrevious(isPagePending)\n\n router.startTransition = (fn: () => void) => {\n setIsTransitioning(true)\n React.startTransition(() => {\n fn()\n setIsTransitioning(false)\n })\n }\n\n // Subscribe to location changes\n // and try to load the new location\n React.useEffect(() => {\n const unsub = router.history.subscribe(router.load)\n\n const nextLocation = router.buildLocation({\n to: router.latestLocation.pathname,\n search: true,\n params: true,\n hash: true,\n state: true,\n _includeValidateSearch: true,\n })\n\n // Check if the current URL matches the canonical form.\n // Compare publicHref (browser-facing URL) for consistency with\n // the server-side redirect check in router.beforeLoad.\n if (\n trimPathRight(router.latestLocation.publicHref) !==\n trimPathRight(nextLocation.publicHref)\n ) {\n router.commitLocation({ ...nextLocation, replace: true })\n }\n\n return () => {\n unsub()\n }\n }, [router, router.history])\n\n // Try to load the initial location\n useLayoutEffect(() => {\n if (\n // if we are hydrating from SSR, loading is triggered in ssr-client\n (typeof window !== 'undefined' && router.ssr) ||\n (mountLoadForRouter.current.router === router &&\n mountLoadForRouter.current.mounted)\n ) {\n return\n }\n mountLoadForRouter.current = { router, mounted: true }\n\n const tryLoad = async () => {\n try {\n await router.load()\n } catch (err) {\n console.error(err)\n }\n }\n\n tryLoad()\n }, [router])\n\n useLayoutEffect(() => {\n // The router was loading and now it's not\n if (previousIsLoading && !isLoading) {\n router.emit({\n type: 'onLoad', // When the new URL has committed, when the new matches have been loaded into state.matches\n ...getLocationChangeInfo(\n router.stores.location.get(),\n router.stores.resolvedLocation.get(),\n ),\n })\n }\n }, [previousIsLoading, router, isLoading])\n\n useLayoutEffect(() => {\n // emit onBeforeRouteMount\n if (previousIsPagePending && !isPagePending) {\n router.emit({\n type: 'onBeforeRouteMount',\n ...getLocationChangeInfo(\n router.stores.location.get(),\n router.stores.resolvedLocation.get(),\n ),\n })\n }\n }, [isPagePending, previousIsPagePending, router])\n\n useLayoutEffect(() => {\n if (previousIsAnyPending && !isAnyPending) {\n const changeInfo = getLocationChangeInfo(\n router.stores.location.get(),\n router.stores.resolvedLocation.get(),\n )\n router.emit({\n type: 'onResolved',\n ...changeInfo,\n })\n\n batch(() => {\n router.stores.status.set('idle')\n router.stores.resolvedLocation.set(router.stores.location.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AAM,OAAO,MAAM;YACZ,KAAK;AACZ,YAAQ,MAAM,IAAI;;;AAItB,WAAS;IACR,CAAC,OAAO,CAAC;AAEZ,uBAAsB;AAEpB,MAAI,qBAAqB,CAAC,UACxB,QAAO,KAAK;GACV,MAAM;GACN,GAAG,sBACD,OAAO,OAAO,SAAS,KAAK,EAC5B,OAAO,OAAO,iBAAiB,KAAK,CACrC;GACF,CAAC;IAEH;EAAC;EAAmB;EAAQ;EAAU,CAAC;AAE1C,uBAAsB;AAEpB,MAAI,yBAAyB,CAAC,cAC5B,QAAO,KAAK;GACV,MAAM;GACN,GAAG,sBACD,OAAO,OAAO,SAAS,KAAK,EAC5B,OAAO,OAAO,iBAAiB,KAAK,CACrC;GACF,CAAC;IAEH;EAAC;EAAe;EAAuB;EAAO,CAAC;AAElD,uBAAsB;AACpB,MAAI,wBAAwB,CAAC,cAAc;GACzC,MAAM,aAAa,sBACjB,OAAO,OAAO,SAAS,KAAK,EAC5B,OAAO,OAAO,iBAAiB,KAAK,CACrC;AACD,UAAO,KAAK;IACV,MAAM;IACN,GAAG;IACJ,CAAC;AAEF,eAAY;AACV,WAAO,OAAO,OAAO,IAAI,OAAO;AAChC,WAAO,OAAO,iBAAiB,IAAI,OAAO,OAAO,SAAS,KAAK,CAAC;KAChE;AAEF,OAAI,WAAW,YACb,kBAAiB,OAAO;;IAG3B;EAAC;EAAc;EAAsB;EAAO,CAAC;AAEhD,QAAO"}
|
|
@@ -112,8 +112,8 @@ function buildTagsFromMatches(router, nonce, matches, assetCrossOrigin) {
|
|
|
112
112
|
var useTags = (assetCrossOrigin) => {
|
|
113
113
|
const router = useRouter();
|
|
114
114
|
const nonce = router.options.ssr?.nonce;
|
|
115
|
-
if (isServer ?? router.isServer) return buildTagsFromMatches(router, nonce, router.stores.
|
|
116
|
-
const routeMeta = useStore(router.stores.
|
|
115
|
+
if (isServer ?? router.isServer) return buildTagsFromMatches(router, nonce, router.stores.matches.get(), assetCrossOrigin);
|
|
116
|
+
const routeMeta = useStore(router.stores.matches, (matches) => {
|
|
117
117
|
return matches.map((match) => match.meta).filter(Boolean);
|
|
118
118
|
}, deepEqual);
|
|
119
119
|
const meta = React$1.useMemo(() => {
|
|
@@ -163,7 +163,7 @@ var useTags = (assetCrossOrigin) => {
|
|
|
163
163
|
resultMeta.reverse();
|
|
164
164
|
return resultMeta;
|
|
165
165
|
}, [routeMeta, nonce]);
|
|
166
|
-
const links = useStore(router.stores.
|
|
166
|
+
const links = useStore(router.stores.matches, (matches) => {
|
|
167
167
|
const constructed = matches.map((match) => match.links).filter(Boolean).flat(1).map((link) => ({
|
|
168
168
|
tag: "link",
|
|
169
169
|
attrs: {
|
|
@@ -183,7 +183,7 @@ var useTags = (assetCrossOrigin) => {
|
|
|
183
183
|
}));
|
|
184
184
|
return [...constructed, ...assets];
|
|
185
185
|
}, deepEqual);
|
|
186
|
-
const preloadLinks = useStore(router.stores.
|
|
186
|
+
const preloadLinks = useStore(router.stores.matches, (matches) => {
|
|
187
187
|
const preloadLinks = [];
|
|
188
188
|
matches.map((match) => router.looseRoutesById[match.routeId]).forEach((route) => router.ssr?.manifest?.routes[route.id]?.preloads?.filter(Boolean).forEach((preload) => {
|
|
189
189
|
const preloadLink = resolveManifestAssetLink(preload);
|
|
@@ -199,7 +199,7 @@ var useTags = (assetCrossOrigin) => {
|
|
|
199
199
|
}));
|
|
200
200
|
return preloadLinks;
|
|
201
201
|
}, deepEqual);
|
|
202
|
-
const styles = useStore(router.stores.
|
|
202
|
+
const styles = useStore(router.stores.matches, (matches) => matches.map((match) => match.styles).flat(1).filter(Boolean).map(({ children, ...attrs }) => ({
|
|
203
203
|
tag: "style",
|
|
204
204
|
attrs: {
|
|
205
205
|
...attrs,
|
|
@@ -207,7 +207,7 @@ var useTags = (assetCrossOrigin) => {
|
|
|
207
207
|
},
|
|
208
208
|
children
|
|
209
209
|
})), deepEqual);
|
|
210
|
-
const headScripts = useStore(router.stores.
|
|
210
|
+
const headScripts = useStore(router.stores.matches, (matches) => matches.map((match) => match.headScripts).flat(1).filter(Boolean).map(({ children, ...script }) => ({
|
|
211
211
|
tag: "script",
|
|
212
212
|
attrs: {
|
|
213
213
|
...script,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headContentUtils.js","names":[],"sources":["../../src/headContentUtils.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport {\n deepEqual,\n escapeHtml,\n getAssetCrossOrigin,\n resolveManifestAssetLink,\n} from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\nimport type {\n AssetCrossOriginConfig,\n RouterManagedTag,\n} from '@tanstack/router-core'\n\nfunction buildTagsFromMatches(\n router: ReturnType<typeof useRouter>,\n nonce: string | undefined,\n matches: Array<any>,\n assetCrossOrigin?: AssetCrossOriginConfig,\n): Array<RouterManagedTag> {\n const routeMeta = matches.map((match) => match.meta!).filter(Boolean)\n\n const resultMeta: Array<RouterManagedTag> = []\n const metaByAttribute: Record<string, true> = {}\n let title: RouterManagedTag | undefined\n for (let i = routeMeta.length - 1; i >= 0; i--) {\n const metas = routeMeta[i]!\n for (let j = metas.length - 1; j >= 0; j--) {\n const m = metas[j]\n if (!m) continue\n\n if (m.title) {\n if (!title) {\n title = {\n tag: 'title',\n children: m.title,\n }\n }\n } else if ('script:ld+json' in m) {\n try {\n const json = JSON.stringify(m['script:ld+json'])\n resultMeta.push({\n tag: 'script',\n attrs: {\n type: 'application/ld+json',\n },\n children: escapeHtml(json),\n })\n } catch {\n // Skip invalid JSON-LD objects\n }\n } else {\n const attribute = m.name ?? m.property\n if (attribute) {\n if (metaByAttribute[attribute]) {\n continue\n } else {\n metaByAttribute[attribute] = true\n }\n }\n\n resultMeta.push({\n tag: 'meta',\n attrs: {\n ...m,\n nonce,\n },\n })\n }\n }\n }\n\n if (title) {\n resultMeta.push(title)\n }\n\n if (nonce) {\n resultMeta.push({\n tag: 'meta',\n attrs: {\n property: 'csp-nonce',\n content: nonce,\n },\n })\n }\n resultMeta.reverse()\n\n const constructedLinks = matches\n .map((match) => match.links!)\n .filter(Boolean)\n .flat(1)\n .map((link) => ({\n tag: 'link',\n attrs: {\n ...link,\n nonce,\n },\n })) satisfies Array<RouterManagedTag>\n\n const manifest = router.ssr?.manifest\n const assetLinks = matches\n .map((match) => manifest?.routes[match.routeId]?.assets ?? [])\n .filter(Boolean)\n .flat(1)\n .filter((asset) => asset.tag === 'link')\n .map(\n (asset) =>\n ({\n tag: 'link',\n attrs: {\n ...asset.attrs,\n crossOrigin:\n getAssetCrossOrigin(assetCrossOrigin, 'stylesheet') ??\n asset.attrs?.crossOrigin,\n suppressHydrationWarning: true,\n nonce,\n },\n }) satisfies RouterManagedTag,\n )\n\n const preloadLinks: Array<RouterManagedTag> = []\n matches\n .map((match) => router.looseRoutesById[match.routeId]!)\n .forEach((route) =>\n router.ssr?.manifest?.routes[route.id]?.preloads\n ?.filter(Boolean)\n .forEach((preload) => {\n const preloadLink = resolveManifestAssetLink(preload)\n preloadLinks.push({\n tag: 'link',\n attrs: {\n rel: 'modulepreload',\n href: preloadLink.href,\n crossOrigin:\n getAssetCrossOrigin(assetCrossOrigin, 'modulepreload') ??\n preloadLink.crossOrigin,\n nonce,\n },\n })\n }),\n )\n\n const styles = (\n matches\n .map((match) => match.styles!)\n .flat(1)\n .filter(Boolean) as Array<RouterManagedTag>\n ).map(({ children, ...attrs }) => ({\n tag: 'style',\n attrs: {\n ...attrs,\n nonce,\n },\n children,\n }))\n\n const headScripts = (\n matches\n .map((match) => match.headScripts!)\n .flat(1)\n .filter(Boolean) as Array<RouterManagedTag>\n ).map(({ children, ...script }) => ({\n tag: 'script',\n attrs: {\n ...script,\n nonce,\n },\n children,\n }))\n\n return uniqBy(\n [\n ...resultMeta,\n ...preloadLinks,\n ...constructedLinks,\n ...assetLinks,\n ...styles,\n ...headScripts,\n ] as Array<RouterManagedTag>,\n (d) => JSON.stringify(d),\n )\n}\n\n/**\n * Build the list of head/link/meta/script tags to render for active matches.\n * Used internally by `HeadContent`.\n */\nexport const useTags = (assetCrossOrigin?: AssetCrossOriginConfig) => {\n const router = useRouter()\n const nonce = router.options.ssr?.nonce\n\n if (isServer ?? router.isServer) {\n return buildTagsFromMatches(\n router,\n nonce,\n router.stores.activeMatchesSnapshot.state,\n assetCrossOrigin,\n )\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n const routeMeta = useStore(\n router.stores.activeMatchesSnapshot,\n (matches) => {\n return matches.map((match) => match.meta!).filter(Boolean)\n },\n deepEqual,\n )\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n const meta: Array<RouterManagedTag> = React.useMemo(() => {\n const resultMeta: Array<RouterManagedTag> = []\n const metaByAttribute: Record<string, true> = {}\n let title: RouterManagedTag | undefined\n for (let i = routeMeta.length - 1; i >= 0; i--) {\n const metas = routeMeta[i]!\n for (let j = metas.length - 1; j >= 0; j--) {\n const m = metas[j]\n if (!m) continue\n\n if (m.title) {\n if (!title) {\n title = {\n tag: 'title',\n children: m.title,\n }\n }\n } else if ('script:ld+json' in m) {\n // Handle JSON-LD structured data\n // Content is HTML-escaped to prevent XSS when injected via dangerouslySetInnerHTML\n try {\n const json = JSON.stringify(m['script:ld+json'])\n resultMeta.push({\n tag: 'script',\n attrs: {\n type: 'application/ld+json',\n },\n children: escapeHtml(json),\n })\n } catch {\n // Skip invalid JSON-LD objects\n }\n } else {\n const attribute = m.name ?? m.property\n if (attribute) {\n if (metaByAttribute[attribute]) {\n continue\n } else {\n metaByAttribute[attribute] = true\n }\n }\n\n resultMeta.push({\n tag: 'meta',\n attrs: {\n ...m,\n nonce,\n },\n })\n }\n }\n }\n\n if (title) {\n resultMeta.push(title)\n }\n\n if (nonce) {\n resultMeta.push({\n tag: 'meta',\n attrs: {\n property: 'csp-nonce',\n content: nonce,\n },\n })\n }\n resultMeta.reverse()\n\n return resultMeta\n }, [routeMeta, nonce])\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n const links = useStore(\n router.stores.activeMatchesSnapshot,\n (matches) => {\n const constructed = matches\n .map((match) => match.links!)\n .filter(Boolean)\n .flat(1)\n .map((link) => ({\n tag: 'link',\n attrs: {\n ...link,\n nonce,\n },\n })) satisfies Array<RouterManagedTag>\n\n const manifest = router.ssr?.manifest\n\n // These are the assets extracted from the ViteManifest\n // using the `startManifestPlugin`\n const assets = matches\n .map((match) => manifest?.routes[match.routeId]?.assets ?? [])\n .filter(Boolean)\n .flat(1)\n .filter((asset) => asset.tag === 'link')\n .map(\n (asset) =>\n ({\n tag: 'link',\n attrs: {\n ...asset.attrs,\n crossOrigin:\n getAssetCrossOrigin(assetCrossOrigin, 'stylesheet') ??\n asset.attrs?.crossOrigin,\n suppressHydrationWarning: true,\n nonce,\n },\n }) satisfies RouterManagedTag,\n )\n\n return [...constructed, ...assets]\n },\n deepEqual,\n )\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n const preloadLinks = useStore(\n router.stores.activeMatchesSnapshot,\n (matches) => {\n const preloadLinks: Array<RouterManagedTag> = []\n\n matches\n .map((match) => router.looseRoutesById[match.routeId]!)\n .forEach((route) =>\n router.ssr?.manifest?.routes[route.id]?.preloads\n ?.filter(Boolean)\n .forEach((preload) => {\n const preloadLink = resolveManifestAssetLink(preload)\n preloadLinks.push({\n tag: 'link',\n attrs: {\n rel: 'modulepreload',\n href: preloadLink.href,\n crossOrigin:\n getAssetCrossOrigin(assetCrossOrigin, 'modulepreload') ??\n preloadLink.crossOrigin,\n nonce,\n },\n })\n }),\n )\n\n return preloadLinks\n },\n deepEqual,\n )\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n const styles = useStore(\n router.stores.activeMatchesSnapshot,\n (matches) =>\n (\n matches\n .map((match) => match.styles!)\n .flat(1)\n .filter(Boolean) as Array<RouterManagedTag>\n ).map(({ children, ...attrs }) => ({\n tag: 'style',\n attrs: {\n ...attrs,\n nonce,\n },\n children,\n })),\n deepEqual,\n )\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n const headScripts: Array<RouterManagedTag> = useStore(\n router.stores.activeMatchesSnapshot,\n (matches) =>\n (\n matches\n .map((match) => match.headScripts!)\n .flat(1)\n .filter(Boolean) as Array<RouterManagedTag>\n ).map(({ children, ...script }) => ({\n tag: 'script',\n attrs: {\n ...script,\n nonce,\n },\n children,\n })),\n deepEqual,\n )\n\n return uniqBy(\n [\n ...meta,\n ...preloadLinks,\n ...links,\n ...styles,\n ...headScripts,\n ] as Array<RouterManagedTag>,\n (d) => {\n return JSON.stringify(d)\n },\n )\n}\n\nexport function uniqBy<T>(arr: Array<T>, fn: (item: T) => string) {\n const seen = new Set<string>()\n return arr.filter((item) => {\n const key = fn(item)\n if (seen.has(key)) {\n return false\n }\n seen.add(key)\n return true\n })\n}\n"],"mappings":";;;;;;AAeA,SAAS,qBACP,QACA,OACA,SACA,kBACyB;CACzB,MAAM,YAAY,QAAQ,KAAK,UAAU,MAAM,KAAM,CAAC,OAAO,QAAQ;CAErE,MAAM,aAAsC,EAAE;CAC9C,MAAM,kBAAwC,EAAE;CAChD,IAAI;AACJ,MAAK,IAAI,IAAI,UAAU,SAAS,GAAG,KAAK,GAAG,KAAK;EAC9C,MAAM,QAAQ,UAAU;AACxB,OAAK,IAAI,IAAI,MAAM,SAAS,GAAG,KAAK,GAAG,KAAK;GAC1C,MAAM,IAAI,MAAM;AAChB,OAAI,CAAC,EAAG;AAER,OAAI,EAAE;QACA,CAAC,MACH,SAAQ;KACN,KAAK;KACL,UAAU,EAAE;KACb;cAEM,oBAAoB,EAC7B,KAAI;IACF,MAAM,OAAO,KAAK,UAAU,EAAE,kBAAkB;AAChD,eAAW,KAAK;KACd,KAAK;KACL,OAAO,EACL,MAAM,uBACP;KACD,UAAU,WAAW,KAAK;KAC3B,CAAC;WACI;QAGH;IACL,MAAM,YAAY,EAAE,QAAQ,EAAE;AAC9B,QAAI,UACF,KAAI,gBAAgB,WAClB;QAEA,iB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D;IACF,CAAC;IACF,CACL;AAEH,SAAO;IAET,UACD;CAGD,MAAM,SAAS,SACb,OAAO,OAAO,wBACb,YAEG,QACG,KAAK,UAAU,MAAM,OAAQ,CAC7B,KAAK,EAAE,CACP,OAAO,QAAQ,CAClB,KAAK,EAAE,UAAU,GAAG,aAAa;EACjC,KAAK;EACL,OAAO;GACL,GAAG;GACH;GACD;EACD;EACD,EAAE,EACL,UACD;CAGD,MAAM,cAAuC,SAC3C,OAAO,OAAO,wBACb,YAEG,QACG,KAAK,UAAU,MAAM,YAAa,CAClC,KAAK,EAAE,CACP,OAAO,QAAQ,CAClB,KAAK,EAAE,UAAU,GAAG,cAAc;EAClC,KAAK;EACL,OAAO;GACL,GAAG;GACH;GACD;EACD;EACD,EAAE,EACL,UACD;AAED,QAAO,OACL;EACE,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACJ,GACA,MAAM;AACL,SAAO,KAAK,UAAU,EAAE;GAE3B;;AAGH,SAAgB,OAAU,KAAe,IAAyB;CAChE,MAAM,uBAAO,IAAI,KAAa;AAC9B,QAAO,IAAI,QAAQ,SAAS;EAC1B,MAAM,MAAM,GAAG,KAAK;AACpB,MAAI,KAAK,IAAI,IAAI,CACf,QAAO;AAET,OAAK,IAAI,IAAI;AACb,SAAO;GACP"}
|
|
1
|
+
{"version":3,"file":"headContentUtils.js","names":[],"sources":["../../src/headContentUtils.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport {\n deepEqual,\n escapeHtml,\n getAssetCrossOrigin,\n resolveManifestAssetLink,\n} from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\nimport type {\n AssetCrossOriginConfig,\n RouterManagedTag,\n} from '@tanstack/router-core'\n\nfunction buildTagsFromMatches(\n router: ReturnType<typeof useRouter>,\n nonce: string | undefined,\n matches: Array<any>,\n assetCrossOrigin?: AssetCrossOriginConfig,\n): Array<RouterManagedTag> {\n const routeMeta = matches.map((match) => match.meta!).filter(Boolean)\n\n const resultMeta: Array<RouterManagedTag> = []\n const metaByAttribute: Record<string, true> = {}\n let title: RouterManagedTag | undefined\n for (let i = routeMeta.length - 1; i >= 0; i--) {\n const metas = routeMeta[i]!\n for (let j = metas.length - 1; j >= 0; j--) {\n const m = metas[j]\n if (!m) continue\n\n if (m.title) {\n if (!title) {\n title = {\n tag: 'title',\n children: m.title,\n }\n }\n } else if ('script:ld+json' in m) {\n try {\n const json = JSON.stringify(m['script:ld+json'])\n resultMeta.push({\n tag: 'script',\n attrs: {\n type: 'application/ld+json',\n },\n children: escapeHtml(json),\n })\n } catch {\n // Skip invalid JSON-LD objects\n }\n } else {\n const attribute = m.name ?? m.property\n if (attribute) {\n if (metaByAttribute[attribute]) {\n continue\n } else {\n metaByAttribute[attribute] = true\n }\n }\n\n resultMeta.push({\n tag: 'meta',\n attrs: {\n ...m,\n nonce,\n },\n })\n }\n }\n }\n\n if (title) {\n resultMeta.push(title)\n }\n\n if (nonce) {\n resultMeta.push({\n tag: 'meta',\n attrs: {\n property: 'csp-nonce',\n content: nonce,\n },\n })\n }\n resultMeta.reverse()\n\n const constructedLinks = matches\n .map((match) => match.links!)\n .filter(Boolean)\n .flat(1)\n .map((link) => ({\n tag: 'link',\n attrs: {\n ...link,\n nonce,\n },\n })) satisfies Array<RouterManagedTag>\n\n const manifest = router.ssr?.manifest\n const assetLinks = matches\n .map((match) => manifest?.routes[match.routeId]?.assets ?? [])\n .filter(Boolean)\n .flat(1)\n .filter((asset) => asset.tag === 'link')\n .map(\n (asset) =>\n ({\n tag: 'link',\n attrs: {\n ...asset.attrs,\n crossOrigin:\n getAssetCrossOrigin(assetCrossOrigin, 'stylesheet') ??\n asset.attrs?.crossOrigin,\n suppressHydrationWarning: true,\n nonce,\n },\n }) satisfies RouterManagedTag,\n )\n\n const preloadLinks: Array<RouterManagedTag> = []\n matches\n .map((match) => router.looseRoutesById[match.routeId]!)\n .forEach((route) =>\n router.ssr?.manifest?.routes[route.id]?.preloads\n ?.filter(Boolean)\n .forEach((preload) => {\n const preloadLink = resolveManifestAssetLink(preload)\n preloadLinks.push({\n tag: 'link',\n attrs: {\n rel: 'modulepreload',\n href: preloadLink.href,\n crossOrigin:\n getAssetCrossOrigin(assetCrossOrigin, 'modulepreload') ??\n preloadLink.crossOrigin,\n nonce,\n },\n })\n }),\n )\n\n const styles = (\n matches\n .map((match) => match.styles!)\n .flat(1)\n .filter(Boolean) as Array<RouterManagedTag>\n ).map(({ children, ...attrs }) => ({\n tag: 'style',\n attrs: {\n ...attrs,\n nonce,\n },\n children,\n }))\n\n const headScripts = (\n matches\n .map((match) => match.headScripts!)\n .flat(1)\n .filter(Boolean) as Array<RouterManagedTag>\n ).map(({ children, ...script }) => ({\n tag: 'script',\n attrs: {\n ...script,\n nonce,\n },\n children,\n }))\n\n return uniqBy(\n [\n ...resultMeta,\n ...preloadLinks,\n ...constructedLinks,\n ...assetLinks,\n ...styles,\n ...headScripts,\n ] as Array<RouterManagedTag>,\n (d) => JSON.stringify(d),\n )\n}\n\n/**\n * Build the list of head/link/meta/script tags to render for active matches.\n * Used internally by `HeadContent`.\n */\nexport const useTags = (assetCrossOrigin?: AssetCrossOriginConfig) => {\n const router = useRouter()\n const nonce = router.options.ssr?.nonce\n\n if (isServer ?? router.isServer) {\n return buildTagsFromMatches(\n router,\n nonce,\n router.stores.matches.get(),\n assetCrossOrigin,\n )\n }\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n const routeMeta = useStore(\n router.stores.matches,\n (matches) => {\n return matches.map((match) => match.meta!).filter(Boolean)\n },\n deepEqual,\n )\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n const meta: Array<RouterManagedTag> = React.useMemo(() => {\n const resultMeta: Array<RouterManagedTag> = []\n const metaByAttribute: Record<string, true> = {}\n let title: RouterManagedTag | undefined\n for (let i = routeMeta.length - 1; i >= 0; i--) {\n const metas = routeMeta[i]!\n for (let j = metas.length - 1; j >= 0; j--) {\n const m = metas[j]\n if (!m) continue\n\n if (m.title) {\n if (!title) {\n title = {\n tag: 'title',\n children: m.title,\n }\n }\n } else if ('script:ld+json' in m) {\n // Handle JSON-LD structured data\n // Content is HTML-escaped to prevent XSS when injected via dangerouslySetInnerHTML\n try {\n const json = JSON.stringify(m['script:ld+json'])\n resultMeta.push({\n tag: 'script',\n attrs: {\n type: 'application/ld+json',\n },\n children: escapeHtml(json),\n })\n } catch {\n // Skip invalid JSON-LD objects\n }\n } else {\n const attribute = m.name ?? m.property\n if (attribute) {\n if (metaByAttribute[attribute]) {\n continue\n } else {\n metaByAttribute[attribute] = true\n }\n }\n\n resultMeta.push({\n tag: 'meta',\n attrs: {\n ...m,\n nonce,\n },\n })\n }\n }\n }\n\n if (title) {\n resultMeta.push(title)\n }\n\n if (nonce) {\n resultMeta.push({\n tag: 'meta',\n attrs: {\n property: 'csp-nonce',\n content: nonce,\n },\n })\n }\n resultMeta.reverse()\n\n return resultMeta\n }, [routeMeta, nonce])\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n const links = useStore(\n router.stores.matches,\n (matches) => {\n const constructed = matches\n .map((match) => match.links!)\n .filter(Boolean)\n .flat(1)\n .map((link) => ({\n tag: 'link',\n attrs: {\n ...link,\n nonce,\n },\n })) satisfies Array<RouterManagedTag>\n\n const manifest = router.ssr?.manifest\n\n // These are the assets extracted from the ViteManifest\n // using the `startManifestPlugin`\n const assets = matches\n .map((match) => manifest?.routes[match.routeId]?.assets ?? [])\n .filter(Boolean)\n .flat(1)\n .filter((asset) => asset.tag === 'link')\n .map(\n (asset) =>\n ({\n tag: 'link',\n attrs: {\n ...asset.attrs,\n crossOrigin:\n getAssetCrossOrigin(assetCrossOrigin, 'stylesheet') ??\n asset.attrs?.crossOrigin,\n suppressHydrationWarning: true,\n nonce,\n },\n }) satisfies RouterManagedTag,\n )\n\n return [...constructed, ...assets]\n },\n deepEqual,\n )\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n const preloadLinks = useStore(\n router.stores.matches,\n (matches) => {\n const preloadLinks: Array<RouterManagedTag> = []\n\n matches\n .map((match) => router.looseRoutesById[match.routeId]!)\n .forEach((route) =>\n router.ssr?.manifest?.routes[route.id]?.preloads\n ?.filter(Boolean)\n .forEach((preload) => {\n const preloadLink = resolveManifestAssetLink(preload)\n preloadLinks.push({\n tag: 'link',\n attrs: {\n rel: 'modulepreload',\n href: preloadLink.href,\n crossOrigin:\n getAssetCrossOrigin(assetCrossOrigin, 'modulepreload') ??\n preloadLink.crossOrigin,\n nonce,\n },\n })\n }),\n )\n\n return preloadLinks\n },\n deepEqual,\n )\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n const styles = useStore(\n router.stores.matches,\n (matches) =>\n (\n matches\n .map((match) => match.styles!)\n .flat(1)\n .filter(Boolean) as Array<RouterManagedTag>\n ).map(({ children, ...attrs }) => ({\n tag: 'style',\n attrs: {\n ...attrs,\n nonce,\n },\n children,\n })),\n deepEqual,\n )\n\n // eslint-disable-next-line react-hooks/rules-of-hooks -- condition is static\n const headScripts: Array<RouterManagedTag> = useStore(\n router.stores.matches,\n (matches) =>\n (\n matches\n .map((match) => match.headScripts!)\n .flat(1)\n .filter(Boolean) as Array<RouterManagedTag>\n ).map(({ children, ...script }) => ({\n tag: 'script',\n attrs: {\n ...script,\n nonce,\n },\n children,\n })),\n deepEqual,\n )\n\n return uniqBy(\n [\n ...meta,\n ...preloadLinks,\n ...links,\n ...styles,\n ...headScripts,\n ] as Array<RouterManagedTag>,\n (d) => {\n return JSON.stringify(d)\n },\n )\n}\n\nexport function uniqBy<T>(arr: Array<T>, fn: (item: T) => string) {\n const seen = new Set<string>()\n return arr.filter((item) => {\n const key = fn(item)\n if (seen.has(key)) {\n return false\n }\n seen.add(key)\n return true\n })\n}\n"],"mappings":";;;;;;AAeA,SAAS,qBACP,QACA,OACA,SACA,kBACyB;CACzB,MAAM,YAAY,QAAQ,KAAK,UAAU,M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H,SAAgB,OAAU,KAAe,IAAyB;CAChE,MAAM,uBAAO,IAAI,KAAa;AAC9B,QAAO,IAAI,QAAQ,SAAS;EAC1B,MAAM,MAAM,GAAG,KAAK;AACpB,MAAI,KAAK,IAAI,IAAI,CACf,QAAO;AAET,OAAK,IAAI,IAAI;AACb,SAAO;GACP"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export { CatchNotFound, DefaultGlobalNotFound } from './not-found.js';
|
|
|
40
40
|
export { notFound, isNotFound } from '@tanstack/router-core';
|
|
41
41
|
export type { NotFoundError } from '@tanstack/router-core';
|
|
42
42
|
export type { ValidateLinkOptions, InferStructuralSharing, ValidateUseSearchOptions, ValidateUseParamsOptions, ValidateLinkOptionsArray, } from './typePrimitives.js';
|
|
43
|
-
export type { ValidateFromPath, ValidateToPath, ValidateSearch, ValidateParams, InferFrom, InferTo, InferMaskTo, InferMaskFrom, ValidateNavigateOptions, ValidateNavigateOptionsArray, ValidateRedirectOptions, ValidateRedirectOptionsArray, ValidateId, InferStrict, InferShouldThrow, InferSelected, ValidateUseSearchResult, ValidateUseParamsResult, } from '@tanstack/router-core';
|
|
43
|
+
export type { ValidateFromPath, ValidateToPath, ValidateSearch, ValidateParams, InferFrom, InferTo, InferMaskTo, InferMaskFrom, ValidateNavigateOptions, ValidateNavigateOptionsArray, ValidateRedirectOptions, ValidateRedirectOptionsArray, ValidateId, InferStrict, InferShouldThrow, InferSelected, ValidateUseSearchResult, ValidateUseParamsResult, SerializerExtensions, RegisteredSerializableInput, Serializable, } from '@tanstack/router-core';
|
|
44
44
|
export { ScriptOnce } from './ScriptOnce.js';
|
|
45
45
|
export { Asset } from './Asset.js';
|
|
46
46
|
export { HeadContent } from './HeadContent.js';
|
package/dist/esm/index.dev.js
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/link.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { useForwardedRef, useIntersectionObserver } from "./utils.js";
|
|
2
3
|
import { useHydrated } from "./ClientOnly.js";
|
|
3
4
|
import { useRouter } from "./useRouter.js";
|
|
@@ -78,7 +79,7 @@ function useLinkProps(options, forwardedRef) {
|
|
|
78
79
|
})();
|
|
79
80
|
const isActive = (() => {
|
|
80
81
|
if (externalLink) return false;
|
|
81
|
-
const currentLocation = router.stores.location.
|
|
82
|
+
const currentLocation = router.stores.location.get();
|
|
82
83
|
const exact = activeOptions?.exact ?? false;
|
|
83
84
|
if (exact) {
|
|
84
85
|
if (!exactPathTest(currentLocation.pathname, next.pathname, router.basepath)) return false;
|