Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
b5b27206
Unverified
Commit
b5b27206
authored
Aug 20, 2025
by
Jiachi Liu
Committed by
GitHub
Aug 20, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[types] refactor shared types (#82844)
parent
5033dcb9
Hide whitespace changes
Inline
Side-by-side
Showing
68 changed files
with
442 additions
and
392 deletions
+442
-392
app-index.tsx
packages/next/src/client/app-index.tsx
+1
-1
app-router-announcer.tsx
packages/next/src/client/components/app-router-announcer.tsx
+1
-1
app-router-instance.ts
packages/next/src/client/components/app-router-instance.ts
+1
-1
app-router.tsx
packages/next/src/client/components/app-router.tsx
+4
-2
bfcache.ts
packages/next/src/client/components/bfcache.ts
+1
-1
layout-router.tsx
packages/next/src/client/components/layout-router.tsx
+3
-3
links.ts
packages/next/src/client/components/links.ts
+1
-1
match-segments.ts
packages/next/src/client/components/match-segments.ts
+1
-1
navigation.ts
packages/next/src/client/components/navigation.ts
+1
-1
aliased-prefetch-navigations.ts
...components/router-reducer/aliased-prefetch-navigations.ts
+2
-2
apply-flight-data.ts
...src/client/components/router-reducer/apply-flight-data.ts
+1
-1
apply-router-state-patch-to-tree.test.tsx
.../router-reducer/apply-router-state-patch-to-tree.test.tsx
+1
-1
apply-router-state-patch-to-tree.ts
...onents/router-reducer/apply-router-state-patch-to-tree.ts
+1
-1
clear-cache-node-data-for-segment-path.test.tsx
...r-reducer/clear-cache-node-data-for-segment-path.test.tsx
+1
-1
clear-cache-node-data-for-segment-path.ts
.../router-reducer/clear-cache-node-data-for-segment-path.ts
+4
-2
compute-changed-path.ts
.../client/components/router-reducer/compute-changed-path.ts
+1
-1
create-initial-router-state.test.tsx
...nents/router-reducer/create-initial-router-state.test.tsx
+4
-2
create-initial-router-state.ts
.../components/router-reducer/create-initial-router-state.ts
+4
-2
create-router-cache-key.ts
...ient/components/router-reducer/create-router-cache-key.ts
+1
-1
fetch-server-response.ts
...client/components/router-reducer/fetch-server-response.ts
+1
-1
fill-cache-with-new-subtree-data.test.tsx
.../router-reducer/fill-cache-with-new-subtree-data.test.tsx
+1
-1
fill-cache-with-new-subtree-data.ts
...onents/router-reducer/fill-cache-with-new-subtree-data.ts
+1
-2
fill-lazy-items-till-leaf-with-head.test.tsx
...uter-reducer/fill-lazy-items-till-leaf-with-head.test.tsx
+4
-2
fill-lazy-items-till-leaf-with-head.ts
...nts/router-reducer/fill-lazy-items-till-leaf-with-head.ts
+2
-2
handle-segment-mismatch.ts
...ient/components/router-reducer/handle-segment-mismatch.ts
+1
-1
invalidate-cache-below-flight-segmentpath.test.tsx
...educer/invalidate-cache-below-flight-segmentpath.test.tsx
+1
-1
invalidate-cache-below-flight-segmentpath.ts
...uter-reducer/invalidate-cache-below-flight-segmentpath.ts
+4
-2
invalidate-cache-by-router-state.test.tsx
.../router-reducer/invalidate-cache-by-router-state.test.tsx
+4
-2
invalidate-cache-by-router-state.ts
...onents/router-reducer/invalidate-cache-by-router-state.ts
+4
-2
is-navigating-to-new-root-layout.test.ts
...s/router-reducer/is-navigating-to-new-root-layout.test.ts
+1
-1
is-navigating-to-new-root-layout.ts
...onents/router-reducer/is-navigating-to-new-root-layout.ts
+1
-1
ppr-navigations.ts
...t/src/client/components/router-reducer/ppr-navigations.ts
+5
-3
find-head-in-cache.test.tsx
...nents/router-reducer/reducers/find-head-in-cache.test.tsx
+4
-2
find-head-in-cache.ts
.../components/router-reducer/reducers/find-head-in-cache.ts
+4
-2
get-segment-value.ts
...t/components/router-reducer/reducers/get-segment-value.ts
+1
-1
has-interception-route-in-current-tree.ts
...educer/reducers/has-interception-route-in-current-tree.ts
+1
-1
hmr-refresh-reducer.ts
...components/router-reducer/reducers/hmr-refresh-reducer.ts
+1
-1
navigate-reducer.ts
...nt/components/router-reducer/reducers/navigate-reducer.ts
+2
-2
refresh-reducer.ts
...ent/components/router-reducer/reducers/refresh-reducer.ts
+1
-1
server-action-reducer.ts
...mponents/router-reducer/reducers/server-action-reducer.ts
+2
-2
server-patch-reducer.ts
...omponents/router-reducer/reducers/server-patch-reducer.ts
+1
-1
refetch-inactive-parallel-segments.ts
...ents/router-reducer/refetch-inactive-parallel-segments.ts
+4
-2
router-reducer-types.ts
.../client/components/router-reducer/router-reducer-types.ts
+2
-2
should-hard-navigate.test.tsx
...t/components/router-reducer/should-hard-navigate.test.tsx
+1
-1
should-hard-navigate.ts
.../client/components/router-reducer/should-hard-navigate.ts
+1
-1
cache.ts
...es/next/src/client/components/segment-cache-impl/cache.ts
+4
-4
navigation.ts
...xt/src/client/components/segment-cache-impl/navigation.ts
+3
-3
prefetch.ts
...next/src/client/components/segment-cache-impl/prefetch.ts
+1
-1
scheduler.ts
...ext/src/client/components/segment-cache-impl/scheduler.ts
+2
-2
flight-data-helpers.test.ts
packages/next/src/client/flight-data-helpers.test.ts
+4
-2
flight-data-helpers.ts
packages/next/src/client/flight-data-helpers.ts
+2
-2
route-params.ts
packages/next/src/client/route-params.ts
+1
-1
app-render.tsx
packages/next/src/server/app-render/app-render.tsx
+2
-3
collect-segment-data.tsx
packages/next/src/server/app-render/collect-segment-data.tsx
+3
-5
create-component-tree.tsx
...ages/next/src/server/app-render/create-component-tree.tsx
+5
-2
create-flight-router-state-from-loader-tree.ts
...app-render/create-flight-router-state-from-loader-tree.ts
+4
-1
get-segment-param.tsx
packages/next/src/server/app-render/get-segment-param.tsx
+1
-1
get-short-dynamic-param-type.tsx
...xt/src/server/app-render/get-short-dynamic-param-type.tsx
+4
-1
parse-and-validate-flight-router-state.tsx
...ver/app-render/parse-and-validate-flight-router-state.tsx
+1
-1
types.ts
packages/next/src/server/app-render/types.ts
+0
-179
walk-tree-with-flight-router-state.tsx
.../server/app-render/walk-tree-with-flight-router-state.tsx
+3
-3
on-demand-entry-handler.ts
packages/next/src/server/dev/on-demand-entry-handler.ts
+1
-1
app-router-context.shared-runtime.ts
.../next/src/shared/lib/app-router-context.shared-runtime.ts
+2
-107
app-router-types.ts
packages/next/src/shared/lib/app-router-types.ts
+302
-0
get-dynamic-param.ts
...ges/next/src/shared/lib/router/utils/get-dynamic-param.ts
+1
-1
segment-value-encoding.ts
...xt/src/shared/lib/segment-cache/segment-value-encoding.ts
+1
-1
segment.ts
packages/next/src/shared/lib/segment.ts
+1
-1
cache-components-tests-manifest.json
test/cache-components-tests-manifest.json
+5
-4
No files found.
packages/next/src/client/app-index.tsx
View file @
b5b27206
...
@@ -17,7 +17,7 @@ import {
...
@@ -17,7 +17,7 @@ import {
createMutableActionQueue
,
createMutableActionQueue
,
}
from
'./components/app-router-instance'
}
from
'./components/app-router-instance'
import
AppRouter
from
'./components/app-router'
import
AppRouter
from
'./components/app-router'
import
type
{
InitialRSCPayload
}
from
'../s
erver/app-render/
types'
import
type
{
InitialRSCPayload
}
from
'../s
hared/lib/app-router-
types'
import
{
createInitialRouterState
}
from
'./components/router-reducer/create-initial-router-state'
import
{
createInitialRouterState
}
from
'./components/router-reducer/create-initial-router-state'
import
{
MissingSlotContext
}
from
'../shared/lib/app-router-context.shared-runtime'
import
{
MissingSlotContext
}
from
'../shared/lib/app-router-context.shared-runtime'
import
{
setAppBuildId
}
from
'./app-build-id'
import
{
setAppBuildId
}
from
'./app-build-id'
...
...
packages/next/src/client/components/app-router-announcer.tsx
View file @
b5b27206
import
{
useEffect
,
useRef
,
useState
}
from
'react'
import
{
useEffect
,
useRef
,
useState
}
from
'react'
import
{
createPortal
}
from
'react-dom'
import
{
createPortal
}
from
'react-dom'
import
type
{
FlightRouterState
}
from
'../../s
erver/app-render/
types'
import
type
{
FlightRouterState
}
from
'../../s
hared/lib/app-router-
types'
const
ANNOUNCER_TYPE
=
'next-route-announcer'
const
ANNOUNCER_TYPE
=
'next-route-announcer'
const
ANNOUNCER_ID
=
'__next-route-announcer__'
const
ANNOUNCER_ID
=
'__next-route-announcer__'
...
...
packages/next/src/client/components/app-router-instance.ts
View file @
b5b27206
...
@@ -29,7 +29,7 @@ import type {
...
@@ -29,7 +29,7 @@ import type {
PrefetchOptions
,
PrefetchOptions
,
}
from
'../../shared/lib/app-router-context.shared-runtime'
}
from
'../../shared/lib/app-router-context.shared-runtime'
import
{
setLinkForCurrentNavigation
,
type
LinkInstance
}
from
'./links'
import
{
setLinkForCurrentNavigation
,
type
LinkInstance
}
from
'./links'
import
type
{
FlightRouterState
}
from
'../../s
erver/app-render/
types'
import
type
{
FlightRouterState
}
from
'../../s
hared/lib/app-router-
types'
import
type
{
ClientInstrumentationHooks
}
from
'../app-index'
import
type
{
ClientInstrumentationHooks
}
from
'../app-index'
import
type
{
GlobalErrorComponent
}
from
'./builtin/global-error'
import
type
{
GlobalErrorComponent
}
from
'./builtin/global-error'
...
...
packages/next/src/client/components/app-router.tsx
View file @
b5b27206
...
@@ -12,7 +12,10 @@ import {
...
@@ -12,7 +12,10 @@ import {
LayoutRouterContext
,
LayoutRouterContext
,
GlobalLayoutRouterContext
,
GlobalLayoutRouterContext
,
}
from
'../../shared/lib/app-router-context.shared-runtime'
}
from
'../../shared/lib/app-router-context.shared-runtime'
import
type
{
CacheNode
}
from
'../../shared/lib/app-router-context.shared-runtime'
import
type
{
CacheNode
,
FlightRouterState
,
}
from
'../../shared/lib/app-router-types'
import
{
ACTION_RESTORE
}
from
'./router-reducer/router-reducer-types'
import
{
ACTION_RESTORE
}
from
'./router-reducer/router-reducer-types'
import
type
{
AppRouterState
}
from
'./router-reducer/router-reducer-types'
import
type
{
AppRouterState
}
from
'./router-reducer/router-reducer-types'
import
{
createHrefFromUrl
}
from
'./router-reducer/create-href-from-url'
import
{
createHrefFromUrl
}
from
'./router-reducer/create-href-from-url'
...
@@ -31,7 +34,6 @@ import { unresolvedThenable } from './unresolved-thenable'
...
@@ -31,7 +34,6 @@ import { unresolvedThenable } from './unresolved-thenable'
import
{
removeBasePath
}
from
'../remove-base-path'
import
{
removeBasePath
}
from
'../remove-base-path'
import
{
hasBasePath
}
from
'../has-base-path'
import
{
hasBasePath
}
from
'../has-base-path'
import
{
getSelectedParams
}
from
'./router-reducer/compute-changed-path'
import
{
getSelectedParams
}
from
'./router-reducer/compute-changed-path'
import
type
{
FlightRouterState
}
from
'../../server/app-render/types'
import
{
useNavFailureHandler
}
from
'./nav-failure-handler'
import
{
useNavFailureHandler
}
from
'./nav-failure-handler'
import
{
import
{
dispatchTraverseAction
,
dispatchTraverseAction
,
...
...
packages/next/src/client/components/bfcache.ts
View file @
b5b27206
import
type
{
FlightRouterState
}
from
'../../s
erver/app-render/
types'
import
type
{
FlightRouterState
}
from
'../../s
hared/lib/app-router-
types'
import
{
useState
}
from
'react'
import
{
useState
}
from
'react'
// When the flag is disabled, only track the currently active tree
// When the flag is disabled, only track the currently active tree
...
...
packages/next/src/client/components/layout-router.tsx
View file @
b5b27206
...
@@ -3,12 +3,12 @@
...
@@ -3,12 +3,12 @@
import
type
{
import
type
{
CacheNode
,
CacheNode
,
LazyCacheNode
,
LazyCacheNode
,
LoadingModuleData
,
}
from
'../../shared/lib/app-router-types'
}
from
'../../shared/lib/app-router-context.shared-runtime
'
import
type
{
LoadingModuleData
}
from
'../../shared/lib/app-router-types
'
import
type
{
import
type
{
FlightRouterState
,
FlightRouterState
,
FlightSegmentPath
,
FlightSegmentPath
,
}
from
'../../s
erver/app-render/
types'
}
from
'../../s
hared/lib/app-router-
types'
import
type
{
ErrorComponent
}
from
'./error-boundary'
import
type
{
ErrorComponent
}
from
'./error-boundary'
import
{
import
{
ACTION_SERVER_PATCH
,
ACTION_SERVER_PATCH
,
...
...
packages/next/src/client/components/links.ts
View file @
b5b27206
import
type
{
FlightRouterState
}
from
'../../s
erver/app-render/
types'
import
type
{
FlightRouterState
}
from
'../../s
hared/lib/app-router-
types'
import
type
{
AppRouterInstance
}
from
'../../shared/lib/app-router-context.shared-runtime'
import
type
{
AppRouterInstance
}
from
'../../shared/lib/app-router-context.shared-runtime'
import
{
getCurrentAppRouterState
}
from
'./app-router-instance'
import
{
getCurrentAppRouterState
}
from
'./app-router-instance'
import
{
createPrefetchURL
}
from
'./app-router'
import
{
createPrefetchURL
}
from
'./app-router'
...
...
packages/next/src/client/components/match-segments.ts
View file @
b5b27206
import
type
{
Segment
}
from
'../../s
erver/app-render/
types'
import
type
{
Segment
}
from
'../../s
hared/lib/app-router-
types'
export
const
matchSegment
=
(
export
const
matchSegment
=
(
existingSegment
:
Segment
,
existingSegment
:
Segment
,
...
...
packages/next/src/client/components/navigation.ts
View file @
b5b27206
import
type
{
FlightRouterState
}
from
'../../s
erver/app-render/
types'
import
type
{
FlightRouterState
}
from
'../../s
hared/lib/app-router-
types'
import
type
{
Params
}
from
'../../server/request/params'
import
type
{
Params
}
from
'../../server/request/params'
import
{
useContext
,
useMemo
}
from
'react'
import
{
useContext
,
useMemo
}
from
'react'
...
...
packages/next/src/client/components/router-reducer/aliased-prefetch-navigations.ts
View file @
b5b27206
import
type
{
import
type
{
CacheNodeSeedData
,
CacheNodeSeedData
,
FlightRouterState
,
FlightRouterState
,
}
from
'../../../s
erver/app-render/
types'
}
from
'../../../s
hared/lib/app-router-
types'
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-
context.shared-runtime
'
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-
types
'
import
{
import
{
addSearchParamsIfPageSegment
,
addSearchParamsIfPageSegment
,
PAGE_SEGMENT_KEY
,
PAGE_SEGMENT_KEY
,
...
...
packages/next/src/client/components/router-reducer/apply-flight-data.ts
View file @
b5b27206
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-
context.shared-runtime
'
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-
types
'
import
{
fillLazyItemsTillLeafWithHead
}
from
'./fill-lazy-items-till-leaf-with-head'
import
{
fillLazyItemsTillLeafWithHead
}
from
'./fill-lazy-items-till-leaf-with-head'
import
{
fillCacheWithNewSubTreeData
}
from
'./fill-cache-with-new-subtree-data'
import
{
fillCacheWithNewSubTreeData
}
from
'./fill-cache-with-new-subtree-data'
import
type
{
PrefetchCacheEntry
}
from
'./router-reducer-types'
import
type
{
PrefetchCacheEntry
}
from
'./router-reducer-types'
...
...
packages/next/src/client/components/router-reducer/apply-router-state-patch-to-tree.test.tsx
View file @
b5b27206
...
@@ -2,7 +2,7 @@ import React from 'react'
...
@@ -2,7 +2,7 @@ import React from 'react'
import
type
{
import
type
{
FlightData
,
FlightData
,
FlightRouterState
,
FlightRouterState
,
}
from
'../../../s
erver/app-render/
types'
}
from
'../../../s
hared/lib/app-router-
types'
import
{
applyRouterStatePatchToTree
}
from
'./apply-router-state-patch-to-tree'
import
{
applyRouterStatePatchToTree
}
from
'./apply-router-state-patch-to-tree'
const
getInitialRouterStateTree
=
():
FlightRouterState
=>
[
const
getInitialRouterStateTree
=
():
FlightRouterState
=>
[
...
...
packages/next/src/client/components/router-reducer/apply-router-state-patch-to-tree.ts
View file @
b5b27206
import
type
{
import
type
{
FlightRouterState
,
FlightRouterState
,
FlightSegmentPath
,
FlightSegmentPath
,
}
from
'../../../s
erver/app-render/
types'
}
from
'../../../s
hared/lib/app-router-
types'
import
{
DEFAULT_SEGMENT_KEY
}
from
'../../../shared/lib/segment'
import
{
DEFAULT_SEGMENT_KEY
}
from
'../../../shared/lib/segment'
import
{
getNextFlightSegmentPath
}
from
'../../flight-data-helpers'
import
{
getNextFlightSegmentPath
}
from
'../../flight-data-helpers'
import
{
matchSegment
}
from
'../match-segments'
import
{
matchSegment
}
from
'../match-segments'
...
...
packages/next/src/client/components/router-reducer/clear-cache-node-data-for-segment-path.test.tsx
View file @
b5b27206
import
React
from
'react'
import
React
from
'react'
import
{
clearCacheNodeDataForSegmentPath
}
from
'./clear-cache-node-data-for-segment-path'
import
{
clearCacheNodeDataForSegmentPath
}
from
'./clear-cache-node-data-for-segment-path'
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-
context.shared-runtime
'
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-
types
'
const
navigatedAt
=
-
1
const
navigatedAt
=
-
1
...
...
packages/next/src/client/components/router-reducer/clear-cache-node-data-for-segment-path.ts
View file @
b5b27206
import
type
{
FlightSegmentPath
}
from
'../../../server/app-render/types'
import
type
{
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-context.shared-runtime'
FlightSegmentPath
,
CacheNode
,
}
from
'../../../shared/lib/app-router-types'
import
{
getNextFlightSegmentPath
}
from
'../../flight-data-helpers'
import
{
getNextFlightSegmentPath
}
from
'../../flight-data-helpers'
import
{
createRouterCacheKey
}
from
'./create-router-cache-key'
import
{
createRouterCacheKey
}
from
'./create-router-cache-key'
...
...
packages/next/src/client/components/router-reducer/compute-changed-path.ts
View file @
b5b27206
import
type
{
import
type
{
FlightRouterState
,
FlightRouterState
,
Segment
,
Segment
,
}
from
'../../../s
erver/app-render/
types'
}
from
'../../../s
hared/lib/app-router-
types'
import
{
INTERCEPTION_ROUTE_MARKERS
}
from
'../../../shared/lib/router/utils/interception-routes'
import
{
INTERCEPTION_ROUTE_MARKERS
}
from
'../../../shared/lib/router/utils/interception-routes'
import
type
{
Params
}
from
'../../../server/request/params'
import
type
{
Params
}
from
'../../../server/request/params'
import
{
import
{
...
...
packages/next/src/client/components/router-reducer/create-initial-router-state.test.tsx
View file @
b5b27206
import
React
from
'react'
import
React
from
'react'
import
type
{
FlightRouterState
}
from
'../../../server/app-render/types'
import
type
{
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-context.shared-runtime'
FlightRouterState
,
CacheNode
,
}
from
'../../../shared/lib/app-router-types'
import
{
createInitialRouterState
}
from
'./create-initial-router-state'
import
{
createInitialRouterState
}
from
'./create-initial-router-state'
import
{
PrefetchCacheEntryStatus
,
PrefetchKind
}
from
'./router-reducer-types'
import
{
PrefetchCacheEntryStatus
,
PrefetchKind
}
from
'./router-reducer-types'
...
...
packages/next/src/client/components/router-reducer/create-initial-router-state.ts
View file @
b5b27206
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-context.shared-runtime'
import
type
{
import
type
{
FlightDataPath
}
from
'../../../server/app-render/types'
CacheNode
,
FlightDataPath
,
}
from
'../../../shared/lib/app-router-types'
import
{
createHrefFromUrl
}
from
'./create-href-from-url'
import
{
createHrefFromUrl
}
from
'./create-href-from-url'
import
{
fillLazyItemsTillLeafWithHead
}
from
'./fill-lazy-items-till-leaf-with-head'
import
{
fillLazyItemsTillLeafWithHead
}
from
'./fill-lazy-items-till-leaf-with-head'
...
...
packages/next/src/client/components/router-reducer/create-router-cache-key.ts
View file @
b5b27206
import
type
{
Segment
}
from
'../../../s
erver/app-render/
types'
import
type
{
Segment
}
from
'../../../s
hared/lib/app-router-
types'
import
{
PAGE_SEGMENT_KEY
}
from
'../../../shared/lib/segment'
import
{
PAGE_SEGMENT_KEY
}
from
'../../../shared/lib/segment'
export
function
createRouterCacheKey
(
export
function
createRouterCacheKey
(
...
...
packages/next/src/client/components/router-reducer/fetch-server-response.ts
View file @
b5b27206
...
@@ -7,7 +7,7 @@ import { createFromReadableStream as createFromReadableStreamBrowser } from 'rea
...
@@ -7,7 +7,7 @@ import { createFromReadableStream as createFromReadableStreamBrowser } from 'rea
import
type
{
import
type
{
FlightRouterState
,
FlightRouterState
,
NavigationFlightResponse
,
NavigationFlightResponse
,
}
from
'../../../s
erver/app-render/
types'
}
from
'../../../s
hared/lib/app-router-
types'
import
type
{
NEXT_ROUTER_SEGMENT_PREFETCH_HEADER
}
from
'../app-router-headers'
import
type
{
NEXT_ROUTER_SEGMENT_PREFETCH_HEADER
}
from
'../app-router-headers'
import
{
import
{
...
...
packages/next/src/client/components/router-reducer/fill-cache-with-new-subtree-data.test.tsx
View file @
b5b27206
import
{
fillCacheWithNewSubTreeData
}
from
'./fill-cache-with-new-subtree-data'
import
{
fillCacheWithNewSubTreeData
}
from
'./fill-cache-with-new-subtree-data'
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-
context.shared-runtime
'
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-
types
'
import
type
{
NormalizedFlightData
}
from
'../../flight-data-helpers'
import
type
{
NormalizedFlightData
}
from
'../../flight-data-helpers'
const
getFlightData
=
():
NormalizedFlightData
[]
=>
{
const
getFlightData
=
():
NormalizedFlightData
[]
=>
{
...
...
packages/next/src/client/components/router-reducer/fill-cache-with-new-subtree-data.ts
View file @
b5b27206
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-context.shared-runtime'
import
type
{
CacheNode
,
Segment
}
from
'../../../shared/lib/app-router-types'
import
type
{
Segment
}
from
'../../../server/app-render/types'
import
{
invalidateCacheByRouterState
}
from
'./invalidate-cache-by-router-state'
import
{
invalidateCacheByRouterState
}
from
'./invalidate-cache-by-router-state'
import
{
fillLazyItemsTillLeafWithHead
}
from
'./fill-lazy-items-till-leaf-with-head'
import
{
fillLazyItemsTillLeafWithHead
}
from
'./fill-lazy-items-till-leaf-with-head'
import
{
createRouterCacheKey
}
from
'./create-router-cache-key'
import
{
createRouterCacheKey
}
from
'./create-router-cache-key'
...
...
packages/next/src/client/components/router-reducer/fill-lazy-items-till-leaf-with-head.test.tsx
View file @
b5b27206
import
React
from
'react'
import
React
from
'react'
import
{
fillLazyItemsTillLeafWithHead
}
from
'./fill-lazy-items-till-leaf-with-head'
import
{
fillLazyItemsTillLeafWithHead
}
from
'./fill-lazy-items-till-leaf-with-head'
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-context.shared-runtime'
import
type
{
import
type
{
FlightData
}
from
'../../../server/app-render/types'
CacheNode
,
FlightData
,
}
from
'../../../shared/lib/app-router-types'
const
getFlightData
=
():
FlightData
=>
{
const
getFlightData
=
():
FlightData
=>
{
return
[
return
[
...
...
packages/next/src/client/components/router-reducer/fill-lazy-items-till-leaf-with-head.ts
View file @
b5b27206
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-
context.shared-runtime
'
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-
types
'
import
type
{
import
type
{
FlightRouterState
,
FlightRouterState
,
CacheNodeSeedData
,
CacheNodeSeedData
,
}
from
'../../../s
erver/app-render/
types'
}
from
'../../../s
hared/lib/app-router-
types'
import
{
createRouterCacheKey
}
from
'./create-router-cache-key'
import
{
createRouterCacheKey
}
from
'./create-router-cache-key'
import
{
import
{
PrefetchCacheEntryStatus
,
PrefetchCacheEntryStatus
,
...
...
packages/next/src/client/components/router-reducer/handle-segment-mismatch.ts
View file @
b5b27206
import
type
{
FlightRouterState
}
from
'../../../s
erver/app-render/
types'
import
type
{
FlightRouterState
}
from
'../../../s
hared/lib/app-router-
types'
import
{
handleExternalUrl
}
from
'./reducers/navigate-reducer'
import
{
handleExternalUrl
}
from
'./reducers/navigate-reducer'
import
type
{
import
type
{
ReadonlyReducerState
,
ReadonlyReducerState
,
...
...
packages/next/src/client/components/router-reducer/invalidate-cache-below-flight-segmentpath.test.tsx
View file @
b5b27206
import
React
from
'react'
import
React
from
'react'
import
{
invalidateCacheBelowFlightSegmentPath
}
from
'./invalidate-cache-below-flight-segmentpath'
import
{
invalidateCacheBelowFlightSegmentPath
}
from
'./invalidate-cache-below-flight-segmentpath'
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-
context.shared-runtime
'
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-
types
'
import
{
fillCacheWithNewSubTreeData
}
from
'./fill-cache-with-new-subtree-data'
import
{
fillCacheWithNewSubTreeData
}
from
'./fill-cache-with-new-subtree-data'
import
type
{
NormalizedFlightData
}
from
'../../flight-data-helpers'
import
type
{
NormalizedFlightData
}
from
'../../flight-data-helpers'
...
...
packages/next/src/client/components/router-reducer/invalidate-cache-below-flight-segmentpath.ts
View file @
b5b27206
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-context.shared-runtime'
import
type
{
import
type
{
FlightSegmentPath
}
from
'../../../server/app-render/types'
CacheNode
,
FlightSegmentPath
,
}
from
'../../../shared/lib/app-router-types'
import
{
createRouterCacheKey
}
from
'./create-router-cache-key'
import
{
createRouterCacheKey
}
from
'./create-router-cache-key'
import
{
getNextFlightSegmentPath
}
from
'../../flight-data-helpers'
import
{
getNextFlightSegmentPath
}
from
'../../flight-data-helpers'
...
...
packages/next/src/client/components/router-reducer/invalidate-cache-by-router-state.test.tsx
View file @
b5b27206
import
{
invalidateCacheByRouterState
}
from
'./invalidate-cache-by-router-state'
import
{
invalidateCacheByRouterState
}
from
'./invalidate-cache-by-router-state'
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-context.shared-runtime'
import
type
{
import
type
{
FlightRouterState
}
from
'../../../server/app-render/types'
CacheNode
,
FlightRouterState
,
}
from
'../../../shared/lib/app-router-types'
const
navigatedAt
=
-
1
const
navigatedAt
=
-
1
...
...
packages/next/src/client/components/router-reducer/invalidate-cache-by-router-state.ts
View file @
b5b27206
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-context.shared-runtime'
import
type
{
import
type
{
FlightRouterState
}
from
'../../../server/app-render/types'
CacheNode
,
FlightRouterState
,
}
from
'../../../shared/lib/app-router-types'
import
{
createRouterCacheKey
}
from
'./create-router-cache-key'
import
{
createRouterCacheKey
}
from
'./create-router-cache-key'
/**
/**
...
...
packages/next/src/client/components/router-reducer/is-navigating-to-new-root-layout.test.ts
View file @
b5b27206
import
type
{
FlightRouterState
}
from
'../../../s
erver/app-render/
types'
import
type
{
FlightRouterState
}
from
'../../../s
hared/lib/app-router-
types'
import
{
isNavigatingToNewRootLayout
}
from
'./is-navigating-to-new-root-layout'
import
{
isNavigatingToNewRootLayout
}
from
'./is-navigating-to-new-root-layout'
describe
(
'isNavigatingToNewRootLayout'
,
()
=>
{
describe
(
'isNavigatingToNewRootLayout'
,
()
=>
{
...
...
packages/next/src/client/components/router-reducer/is-navigating-to-new-root-layout.ts
View file @
b5b27206
import
type
{
FlightRouterState
}
from
'../../../s
erver/app-render/
types'
import
type
{
FlightRouterState
}
from
'../../../s
hared/lib/app-router-
types'
export
function
isNavigatingToNewRootLayout
(
export
function
isNavigatingToNewRootLayout
(
currentTree
:
FlightRouterState
,
currentTree
:
FlightRouterState
,
...
...
packages/next/src/client/components/router-reducer/ppr-navigations.ts
View file @
b5b27206
...
@@ -3,14 +3,16 @@ import type {
...
@@ -3,14 +3,16 @@ import type {
FlightRouterState
,
FlightRouterState
,
FlightSegmentPath
,
FlightSegmentPath
,
Segment
,
Segment
,
}
from
'../../../s
erver/app-render/
types'
}
from
'../../../s
hared/lib/app-router-
types'
import
type
{
import
type
{
CacheNode
,
CacheNode
,
ChildSegmentMap
,
ChildSegmentMap
,
ReadyCacheNode
,
}
from
'../../../shared/lib/app-router-types'
import
type
{
HeadData
,
HeadData
,
LoadingModuleData
,
LoadingModuleData
,
ReadyCacheNode
,
}
from
'../../../shared/lib/app-router-types'
}
from
'../../../shared/lib/app-router-context.shared-runtime'
import
{
DEFAULT_SEGMENT_KEY
}
from
'../../../shared/lib/segment'
import
{
DEFAULT_SEGMENT_KEY
}
from
'../../../shared/lib/segment'
import
{
matchSegment
}
from
'../match-segments'
import
{
matchSegment
}
from
'../match-segments'
import
{
createRouterCacheKey
}
from
'./create-router-cache-key'
import
{
createRouterCacheKey
}
from
'./create-router-cache-key'
...
...
packages/next/src/client/components/router-reducer/reducers/find-head-in-cache.test.tsx
View file @
b5b27206
import
type
{
FlightRouterState
}
from
'../../../../server/app-render/types'
import
type
{
import
type
{
CacheNode
}
from
'../../../../shared/lib/app-router-context.shared-runtime'
FlightRouterState
,
CacheNode
,
}
from
'../../../../shared/lib/app-router-types'
import
{
findHeadInCache
}
from
'./find-head-in-cache'
import
{
findHeadInCache
}
from
'./find-head-in-cache'
const
navigatedAt
=
-
1
const
navigatedAt
=
-
1
...
...
packages/next/src/client/components/router-reducer/reducers/find-head-in-cache.ts
View file @
b5b27206
import
type
{
FlightRouterState
}
from
'../../../../server/app-render/types'
import
type
{
import
type
{
CacheNode
}
from
'../../../../shared/lib/app-router-context.shared-runtime'
FlightRouterState
,
CacheNode
,
}
from
'../../../../shared/lib/app-router-types'
import
{
DEFAULT_SEGMENT_KEY
}
from
'../../../../shared/lib/segment'
import
{
DEFAULT_SEGMENT_KEY
}
from
'../../../../shared/lib/segment'
import
{
createRouterCacheKey
}
from
'../create-router-cache-key'
import
{
createRouterCacheKey
}
from
'../create-router-cache-key'
...
...
packages/next/src/client/components/router-reducer/reducers/get-segment-value.ts
View file @
b5b27206
import
type
{
Segment
}
from
'../../../../s
erver/app-render/
types'
import
type
{
Segment
}
from
'../../../../s
hared/lib/app-router-
types'
export
function
getSegmentValue
(
segment
:
Segment
)
{
export
function
getSegmentValue
(
segment
:
Segment
)
{
return
Array
.
isArray
(
segment
)
?
segment
[
1
]
:
segment
return
Array
.
isArray
(
segment
)
?
segment
[
1
]
:
segment
...
...
packages/next/src/client/components/router-reducer/reducers/has-interception-route-in-current-tree.ts
View file @
b5b27206
import
type
{
FlightRouterState
}
from
'../../../../s
erver/app-render/
types'
import
type
{
FlightRouterState
}
from
'../../../../s
hared/lib/app-router-
types'
import
{
isInterceptionRouteAppPath
}
from
'../../../../shared/lib/router/utils/interception-routes'
import
{
isInterceptionRouteAppPath
}
from
'../../../../shared/lib/router/utils/interception-routes'
export
function
hasInterceptionRouteInCurrentTree
([
export
function
hasInterceptionRouteInCurrentTree
([
...
...
packages/next/src/client/components/router-reducer/reducers/hmr-refresh-reducer.ts
View file @
b5b27206
...
@@ -11,7 +11,7 @@ import type {
...
@@ -11,7 +11,7 @@ import type {
import
{
handleExternalUrl
}
from
'./navigate-reducer'
import
{
handleExternalUrl
}
from
'./navigate-reducer'
import
{
handleMutable
}
from
'../handle-mutable'
import
{
handleMutable
}
from
'../handle-mutable'
import
{
applyFlightData
}
from
'../apply-flight-data'
import
{
applyFlightData
}
from
'../apply-flight-data'
import
type
{
CacheNode
}
from
'../../../../shared/lib/app-router-
context.shared-runtime
'
import
type
{
CacheNode
}
from
'../../../../shared/lib/app-router-
types
'
import
{
createEmptyCacheNode
}
from
'../../app-router'
import
{
createEmptyCacheNode
}
from
'../../app-router'
import
{
handleSegmentMismatch
}
from
'../handle-segment-mismatch'
import
{
handleSegmentMismatch
}
from
'../handle-segment-mismatch'
import
{
hasInterceptionRouteInCurrentTree
}
from
'./has-interception-route-in-current-tree'
import
{
hasInterceptionRouteInCurrentTree
}
from
'./has-interception-route-in-current-tree'
...
...
packages/next/src/client/components/router-reducer/reducers/navigate-reducer.ts
View file @
b5b27206
import
type
{
CacheNode
}
from
'../../../../shared/lib/app-router-
context.shared-runtime
'
import
type
{
CacheNode
}
from
'../../../../shared/lib/app-router-
types
'
import
type
{
import
type
{
FlightRouterState
,
FlightRouterState
,
FlightSegmentPath
,
FlightSegmentPath
,
}
from
'../../../../s
erver/app-render/
types'
}
from
'../../../../s
hared/lib/app-router-
types'
import
{
fetchServerResponse
}
from
'../fetch-server-response'
import
{
fetchServerResponse
}
from
'../fetch-server-response'
import
{
createHrefFromUrl
}
from
'../create-href-from-url'
import
{
createHrefFromUrl
}
from
'../create-href-from-url'
import
{
invalidateCacheBelowFlightSegmentPath
}
from
'../invalidate-cache-below-flight-segmentpath'
import
{
invalidateCacheBelowFlightSegmentPath
}
from
'../invalidate-cache-below-flight-segmentpath'
...
...
packages/next/src/client/components/router-reducer/reducers/refresh-reducer.ts
View file @
b5b27206
...
@@ -10,7 +10,7 @@ import type {
...
@@ -10,7 +10,7 @@ import type {
}
from
'../router-reducer-types'
}
from
'../router-reducer-types'
import
{
handleExternalUrl
}
from
'./navigate-reducer'
import
{
handleExternalUrl
}
from
'./navigate-reducer'
import
{
handleMutable
}
from
'../handle-mutable'
import
{
handleMutable
}
from
'../handle-mutable'
import
type
{
CacheNode
}
from
'../../../../shared/lib/app-router-
context.shared-runtime
'
import
type
{
CacheNode
}
from
'../../../../shared/lib/app-router-
types
'
import
{
fillLazyItemsTillLeafWithHead
}
from
'../fill-lazy-items-till-leaf-with-head'
import
{
fillLazyItemsTillLeafWithHead
}
from
'../fill-lazy-items-till-leaf-with-head'
import
{
createEmptyCacheNode
}
from
'../../app-router'
import
{
createEmptyCacheNode
}
from
'../../app-router'
import
{
handleSegmentMismatch
}
from
'../handle-segment-mismatch'
import
{
handleSegmentMismatch
}
from
'../handle-segment-mismatch'
...
...
packages/next/src/client/components/router-reducer/reducers/server-action-reducer.ts
View file @
b5b27206
import
type
{
import
type
{
ActionFlightResponse
,
ActionFlightResponse
,
ActionResult
,
ActionResult
,
}
from
'../../../../s
erver/app-render/
types'
}
from
'../../../../s
hared/lib/app-router-
types'
import
{
callServer
}
from
'../../../app-call-server'
import
{
callServer
}
from
'../../../app-call-server'
import
{
findSourceMapURL
}
from
'../../../app-find-source-map-url'
import
{
findSourceMapURL
}
from
'../../../app-find-source-map-url'
import
{
import
{
...
@@ -34,7 +34,7 @@ import { createHrefFromUrl } from '../create-href-from-url'
...
@@ -34,7 +34,7 @@ import { createHrefFromUrl } from '../create-href-from-url'
import
{
handleExternalUrl
}
from
'./navigate-reducer'
import
{
handleExternalUrl
}
from
'./navigate-reducer'
import
{
applyRouterStatePatchToTree
}
from
'../apply-router-state-patch-to-tree'
import
{
applyRouterStatePatchToTree
}
from
'../apply-router-state-patch-to-tree'
import
{
isNavigatingToNewRootLayout
}
from
'../is-navigating-to-new-root-layout'
import
{
isNavigatingToNewRootLayout
}
from
'../is-navigating-to-new-root-layout'
import
type
{
CacheNode
}
from
'../../../../shared/lib/app-router-
context.shared-runtime
'
import
type
{
CacheNode
}
from
'../../../../shared/lib/app-router-
types
'
import
{
handleMutable
}
from
'../handle-mutable'
import
{
handleMutable
}
from
'../handle-mutable'
import
{
fillLazyItemsTillLeafWithHead
}
from
'../fill-lazy-items-till-leaf-with-head'
import
{
fillLazyItemsTillLeafWithHead
}
from
'../fill-lazy-items-till-leaf-with-head'
import
{
createEmptyCacheNode
}
from
'../../app-router'
import
{
createEmptyCacheNode
}
from
'../../app-router'
...
...
packages/next/src/client/components/router-reducer/reducers/server-patch-reducer.ts
View file @
b5b27206
...
@@ -10,7 +10,7 @@ import type {
...
@@ -10,7 +10,7 @@ import type {
import
{
handleExternalUrl
}
from
'./navigate-reducer'
import
{
handleExternalUrl
}
from
'./navigate-reducer'
import
{
applyFlightData
}
from
'../apply-flight-data'
import
{
applyFlightData
}
from
'../apply-flight-data'
import
{
handleMutable
}
from
'../handle-mutable'
import
{
handleMutable
}
from
'../handle-mutable'
import
type
{
CacheNode
}
from
'../../../../shared/lib/app-router-
context.shared-runtime
'
import
type
{
CacheNode
}
from
'../../../../shared/lib/app-router-
types
'
import
{
createEmptyCacheNode
}
from
'../../app-router'
import
{
createEmptyCacheNode
}
from
'../../app-router'
export
function
serverPatchReducer
(
export
function
serverPatchReducer
(
...
...
packages/next/src/client/components/router-reducer/refetch-inactive-parallel-segments.ts
View file @
b5b27206
import
type
{
FlightRouterState
}
from
'../../../server/app-render/types'
import
type
{
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-context.shared-runtime'
FlightRouterState
,
CacheNode
,
}
from
'../../../shared/lib/app-router-types'
import
type
{
AppRouterState
}
from
'./router-reducer-types'
import
type
{
AppRouterState
}
from
'./router-reducer-types'
import
{
applyFlightData
}
from
'./apply-flight-data'
import
{
applyFlightData
}
from
'./apply-flight-data'
import
{
fetchServerResponse
}
from
'./fetch-server-response'
import
{
fetchServerResponse
}
from
'./fetch-server-response'
...
...
packages/next/src/client/components/router-reducer/router-reducer-types.ts
View file @
b5b27206
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-
context.shared-runtime
'
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-
types
'
import
type
{
import
type
{
FlightRouterState
,
FlightRouterState
,
FlightSegmentPath
,
FlightSegmentPath
,
}
from
'../../../s
erver/app-render/
types'
}
from
'../../../s
hared/lib/app-router-
types'
import
type
{
FetchServerResponseResult
}
from
'./fetch-server-response'
import
type
{
FetchServerResponseResult
}
from
'./fetch-server-response'
export
const
ACTION_REFRESH
=
'refresh'
export
const
ACTION_REFRESH
=
'refresh'
...
...
packages/next/src/client/components/router-reducer/should-hard-navigate.test.tsx
View file @
b5b27206
...
@@ -2,7 +2,7 @@ import React from 'react'
...
@@ -2,7 +2,7 @@ import React from 'react'
import
type
{
import
type
{
FlightData
,
FlightData
,
FlightRouterState
,
FlightRouterState
,
}
from
'../../../s
erver/app-render/
types'
}
from
'../../../s
hared/lib/app-router-
types'
import
{
shouldHardNavigate
}
from
'./should-hard-navigate'
import
{
shouldHardNavigate
}
from
'./should-hard-navigate'
describe
(
'shouldHardNavigate'
,
()
=>
{
describe
(
'shouldHardNavigate'
,
()
=>
{
...
...
packages/next/src/client/components/router-reducer/should-hard-navigate.ts
View file @
b5b27206
...
@@ -2,7 +2,7 @@ import type {
...
@@ -2,7 +2,7 @@ import type {
FlightRouterState
,
FlightRouterState
,
FlightDataPath
,
FlightDataPath
,
Segment
,
Segment
,
}
from
'../../../s
erver/app-render/
types'
}
from
'../../../s
hared/lib/app-router-
types'
import
{
getNextFlightSegmentPath
}
from
'../../flight-data-helpers'
import
{
getNextFlightSegmentPath
}
from
'../../flight-data-helpers'
import
{
matchSegment
}
from
'../match-segments'
import
{
matchSegment
}
from
'../match-segments'
...
...
packages/next/src/client/components/segment-cache-impl/cache.ts
View file @
b5b27206
...
@@ -6,13 +6,13 @@ import type {
...
@@ -6,13 +6,13 @@ import type {
import
type
{
import
type
{
HeadData
,
HeadData
,
LoadingModuleData
,
LoadingModuleData
,
}
from
'../../../shared/lib/app-router-
context.shared-runtime
'
}
from
'../../../shared/lib/app-router-
types
'
import
type
{
import
type
{
CacheNodeSeedData
,
CacheNodeSeedData
,
DynamicParamTypesShort
,
DynamicParamTypesShort
,
Segment
as
FlightRouterStateSegment
,
Segment
as
FlightRouterStateSegment
,
}
from
'../../../s
erver/app-render/
types'
}
from
'../../../s
hared/lib/app-router-
types'
import
{
HasLoadingBoundary
}
from
'../../../s
erver/app-render/
types'
import
{
HasLoadingBoundary
}
from
'../../../s
hared/lib/app-router-
types'
import
{
import
{
NEXT_DID_POSTPONE_HEADER
,
NEXT_DID_POSTPONE_HEADER
,
NEXT_ROUTER_PREFETCH_HEADER
,
NEXT_ROUTER_PREFETCH_HEADER
,
...
@@ -70,7 +70,7 @@ import {
...
@@ -70,7 +70,7 @@ import {
import
type
{
import
type
{
FlightRouterState
,
FlightRouterState
,
NavigationFlightResponse
,
NavigationFlightResponse
,
}
from
'../../../s
erver/app-render/
types'
}
from
'../../../s
hared/lib/app-router-
types'
import
{
normalizeFlightData
}
from
'../../flight-data-helpers'
import
{
normalizeFlightData
}
from
'../../flight-data-helpers'
import
{
STATIC_STALETIME_MS
}
from
'../router-reducer/prefetch-cache-utils'
import
{
STATIC_STALETIME_MS
}
from
'../router-reducer/prefetch-cache-utils'
import
{
pingVisibleLinks
}
from
'../links'
import
{
pingVisibleLinks
}
from
'../links'
...
...
packages/next/src/client/components/segment-cache-impl/navigation.ts
View file @
b5b27206
...
@@ -2,12 +2,12 @@ import type {
...
@@ -2,12 +2,12 @@ import type {
CacheNodeSeedData
,
CacheNodeSeedData
,
FlightRouterState
,
FlightRouterState
,
FlightSegmentPath
,
FlightSegmentPath
,
}
from
'../../../server/app-render/types'
}
from
'../../../shared/lib/app-router-types'
import
type
{
CacheNode
}
from
'../../../shared/lib/app-router-types'
import
type
{
import
type
{
CacheNode
,
HeadData
,
HeadData
,
LoadingModuleData
,
LoadingModuleData
,
}
from
'../../../shared/lib/app-router-
context.shared-runtime
'
}
from
'../../../shared/lib/app-router-
types
'
import
type
{
NormalizedFlightData
}
from
'../../flight-data-helpers'
import
type
{
NormalizedFlightData
}
from
'../../flight-data-helpers'
import
{
fetchServerResponse
}
from
'../router-reducer/fetch-server-response'
import
{
fetchServerResponse
}
from
'../router-reducer/fetch-server-response'
import
{
import
{
...
...
packages/next/src/client/components/segment-cache-impl/prefetch.ts
View file @
b5b27206
import
type
{
FlightRouterState
}
from
'../../../s
erver/app-render/
types'
import
type
{
FlightRouterState
}
from
'../../../s
hared/lib/app-router-
types'
import
{
createPrefetchURL
}
from
'../app-router'
import
{
createPrefetchURL
}
from
'../app-router'
import
{
createCacheKey
}
from
'./cache-key'
import
{
createCacheKey
}
from
'./cache-key'
import
{
schedulePrefetchTask
}
from
'./scheduler'
import
{
schedulePrefetchTask
}
from
'./scheduler'
...
...
packages/next/src/client/components/segment-cache-impl/scheduler.ts
View file @
b5b27206
...
@@ -2,8 +2,8 @@ import type {
...
@@ -2,8 +2,8 @@ import type {
FlightRouterState
,
FlightRouterState
,
Segment
as
FlightRouterStateSegment
,
Segment
as
FlightRouterStateSegment
,
Segment
,
Segment
,
}
from
'../../../s
erver/app-render/
types'
}
from
'../../../s
hared/lib/app-router-
types'
import
{
HasLoadingBoundary
}
from
'../../../s
erver/app-render/
types'
import
{
HasLoadingBoundary
}
from
'../../../s
hared/lib/app-router-
types'
import
{
matchSegment
}
from
'../match-segments'
import
{
matchSegment
}
from
'../match-segments'
import
{
import
{
readOrCreateRouteCacheEntry
,
readOrCreateRouteCacheEntry
,
...
...
packages/next/src/client/flight-data-helpers.test.ts
View file @
b5b27206
import
{
prepareFlightRouterStateForRequest
}
from
'./flight-data-helpers'
import
{
prepareFlightRouterStateForRequest
}
from
'./flight-data-helpers'
import
type
{
FlightRouterState
}
from
'../server/app-render/types'
import
{
import
{
HasLoadingBoundary
}
from
'../server/app-render/types'
HasLoadingBoundary
,
type
FlightRouterState
,
}
from
'../shared/lib/app-router-types'
describe
(
'prepareFlightRouterStateForRequest'
,
()
=>
{
describe
(
'prepareFlightRouterStateForRequest'
,
()
=>
{
describe
(
'HMR refresh handling'
,
()
=>
{
describe
(
'HMR refresh handling'
,
()
=>
{
...
...
packages/next/src/client/flight-data-helpers.ts
View file @
b5b27206
...
@@ -5,8 +5,8 @@ import type {
...
@@ -5,8 +5,8 @@ import type {
FlightRouterState
,
FlightRouterState
,
FlightSegmentPath
,
FlightSegmentPath
,
Segment
,
Segment
,
}
from
'../server/app-render/types'
HeadData
,
import
type
{
HeadData
}
from
'../shared/lib/app-router-context.shared-runtime
'
}
from
'../shared/lib/app-router-types
'
import
{
PAGE_SEGMENT_KEY
}
from
'../shared/lib/segment'
import
{
PAGE_SEGMENT_KEY
}
from
'../shared/lib/segment'
export
type
NormalizedFlightData
=
{
export
type
NormalizedFlightData
=
{
...
...
packages/next/src/client/route-params.ts
View file @
b5b27206
import
type
{
DynamicParamTypesShort
}
from
'../s
erver/app-render/
types'
import
type
{
DynamicParamTypesShort
}
from
'../s
hared/lib/app-router-
types'
import
{
import
{
addSearchParamsIfPageSegment
,
addSearchParamsIfPageSegment
,
DEFAULT_SEGMENT_KEY
,
DEFAULT_SEGMENT_KEY
,
...
...
packages/next/src/server/app-render/app-render.tsx
View file @
b5b27206
import
type
{
RenderOpts
,
PreloadCallbacks
}
from
'./types'
import
type
{
import
type
{
ActionResult
,
ActionResult
,
DynamicParamTypesShort
,
DynamicParamTypesShort
,
FlightRouterState
,
FlightRouterState
,
RenderOpts
,
Segment
,
Segment
,
CacheNodeSeedData
,
CacheNodeSeedData
,
PreloadCallbacks
,
RSCPayload
,
RSCPayload
,
FlightData
,
FlightData
,
InitialRSCPayload
,
InitialRSCPayload
,
FlightDataPath
,
FlightDataPath
,
}
from
'.
/
types'
}
from
'.
./../shared/lib/app-router-
types'
import
{
import
{
workAsyncStorage
,
workAsyncStorage
,
type
WorkStore
,
type
WorkStore
,
...
...
packages/next/src/server/app-render/collect-segment-data.tsx
View file @
b5b27206
...
@@ -3,7 +3,9 @@ import type {
...
@@ -3,7 +3,9 @@ import type {
FlightRouterState
,
FlightRouterState
,
InitialRSCPayload
,
InitialRSCPayload
,
DynamicParamTypesShort
,
DynamicParamTypesShort
,
}
from
'./types'
HeadData
,
LoadingModuleData
,
}
from
'../../shared/lib/app-router-types'
import
type
{
ManifestNode
}
from
'../../build/webpack/plugins/flight-manifest-plugin'
import
type
{
ManifestNode
}
from
'../../build/webpack/plugins/flight-manifest-plugin'
// eslint-disable-next-line import/no-extraneous-dependencies
// eslint-disable-next-line import/no-extraneous-dependencies
...
@@ -16,10 +18,6 @@ import {
...
@@ -16,10 +18,6 @@ import {
streamToBuffer
,
streamToBuffer
,
}
from
'../stream-utils/node-web-streams-helper'
}
from
'../stream-utils/node-web-streams-helper'
import
{
waitAtLeastOneReactRenderTask
}
from
'../../lib/scheduler'
import
{
waitAtLeastOneReactRenderTask
}
from
'../../lib/scheduler'
import
type
{
HeadData
,
LoadingModuleData
,
}
from
'../../shared/lib/app-router-context.shared-runtime'
import
{
import
{
type
SegmentRequestKey
,
type
SegmentRequestKey
,
createSegmentRequestKeyPart
,
createSegmentRequestKeyPart
,
...
...
packages/next/src/server/app-render/create-component-tree.tsx
View file @
b5b27206
import
type
{
CacheNodeSeedData
,
PreloadCallbacks
}
from
'./types'
import
type
{
CacheNodeSeedData
,
LoadingModuleData
,
}
from
'../../shared/lib/app-router-types'
import
type
{
PreloadCallbacks
}
from
'./types'
import
React
from
'react'
import
React
from
'react'
import
{
import
{
isClientReference
,
isClientReference
,
...
@@ -17,7 +21,6 @@ import { PARALLEL_ROUTE_DEFAULT_PATH } from '../../client/components/builtin/def
...
@@ -17,7 +21,6 @@ import { PARALLEL_ROUTE_DEFAULT_PATH } from '../../client/components/builtin/def
import
{
getTracer
}
from
'../lib/trace/tracer'
import
{
getTracer
}
from
'../lib/trace/tracer'
import
{
NextNodeServerSpan
}
from
'../lib/trace/constants'
import
{
NextNodeServerSpan
}
from
'../lib/trace/constants'
import
{
StaticGenBailoutError
}
from
'../../client/components/static-generation-bailout'
import
{
StaticGenBailoutError
}
from
'../../client/components/static-generation-bailout'
import
type
{
LoadingModuleData
}
from
'../../shared/lib/app-router-context.shared-runtime'
import
type
{
Params
}
from
'../request/params'
import
type
{
Params
}
from
'../request/params'
import
{
workUnitAsyncStorage
}
from
'./work-unit-async-storage.external'
import
{
workUnitAsyncStorage
}
from
'./work-unit-async-storage.external'
import
{
OUTLET_BOUNDARY_NAME
}
from
'../../lib/framework/boundary-constants'
import
{
OUTLET_BOUNDARY_NAME
}
from
'../../lib/framework/boundary-constants'
...
...
packages/next/src/server/app-render/create-flight-router-state-from-loader-tree.ts
View file @
b5b27206
import
type
{
LoaderTree
}
from
'../lib/app-dir-module'
import
type
{
LoaderTree
}
from
'../lib/app-dir-module'
import
{
HasLoadingBoundary
,
type
FlightRouterState
}
from
'./types'
import
{
HasLoadingBoundary
,
type
FlightRouterState
,
}
from
'../../shared/lib/app-router-types'
import
type
{
GetDynamicParamFromSegment
}
from
'./app-render'
import
type
{
GetDynamicParamFromSegment
}
from
'./app-render'
import
{
addSearchParamsIfPageSegment
}
from
'../../shared/lib/segment'
import
{
addSearchParamsIfPageSegment
}
from
'../../shared/lib/segment'
...
...
packages/next/src/server/app-render/get-segment-param.tsx
View file @
b5b27206
import
{
INTERCEPTION_ROUTE_MARKERS
}
from
'../../shared/lib/router/utils/interception-routes'
import
{
INTERCEPTION_ROUTE_MARKERS
}
from
'../../shared/lib/router/utils/interception-routes'
import
type
{
DynamicParamTypes
}
from
'.
/
types'
import
type
{
DynamicParamTypes
}
from
'.
./../shared/lib/app-router-
types'
/**
/**
* Parse dynamic route segment to type of parameter
* Parse dynamic route segment to type of parameter
...
...
packages/next/src/server/app-render/get-short-dynamic-param-type.tsx
View file @
b5b27206
import
type
{
DynamicParamTypes
,
DynamicParamTypesShort
}
from
'./types'
import
type
{
DynamicParamTypes
,
DynamicParamTypesShort
,
}
from
'../../shared/lib/app-router-types'
export
const
dynamicParamTypes
:
Record
<
export
const
dynamicParamTypes
:
Record
<
DynamicParamTypes
,
DynamicParamTypes
,
...
...
packages/next/src/server/app-render/parse-and-validate-flight-router-state.tsx
View file @
b5b27206
import
type
{
FlightRouterState
}
from
'.
/
types'
import
type
{
FlightRouterState
}
from
'.
./../shared/lib/app-router-
types'
import
{
flightRouterStateSchema
}
from
'./types'
import
{
flightRouterStateSchema
}
from
'./types'
import
{
assert
}
from
'next/dist/compiled/superstruct'
import
{
assert
}
from
'next/dist/compiled/superstruct'
...
...
packages/next/src/server/app-render/types.ts
View file @
b5b27206
...
@@ -8,10 +8,6 @@ import type { ClientReferenceManifest } from '../../build/webpack/plugins/flight
...
@@ -8,10 +8,6 @@ import type { ClientReferenceManifest } from '../../build/webpack/plugins/flight
import
type
{
NextFontManifest
}
from
'../../build/webpack/plugins/next-font-manifest-plugin'
import
type
{
NextFontManifest
}
from
'../../build/webpack/plugins/next-font-manifest-plugin'
import
type
{
ParsedUrlQuery
}
from
'querystring'
import
type
{
ParsedUrlQuery
}
from
'querystring'
import
type
{
AppPageModule
}
from
'../route-modules/app-page/module'
import
type
{
AppPageModule
}
from
'../route-modules/app-page/module'
import
type
{
HeadData
,
LoadingModuleData
,
}
from
'../../shared/lib/app-router-context.shared-runtime'
import
type
{
DeepReadonly
}
from
'../../shared/lib/deep-readonly'
import
type
{
DeepReadonly
}
from
'../../shared/lib/deep-readonly'
import
type
{
__ApiPreviewProps
}
from
'../api-utils'
import
type
{
__ApiPreviewProps
}
from
'../api-utils'
...
@@ -23,17 +19,8 @@ import type { BaseNextRequest } from '../base-http'
...
@@ -23,17 +19,8 @@ import type { BaseNextRequest } from '../base-http'
import
type
{
IncomingMessage
}
from
'http'
import
type
{
IncomingMessage
}
from
'http'
import
type
{
RenderResumeDataCache
}
from
'../resume-data-cache/resume-data-cache'
import
type
{
RenderResumeDataCache
}
from
'../resume-data-cache/resume-data-cache'
export
type
DynamicParamTypes
=
|
'catchall'
|
'catchall-intercepted'
|
'optional-catchall'
|
'dynamic'
|
'dynamic-intercepted'
const
dynamicParamTypesSchema
=
s
.
enums
([
'c'
,
'ci'
,
'oc'
,
'd'
,
'di'
])
const
dynamicParamTypesSchema
=
s
.
enums
([
'c'
,
'ci'
,
'oc'
,
'd'
,
'di'
])
export
type
DynamicParamTypesShort
=
s
.
Infer
<
typeof
dynamicParamTypesSchema
>
const
segmentSchema
=
s
.
union
([
const
segmentSchema
=
s
.
union
([
s
.
string
(),
s
.
string
(),
...
@@ -52,8 +39,6 @@ const segmentSchema = s.union([
...
@@ -52,8 +39,6 @@ const segmentSchema = s.union([
]),
]),
])
])
export
type
Segment
=
s
.
Infer
<
typeof
segmentSchema
>
// unfortunately the tuple is not understood well by Describe so we have to
// unfortunately the tuple is not understood well by Describe so we have to
// use any here. This does not have any impact on the runtime type since the validation
// use any here. This does not have any impact on the runtime type since the validation
// does work correctly.
// does work correctly.
...
@@ -77,124 +62,6 @@ export const flightRouterStateSchema: s.Describe<any> = s.tuple([
...
@@ -77,124 +62,6 @@ export const flightRouterStateSchema: s.Describe<any> = s.tuple([
s
.
optional
(
s
.
boolean
()),
s
.
optional
(
s
.
boolean
()),
])
])
/**
* Router state
*/
export
type
FlightRouterState
=
[
segment
:
Segment
,
parallelRoutes
:
{
[
parallelRouterKey
:
string
]:
FlightRouterState
},
url
?:
string
|
null
,
/**
* "refresh" and "refetch", despite being similarly named, have different
* semantics:
* - "refetch" is used during a request to inform the server where rendering
* should start from.
*
* - "refresh" is used by the client to mark that a segment should re-fetch the
* data from the server for the current segment. It uses the "url" property
* above to determine where to fetch from.
*
* - "inside-shared-layout" is used during a prefetch request to inform the
* server that even if the segment matches, it should be treated as if it's
* within the "new" part of a navigation — inside the shared layout. If
* the segment doesn't match, then it has no effect, since it would be
* treated as new regardless. If it does match, though, the server does not
* need to render it, because the client already has it.
*
* - "metadata-only" instructs the server to skip rendering the segments and
* only send the head data.
*
* A bit confusing, but that's because it has only one extremely narrow use
* case — during a non-PPR prefetch, the server uses it to find the first
* loading boundary beneath a shared layout.
*
* TODO: We should rethink the protocol for dynamic requests. It might not
* make sense for the client to send a FlightRouterState, since this type is
* overloaded with concerns.
*/
refresh
?:
|
'refetch'
|
'refresh'
|
'inside-shared-layout'
|
'metadata-only'
|
null
,
isRootLayout
?:
boolean
,
/**
* Only present when responding to a tree prefetch request. Indicates whether
* there is a loading boundary somewhere in the tree. The client cache uses
* this to determine if it can skip the data prefetch request.
*/
hasLoadingBoundary
?:
HasLoadingBoundary
,
]
export
const
enum
HasLoadingBoundary
{
// There is a loading boundary in this particular segment
SegmentHasLoadingBoundary
=
1
,
// There is a loading boundary somewhere in the subtree (but not in
// this segment)
SubtreeHasLoadingBoundary
=
2
,
// There is no loading boundary in this segment or any of its descendants
SubtreeHasNoLoadingBoundary
=
3
,
}
/**
* Individual Flight response path
*/
export
type
FlightSegmentPath
=
// Uses `any` as repeating pattern can't be typed.
|
any
[]
// Looks somewhat like this
|
[
segment
:
Segment
,
parallelRouterKey
:
string
,
segment
:
Segment
,
parallelRouterKey
:
string
,
segment
:
Segment
,
parallelRouterKey
:
string
,
]
/**
* Represents a tree of segments and the Flight data (i.e. React nodes) that
* correspond to each one. The tree is isomorphic to the FlightRouterState;
* however in the future we want to be able to fetch arbitrary partial segments
* without having to fetch all its children. So this response format will
* likely change.
*/
export
type
CacheNodeSeedData
=
[
segment
:
Segment
,
node
:
React
.
ReactNode
|
null
,
parallelRoutes
:
{
[
parallelRouterKey
:
string
]:
CacheNodeSeedData
|
null
},
loading
:
LoadingModuleData
|
Promise
<
LoadingModuleData
>
,
isPartial
:
boolean
,
]
export
type
FlightDataSegment
=
[
/* segment of the rendered slice: */
Segment
,
/* treePatch */
FlightRouterState
,
/* cacheNodeSeedData */
CacheNodeSeedData
|
null
,
// Can be null during prefetch if there's no loading component
/* head: viewport */
HeadData
,
/* isHeadPartial */
boolean
,
]
export
type
FlightDataPath
=
// Uses `any` as repeating pattern can't be typed.
|
any
[]
// Looks somewhat like this
|
[
// Holds full path to the segment.
...
FlightSegmentPath
[],
...
FlightDataSegment
,
]
/**
* The Flight response data
*/
export
type
FlightData
=
Array
<
FlightDataPath
>
|
string
export
type
ActionResult
=
Promise
<
any
>
export
type
ServerOnInstrumentationRequestError
=
(
export
type
ServerOnInstrumentationRequestError
=
(
error
:
unknown
,
error
:
unknown
,
// The request could be middleware, node server or web server request,
// The request could be middleware, node server or web server request,
...
@@ -321,49 +188,3 @@ export type RenderOpts = LoadComponentsReturnType<AppPageModule> &
...
@@ -321,49 +188,3 @@ export type RenderOpts = LoadComponentsReturnType<AppPageModule> &
RequestLifecycleOpts
RequestLifecycleOpts
export
type
PreloadCallbacks
=
(()
=>
void
)[]
export
type
PreloadCallbacks
=
(()
=>
void
)[]
export
type
InitialRSCPayload
=
{
/** buildId */
b
:
string
/** assetPrefix */
p
:
string
/** initialCanonicalUrlParts */
c
:
string
[]
/** couldBeIntercepted */
i
:
boolean
/** initialFlightData */
f
:
FlightDataPath
[]
/** missingSlots */
m
:
Set
<
string
>
|
undefined
/** GlobalError */
G
:
[
React
.
ComponentType
<
any
>
,
React
.
ReactNode
|
undefined
]
/** postponed */
s
:
boolean
/** prerendered */
S
:
boolean
}
// Response from `createFromFetch` for normal rendering
export
type
NavigationFlightResponse
=
{
/** buildId */
b
:
string
/** flightData */
f
:
FlightData
/** prerendered */
S
:
boolean
}
// Response from `createFromFetch` for server actions. Action's flight data can be null
export
type
ActionFlightResponse
=
{
/** actionResult */
a
:
ActionResult
/** buildId */
b
:
string
/** flightData */
f
:
FlightData
}
export
type
RSCPayload
=
|
InitialRSCPayload
|
NavigationFlightResponse
|
ActionFlightResponse
packages/next/src/server/app-render/walk-tree-with-flight-router-state.tsx
View file @
b5b27206
...
@@ -2,9 +2,10 @@ import type {
...
@@ -2,9 +2,10 @@ import type {
FlightDataPath
,
FlightDataPath
,
FlightDataSegment
,
FlightDataSegment
,
FlightRouterState
,
FlightRouterState
,
PreloadCallbacks
,
Segment
,
Segment
,
}
from
'./types'
HeadData
,
}
from
'../../shared/lib/app-router-types'
import
type
{
PreloadCallbacks
}
from
'./types'
import
{
matchSegment
}
from
'../../client/components/match-segments'
import
{
matchSegment
}
from
'../../client/components/match-segments'
import
type
{
LoaderTree
}
from
'../lib/app-dir-module'
import
type
{
LoaderTree
}
from
'../lib/app-dir-module'
import
{
getLinkAndScriptTags
}
from
'./get-css-inlined-link-tags'
import
{
getLinkAndScriptTags
}
from
'./get-css-inlined-link-tags'
...
@@ -20,7 +21,6 @@ import {
...
@@ -20,7 +21,6 @@ import {
addSearchParamsIfPageSegment
,
addSearchParamsIfPageSegment
,
}
from
'../../shared/lib/segment'
}
from
'../../shared/lib/segment'
import
{
createComponentTree
}
from
'./create-component-tree'
import
{
createComponentTree
}
from
'./create-component-tree'
import
type
{
HeadData
}
from
'../../shared/lib/app-router-context.shared-runtime'
import
{
getSegmentParam
}
from
'./get-segment-param'
import
{
getSegmentParam
}
from
'./get-segment-param'
/**
/**
...
...
packages/next/src/server/dev/on-demand-entry-handler.ts
View file @
b5b27206
...
@@ -5,7 +5,7 @@ import type {
...
@@ -5,7 +5,7 @@ import type {
DynamicParamTypesShort
,
DynamicParamTypesShort
,
FlightRouterState
,
FlightRouterState
,
FlightSegmentPath
,
FlightSegmentPath
,
}
from
'../
app-render/
types'
}
from
'../
../shared/lib/app-router-
types'
import
type
{
CompilerNameValues
}
from
'../../shared/lib/constants'
import
type
{
CompilerNameValues
}
from
'../../shared/lib/constants'
import
type
{
RouteDefinition
}
from
'../route-definitions/route-definition'
import
type
{
RouteDefinition
}
from
'../route-definitions/route-definition'
import
type
HotReloaderWebpack
from
'./hot-reloader-webpack'
import
type
HotReloaderWebpack
from
'./hot-reloader-webpack'
...
...
packages/next/src/shared/lib/app-router-context.shared-runtime.ts
View file @
b5b27206
'use client'
'use client'
import
type
{
FetchServerResponseResult
}
from
'../../client/components/router-reducer/fetch-server-response'
import
type
{
import
type
{
FocusAndScrollRef
,
FocusAndScrollRef
,
PrefetchKind
,
PrefetchKind
,
...
@@ -8,114 +7,10 @@ import type {
...
@@ -8,114 +7,10 @@ import type {
import
type
{
import
type
{
FlightRouterState
,
FlightRouterState
,
FlightSegmentPath
,
FlightSegmentPath
,
}
from
'../../server/app-render/types'
CacheNode
,
}
from
'./app-router-types'
import
React
from
'react'
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
{
export
interface
NavigateOptions
{
scroll
?:
boolean
scroll
?:
boolean
}
}
...
...
packages/next/src/shared/lib/app-router-types.ts
0 → 100644
View file @
b5b27206
/**
* App Router types - Client-safe types for the Next.js App Router
*
* This file contains type definitions that can be safely imported
* by both client-side and server-side code without circular dependencies.
*/
import
type
{
FetchServerResponseResult
}
from
'../../client/components/router-reducer/fetch-server-response'
import
type
React
from
'react'
export
type
LoadingModuleData
=
|
[
React
.
JSX
.
Element
,
React
.
ReactNode
,
React
.
ReactNode
]
|
null
/** viewport metadata node */
export
type
HeadData
=
React
.
ReactNode
export
type
ChildSegmentMap
=
Map
<
string
,
CacheNode
>
/**
* Cache node used in app-router / layout-router.
*/
export
type
CacheNode
=
ReadyCacheNode
|
LazyCacheNode
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
type
DynamicParamTypes
=
|
'catchall'
|
'catchall-intercepted'
|
'optional-catchall'
|
'dynamic'
|
'dynamic-intercepted'
export
type
DynamicParamTypesShort
=
'c'
|
'ci'
|
'oc'
|
'd'
|
'di'
export
type
Segment
=
|
string
|
[
// Param name
string
,
// Param cache key (almost the same as the value, but arrays are
// concatenated into strings)
// TODO: We should change this to just be the value. Currently we convert
// it back to a value when passing to useParams. It only needs to be
// a string when converted to a a cache key, but that doesn't mean we
// need to store it as that representation.
string
,
// Dynamic param type
DynamicParamTypesShort
,
]
/**
* Router state
*/
export
type
FlightRouterState
=
[
segment
:
Segment
,
parallelRoutes
:
{
[
parallelRouterKey
:
string
]:
FlightRouterState
},
url
?:
string
|
null
,
/**
* "refresh" and "refetch", despite being similarly named, have different
* semantics:
* - "refetch" is used during a request to inform the server where rendering
* should start from.
*
* - "refresh" is used by the client to mark that a segment should re-fetch the
* data from the server for the current segment. It uses the "url" property
* above to determine where to fetch from.
*
* - "inside-shared-layout" is used during a prefetch request to inform the
* server that even if the segment matches, it should be treated as if it's
* within the "new" part of a navigation — inside the shared layout. If
* the segment doesn't match, then it has no effect, since it would be
* treated as new regardless. If it does match, though, the server does not
* need to render it, because the client already has it.
*
* - "metadata-only" instructs the server to skip rendering the segments and
* only send the head data.
*
* A bit confusing, but that's because it has only one extremely narrow use
* case — during a non-PPR prefetch, the server uses it to find the first
* loading boundary beneath a shared layout.
*
* TODO: We should rethink the protocol for dynamic requests. It might not
* make sense for the client to send a FlightRouterState, since this type is
* overloaded with concerns.
*/
refresh
?:
|
'refetch'
|
'refresh'
|
'inside-shared-layout'
|
'metadata-only'
|
null
,
isRootLayout
?:
boolean
,
/**
* Only present when responding to a tree prefetch request. Indicates whether
* there is a loading boundary somewhere in the tree. The client cache uses
* this to determine if it can skip the data prefetch request.
*/
hasLoadingBoundary
?:
HasLoadingBoundary
,
]
export
const
enum
HasLoadingBoundary
{
// There is a loading boundary in this particular segment
SegmentHasLoadingBoundary
=
1
,
// There is a loading boundary somewhere in the subtree (but not in
// this segment)
SubtreeHasLoadingBoundary
=
2
,
// There is no loading boundary in this segment or any of its descendants
SubtreeHasNoLoadingBoundary
=
3
,
}
/**
* Individual Flight response path
*/
export
type
FlightSegmentPath
=
// Uses `any` as repeating pattern can't be typed.
|
any
[]
// Looks somewhat like this
|
[
segment
:
Segment
,
parallelRouterKey
:
string
,
segment
:
Segment
,
parallelRouterKey
:
string
,
segment
:
Segment
,
parallelRouterKey
:
string
,
]
/**
* Represents a tree of segments and the Flight data (i.e. React nodes) that
* correspond to each one. The tree is isomorphic to the FlightRouterState;
* however in the future we want to be able to fetch arbitrary partial segments
* without having to fetch all its children. So this response format will
* likely change.
*/
export
type
CacheNodeSeedData
=
[
segment
:
Segment
,
node
:
React
.
ReactNode
|
null
,
parallelRoutes
:
{
[
parallelRouterKey
:
string
]:
CacheNodeSeedData
|
null
},
loading
:
LoadingModuleData
|
Promise
<
LoadingModuleData
>
,
isPartial
:
boolean
,
]
export
type
FlightDataSegment
=
[
/* segment of the rendered slice: */
Segment
,
/* treePatch */
FlightRouterState
,
/* cacheNodeSeedData */
CacheNodeSeedData
|
null
,
// Can be null during prefetch if there's no loading component
/* head: viewport */
HeadData
,
/* isHeadPartial */
boolean
,
]
export
type
FlightDataPath
=
// Uses `any` as repeating pattern can't be typed.
|
any
[]
// Looks somewhat like this
|
[
// Holds full path to the segment.
...
FlightSegmentPath
[],
...
FlightDataSegment
,
]
/**
* The Flight response data
*/
export
type
FlightData
=
Array
<
FlightDataPath
>
|
string
export
type
ActionResult
=
Promise
<
any
>
export
type
InitialRSCPayload
=
{
/** buildId */
b
:
string
/** assetPrefix */
p
:
string
/** initialCanonicalUrlParts */
c
:
string
[]
/** couldBeIntercepted */
i
:
boolean
/** initialFlightData */
f
:
FlightDataPath
[]
/** missingSlots */
m
:
Set
<
string
>
|
undefined
/** GlobalError */
G
:
[
React
.
ComponentType
<
any
>
,
React
.
ReactNode
|
undefined
]
/** postponed */
s
:
boolean
/** prerendered */
S
:
boolean
}
// Response from `createFromFetch` for normal rendering
export
type
NavigationFlightResponse
=
{
/** buildId */
b
:
string
/** flightData */
f
:
FlightData
/** prerendered */
S
:
boolean
}
// Response from `createFromFetch` for server actions. Action's flight data can be null
export
type
ActionFlightResponse
=
{
/** actionResult */
a
:
ActionResult
/** buildId */
b
:
string
/** flightData */
f
:
FlightData
}
export
type
RSCPayload
=
|
InitialRSCPayload
|
NavigationFlightResponse
|
ActionFlightResponse
packages/next/src/shared/lib/router/utils/get-dynamic-param.ts
View file @
b5b27206
import
type
{
DynamicParam
}
from
'../../../../server/app-render/app-render'
import
type
{
DynamicParam
}
from
'../../../../server/app-render/app-render'
import
type
{
DynamicParamTypesShort
}
from
'../../
../../server/app-render/
types'
import
type
{
DynamicParamTypesShort
}
from
'../../
app-router-
types'
import
type
{
FallbackRouteParams
}
from
'../../../../server/request/fallback-params'
import
type
{
FallbackRouteParams
}
from
'../../../../server/request/fallback-params'
/**
/**
...
...
packages/next/src/shared/lib/segment-cache/segment-value-encoding.ts
View file @
b5b27206
import
{
PAGE_SEGMENT_KEY
}
from
'../segment'
import
{
PAGE_SEGMENT_KEY
}
from
'../segment'
import
type
{
Segment
as
FlightRouterStateSegment
}
from
'../
../../server/app-render/
types'
import
type
{
Segment
as
FlightRouterStateSegment
}
from
'../
app-router-
types'
// TypeScript trick to simulate opaque types, like in Flow.
// TypeScript trick to simulate opaque types, like in Flow.
type
Opaque
<
K
,
T
>
=
T
&
{
__brand
:
K
}
type
Opaque
<
K
,
T
>
=
T
&
{
__brand
:
K
}
...
...
packages/next/src/shared/lib/segment.ts
View file @
b5b27206
import
type
{
Segment
}
from
'.
./../server/app-render/
types'
import
type
{
Segment
}
from
'.
/app-router-
types'
export
function
isGroupSegment
(
segment
:
string
)
{
export
function
isGroupSegment
(
segment
:
string
)
{
// Use array[0] for performant purpose
// Use array[0] for performant purpose
...
...
test/cache-components-tests-manifest.json
View file @
b5b27206
...
@@ -27,10 +27,11 @@
...
@@ -27,10 +27,11 @@
]
]
},
},
"test/production/app-dir/browser-chunks/browser-chunks.test.ts"
:
{
"test/production/app-dir/browser-chunks/browser-chunks.test.ts"
:
{
"passed"
:
[],
"passed"
:
[
"failed"
:
[
"browser-chunks must not bundle any server modules into browser chunks"
,
"browser-chunks must not bundle any server modules into browser chunks"
"browser-chunks must not bundle any dev overlay into browser chunks"
]
],
"failed"
:
[]
},
},
"test/e2e/next-form/default/next-form-prefetch.test.ts"
:
{
"test/e2e/next-form/default/next-form-prefetch.test.ts"
:
{
"passed"
:
[
"passed"
:
[
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment