File size: 5,103 Bytes
fea495a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import type { FetchServerResponseResult } from '../../client/components/router-reducer/fetch-server-response';
import type { FocusAndScrollRef, PrefetchKind } from '../../client/components/router-reducer/router-reducer-types';
import type { FlightRouterState, FlightSegmentPath } from '../../server/app-render/types';
import React from 'react';
export type ChildSegmentMap = Map<string, CacheNode>;
/**
 * Cache node used in app-router / layout-router.
 */
export type CacheNode = ReadyCacheNode | LazyCacheNode;
export type LoadingModuleData = [React.JSX.Element, React.ReactNode, React.ReactNode] | null;
/** viewport metadata node */
export type HeadData = React.ReactNode;
export type LazyCacheNode = {
    /**
     * When rsc is null, this is a lazily-initialized cache node.
     *
     * If the app attempts to render it, it triggers a lazy data fetch,
     * postpones the render, and schedules an update to a new tree.
     *
     * TODO: This mechanism should not be used when PPR is enabled, though it
     * currently is in some cases until we've implemented partial
     * segment fetching.
     */
    rsc: null;
    /**
     * A prefetched version of the segment data. See explanation in corresponding
     * field of ReadyCacheNode (below).
     *
     * Since LazyCacheNode mostly only exists in the non-PPR implementation, this
     * will usually be null, but it could have been cloned from a previous
     * CacheNode that was created by the PPR implementation. Eventually we want
     * to migrate everything away from LazyCacheNode entirely.
     */
    prefetchRsc: React.ReactNode;
    /**
     * A pending response for the lazy data fetch. If this is not present
     * during render, it is lazily created.
     */
    lazyData: Promise<FetchServerResponseResult> | null;
    prefetchHead: HeadData | null;
    head: HeadData;
    loading: LoadingModuleData | Promise<LoadingModuleData>;
    /**
     * Child parallel routes.
     */
    parallelRoutes: Map<string, ChildSegmentMap>;
    /**
     * The timestamp of the navigation that last updated the CacheNode's data. If
     * a CacheNode is reused from a previous navigation, this value is not
     * updated. Used to track the staleness of the data.
     */
    navigatedAt: number;
};
export type ReadyCacheNode = {
    /**
     * When rsc is not null, it represents the RSC data for the
     * corresponding segment.
     *
     * `null` is a valid React Node but because segment data is always a
     * <LayoutRouter> component, we can use `null` to represent empty.
     *
     * TODO: For additional type safety, update this type to
     * Exclude<React.ReactNode, null>. Need to update createEmptyCacheNode to
     * accept rsc as an argument, or just inline the callers.
     */
    rsc: React.ReactNode;
    /**
     * Represents a static version of the segment that can be shown immediately,
     * and may or may not contain dynamic holes. It's prefetched before a
     * navigation occurs.
     *
     * During rendering, we will choose whether to render `rsc` or `prefetchRsc`
     * with `useDeferredValue`. As with the `rsc` field, a value of `null` means
     * no value was provided. In this case, the LayoutRouter will go straight to
     * rendering the `rsc` value; if that one is also missing, it will suspend and
     * trigger a lazy fetch.
     */
    prefetchRsc: React.ReactNode;
    /**
     * There should never be a lazy data request in this case.
     */
    lazyData: null;
    prefetchHead: HeadData | null;
    head: HeadData;
    loading: LoadingModuleData | Promise<LoadingModuleData>;
    parallelRoutes: Map<string, ChildSegmentMap>;
    navigatedAt: number;
};
export interface NavigateOptions {
    scroll?: boolean;
}
export interface PrefetchOptions {
    kind: PrefetchKind;
    onInvalidate?: () => void;
}
export interface AppRouterInstance {
    /**
     * Navigate to the previous history entry.
     */
    back(): void;
    /**
     * Navigate to the next history entry.
     */
    forward(): void;
    /**
     * Refresh the current page.
     */
    refresh(): void;
    /**
     * Navigate to the provided href.
     * Pushes a new history entry.
     */
    push(href: string, options?: NavigateOptions): void;
    /**
     * Navigate to the provided href.
     * Replaces the current history entry.
     */
    replace(href: string, options?: NavigateOptions): void;
    /**
     * Prefetch the provided href.
     */
    prefetch(href: string, options?: PrefetchOptions): void;
}
export declare const AppRouterContext: React.Context<AppRouterInstance | null>;
export declare const LayoutRouterContext: React.Context<{
    parentTree: FlightRouterState;
    parentCacheNode: CacheNode;
    parentSegmentPath: FlightSegmentPath | null;
    url: string;
} | null>;
export declare const GlobalLayoutRouterContext: React.Context<{
    tree: FlightRouterState;
    focusAndScrollRef: FocusAndScrollRef;
    nextUrl: string | null;
}>;
export declare const TemplateContext: React.Context<React.ReactNode>;
export declare const MissingSlotContext: React.Context<Set<string>>;