73 lines
3.7 KiB
TypeScript
73 lines
3.7 KiB
TypeScript
import type { Params } from '../request/params';
|
|
import type { SearchParams } from '../request/search-params';
|
|
import type { VaryParamsThenable, VaryParams } from '../../shared/lib/segment-cache/vary-params-decoding';
|
|
/**
|
|
* Accumulates vary params for a single segment (or for metadata/rootParams).
|
|
*
|
|
* VaryParamsAccumulator is also a thenable that can be serialized by React
|
|
* Flight. The accumulator starts as 'pending' and accumulates param accesses
|
|
* during render. Call `finishTrackingVaryParams()` after rendering to resolve
|
|
* all accumulators.
|
|
*
|
|
* The `status` and `value` fields follow the React Flight thenable protocol:
|
|
* when `status === 'fulfilled'`, Flight can read `value` synchronously without
|
|
* scheduling a microtask via `.then()`.
|
|
*/
|
|
export type VaryParamsAccumulator = {
|
|
varyParams: VaryParams;
|
|
status: 'pending' | 'fulfilled';
|
|
value: VaryParams;
|
|
then(onfulfilled?: ((value: Set<string>) => unknown) | null, onrejected?: ((reason: unknown) => unknown) | null): void;
|
|
resolvers: Array<(value: Set<string>) => void>;
|
|
};
|
|
/**
|
|
* A mutable data structure for accumulating per-segment vary params for an
|
|
* entire server response. It's only used during prerenders. It describes
|
|
* metadata about the response itself.
|
|
*/
|
|
export type ResponseVaryParamsAccumulator = {
|
|
/** Vary params accumulator for metadata/viewport (the "head" segment) */
|
|
head: VaryParamsAccumulator;
|
|
/** Vary params accumulator for root params access */
|
|
rootParams: VaryParamsAccumulator;
|
|
/** Vary params accumulators for each route segment */
|
|
segments: Set<VaryParamsAccumulator>;
|
|
};
|
|
export declare const emptyVaryParamsAccumulator: VaryParamsAccumulator;
|
|
export declare function createResponseVaryParamsAccumulator(): ResponseVaryParamsAccumulator;
|
|
/**
|
|
* Allocates a new VaryParamsAccumulator and adds it to the response accumulator
|
|
* associated with the current WorkUnitStore.
|
|
*
|
|
* Returns a thenable that resolves to the segment's vary params once rendering
|
|
* is complete. The thenable can be passed directly to React Flight for
|
|
* serialization.
|
|
*/
|
|
export declare function createVaryParamsAccumulator(): VaryParamsAccumulator | null;
|
|
export declare function getMetadataVaryParamsAccumulator(): VaryParamsAccumulator | null;
|
|
export declare function getVaryParamsThenable(accumulator: VaryParamsAccumulator): VaryParamsThenable | null;
|
|
export declare function getMetadataVaryParamsThenable(): VaryParamsThenable | null;
|
|
export declare const getViewportVaryParamsAccumulator: typeof getMetadataVaryParamsAccumulator;
|
|
export declare function getRootParamsVaryParamsAccumulator(): VaryParamsAccumulator | null;
|
|
/**
|
|
* Records that a param was accessed. Adds the param name to the accumulator's
|
|
* varyParams set.
|
|
*/
|
|
export declare function accumulateVaryParam(accumulator: VaryParamsAccumulator, paramName: string): void;
|
|
/**
|
|
* Records a root param access.
|
|
*/
|
|
export declare function accumulateRootVaryParam(paramName: string): void;
|
|
export declare function createVaryingParams(accumulator: VaryParamsAccumulator, originalParamsObject: Params, optionalCatchAllParamName: string | null): Params;
|
|
export declare function createVaryingSearchParams(accumulator: VaryParamsAccumulator, originalSearchParamsObject: SearchParams): SearchParams;
|
|
/**
|
|
* Resolves all segment accumulators in a ResponseVaryParamsAccumulator with
|
|
* their final vary params. Call this after rendering is complete.
|
|
*
|
|
* Each segment's thenable is resolved with its vary params merged with the
|
|
* root params. If we can't track vary params (e.g., legacy prerender), simply
|
|
* don't call this function - the client treats unresolved thenables as
|
|
* "unknown" vary params.
|
|
*/
|
|
export declare function finishAccumulatingVaryParams(responseAccumulator: ResponseVaryParamsAccumulator): Promise<void>;
|