UNPKG

@tanstack/solid-router

Version:

Modern and scalable routing for Solid applications

52 lines (51 loc) 2.4 kB
import { ServerFunctionEvent, ServerFunctionOutcome } from '@solidjs/web/server-functions/server'; import { AnyRouter } from '@tanstack/router-core'; export interface LoadFlightTargetOptions<TRouter extends AnyRouter, T> { router: TRouter; /** The mutation's server-function event (the collector's first argument). */ event: ServerFunctionEvent; /** The pre-digested mutation outcome (the collector's second argument). */ outcome: ServerFunctionOutcome; /** * Overrides the target the router loads, for frameworks whose redirects * are serialized before the collector sees them (the pre-digested * `outcome.targetUrl` only understands raw `Location` headers). Defaults * to `outcome.targetUrl`. */ href?: string; /** * Runs inside the flight request-event scope once the target's route * data functions have settled — extract whatever the caller's cache * needs (dehydrate a query client, snapshot match state). Returning * undefined omits the slice from the response. */ collect: (router: TRouter) => T | Promise<T>; } /** * The router's half of single-flight collection: runs the matched routes' * data functions for the URL the client will show after a mutation, then * hands the loaded router to `collect`. This is the cache-agnostic * trigger — the router knows how to load route data for a target, and * deliberately not what that data was written into. Any cache builds a * flight-data hook from it by composing its own extraction: * * ```ts * registerFlightDataSource('sq', (event, outcome) => * loadFlightTarget({ * router: createAppRouter((queryClient = createQueryClient())), * event, * outcome, * collect: () => dehydrate(queryClient), * }), * ) * ``` * * The load observes post-mutation state: the flight event's request * targets `outcome.targetUrl` with the mutation's cookie effects already * folded in (a session the mutation just wrote or cleared is what the * data functions see, exactly as the browser's next request would), and * the router is pointed at the target through a fresh memory history. * Resolves undefined when there is no target (a non-browser caller, or a * redirect leaving the app). */ export declare function loadFlightTarget<TRouter extends AnyRouter, T>(options: LoadFlightTargetOptions<TRouter, T>): Promise<T | undefined>;