Server integration
Import
import { createFlightDataCollector, type FlightDataCollectorOptions,} from "@solidjs/router/server";Keep this server-only entry out of client bundles. The server entry imports the request-event storage integration.
createFlightDataCollector
Creates the collectFlightData hook for the Solid server-function handler.
function createFlightDataCollector( options: FlightDataCollectorOptions | RouterInstanceLike): CollectFlightDataHook;Pass a createRouter instance:
const collectFlightData = createFlightDataCollector(Router);Or pass an options object:
interface FlightDataCollectorOptions { routes: | RouteDefinition | readonly RouteDefinition[] | (() => RouteDefinition | readonly RouteDefinition[]); rootPreload?: RoutePreloadFunc; base?: string;}routes can be built lazily by a thunk.
rootPreload corresponds to the router config's preload.
base corresponds to the router config's base.
Register with server functions
import { configureServerFunctionsServer } from "@solidjs/web/server-functions/server";
configureServerFunctionsServer({ collectFlightData: createFlightDataCollector(Router),});The collector:
- Reads the target and revalidation keys from the server-function outcome.
- Resolves lazy route subtrees matched by the previous or target URL.
- Runs the root preload with
intent: "initial". - Runs target route preloads with
intent: "preload". - Returns collected keyed query values.
Returns undefined when the outcome has no target URL or no collected values.
The collector logs errors from lazy resolution or preload collection.
The errors do not replace the mutation outcome.
The server-function handler folds the returned data into the mutation response. A mounted client router consumes the data when single flight is enabled.
Types
The server entry re-exports:
type CollectFlightDataHook;type ServerFunctionOutcome;CollectFlightDataHook and ServerFunctionOutcome originate from @solidjs/web/server-functions/server.