-
Notifications
You must be signed in to change notification settings - Fork 26k
/
app-router-context.ts
44 lines (39 loc) · 1.27 KB
/
app-router-context.ts
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
import React from 'react'
import type { FlightRouterState, FlightData } from '../../server/app-render'
export type ChildSegmentMap = Map<string, CacheNode>
type ParallelRoutesCacheNodes = Map<string, ChildSegmentMap>
export type CacheNode = {
data: ReturnType<
typeof import('../../client/components/app-router.client').fetchServerResponse
> | null
subTreeData: null | React.ReactNode
parallelRoutes: ParallelRoutesCacheNodes
}
export type AppRouterInstance = {
reload(): void
push(href: string): void
softPush(href: string): void
replace(href: string): void
softReplace(href: string): void
prefetch(href: string): Promise<void>
}
export const AppRouterContext = React.createContext<AppRouterInstance>(
null as any
)
export const AppTreeContext = React.createContext<{
childNodes: CacheNode['parallelRoutes']
tree: FlightRouterState
url: string
}>(null as any)
export const FullAppTreeContext = React.createContext<{
tree: FlightRouterState
changeByServerResponse: (
previousTree: FlightRouterState,
flightData: FlightData
) => void
}>(null as any)
if (process.env.NODE_ENV !== 'production') {
AppRouterContext.displayName = 'AppRouterContext'
AppTreeContext.displayName = 'AppTreeContext'
FullAppTreeContext.displayName = 'FullAppTreeContext'
}