@tanstack/solid-router
Version:
Modern and scalable routing for Solid applications
39 lines (38 loc) • 2.22 kB
text/typescript
import { AnyRouter } from '@tanstack/router-core';
/**
* Registers the router as the unnamed single-flight consumer of Solid's
* server-function transport, so the response helpers a mutation returns —
* `redirect()`, `reload()`, `respond(value, { revalidate })` — take effect
* on the client without the caller wrapping the call: the transport hands
* the caller the plain value and the router applies the metadata. Called
* by `RouterContextProvider` on the client; returns the unsubscribe.
*
* Subscribing is also the single-flight opt-in: while registered, the
* transport tags mutation calls so the server can fold fresh data for
* registered collectors into the same response. The router claims no
* slice of that data itself — route data is reloaded through `invalidate`
* below, and caches that want seeding (a query client) subscribe under
* their own source id.
*/
export declare function setupFlightDataConsumer(router: AnyRouter): () => void;
/**
* Applies a server-function response's integration metadata to the
* router. A mutation is a write, so a response carrying metadata reloads
* the route data the page is built on: committed and cached matches are
* invalidated the way `router.invalidate()` does after a mutation.
*
* `X-Revalidate` names entries in caches the router does not own, so the
* keys themselves are left to those caches' consumers; the router reads
* only the declaration's shape. Absent (a bare `redirect()`/`reload()`),
* named keys, or the reserved `*` all say a write happened — route data
* reloads. An EMPTY declaration (`revalidate: []`) is the author narrowing
* the scope to nothing, and the router honors that too: a redirect still
* navigates, but nothing is reloaded on the way.
*
* The redirect carrier delivers the target RESOLVED to an absolute url, so
* the soft/hard split is a real origin comparison: a same-origin target
* navigates under the router (`replace`, matching what HTTP gives a form
* post — the destination takes the submission's place in history), and any
* other origin leaves the app through a document navigation.
*/
export declare function applyResponseMetadata(router: AnyRouter, response: Response): void;