MCPcopy Create free account
hub / github.com/TanStack/router / executeRouter

Function executeRouter

packages/start-server-core/src/createStartHandler.ts:814–888  ·  view source on GitHub ↗
(
          serverContext: TODO,
          matchedRoutes: ReadonlyArray<AnyRoute>,
          routerInstance: AnyRouter,
        )

Source from the content-addressed store, hash-verified

812 // Runs as the route pipeline's terminal, which waits on the request
813 // signal and disposes a result that settles after an abort.
814 const executeRouter = async (
815 serverContext: TODO,
816 matchedRoutes: ReadonlyArray<AnyRoute>,
817 routerInstance: AnyRouter,
818 ): Promise<SsrResponse> => {
819 if (
820 !/(^|,)\s*(\*\/\*|text\/html)/.test(
821 request.headers.get('Accept') || '*/*',
822 )
823 ) {
824 return normalizeSsrResponse(
825 Response.json(
826 { error: 'Only HTML requests are supported here' },
827 { status: 406 },
828 ),
829 )
830 }
831
832 const pendingManifest = resolveManifestForRequest({
833 request,
834 requestInlineCss: requestOpts?.inlineCss,
835 getBaseManifest: () => getBaseManifest(matchedRoutes),
836 })
837 const manifest = isPromise(pendingManifest)
838 ? await waitForRequest(pendingManifest, signal)
839 : pendingManifest
840
841 const earlyHints = createEarlyHintsForRequest(requestOpts)
842
843 earlyHints?.collectStatic({ manifest, matchedRoutes })
844
845 // The request's stored context, not the resolver's template: RSC
846 // adds request assets to it, so read them at call time.
847 const storedStartContext = getStartContext({ throwIfNotFound: false })
848 attachRouterServerSsrUtils({
849 router: routerInstance,
850 manifest,
851 getRequestAssets: () => storedStartContext?.requestAssets,
852 })
853
854 // `additionalContext` is request-scoped and only read from router.options
855 // during load; avoid a full router.update() and redundant location parse.
856 routerInstance.options.additionalContext = { serverContext }
857 await routerInstance.load({
858 _signal: signal,
859 _skipLocationUpdate: true,
860 })
861 signal.throwIfAborted()
862
863 if (routerInstance._serverResult?.type === 'redirect') {
864 return normalizeSsrResponse(routerInstance._serverResult.redirect)
865 }
866
867 earlyHints?.collectDynamic(
868 _getRenderedMatches(routerInstance.stores.matches.get()),
869 )
870
871 // Pass request-scoped assets to dehydrate for manifest injection

Callers 1

terminalHandlerFunction · 0.85

Calls 9

isPromiseFunction · 0.90
getStartContextFunction · 0.90
_getRenderedMatchesFunction · 0.90
normalizeSsrResponseFunction · 0.85
getStartResponseHeadersFunction · 0.85
getMethod · 0.65
jsonMethod · 0.65
loadMethod · 0.65

Tested by

no test coverage detected