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
dbf94c57
Unverified
Commit
dbf94c57
authored
Jul 15, 2022
by
Tim Neutkens
Committed by
GitHub
Jul 15, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix check for optimistic routing and handle loading in server-patch (#38687)
parent
2da0ca21
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
21 deletions
+25
-21
reducer.ts
packages/next/client/components/reducer.ts
+25
-21
No files found.
packages/next/client/components/reducer.ts
View file @
dbf94c57
...
@@ -154,27 +154,28 @@ const canOptimisticallyRender = (
...
@@ -154,27 +154,28 @@ const canOptimisticallyRender = (
):
boolean
=>
{
):
boolean
=>
{
const
segment
=
segments
[
0
]
const
segment
=
segments
[
0
]
const
isLastSegment
=
segments
.
length
===
1
const
isLastSegment
=
segments
.
length
===
1
const
[
existingSegment
,
existingParallelRoutes
,
,
,
loadingMarker
]
=
const
[
existingSegment
,
existingParallelRoutes
,
,
,
loadingMarker
]
=
flightRouterState
flightRouterState
// If the segments mismatch we can't resolve deeper into the tree
const
segmentMatches
=
matchSegment
(
existingSegment
,
segment
)
const
hasLoading
=
loadingMarker
===
'loading'
// If the segment mismatches we can't assume this level has loading
if
(
!
segmentMatches
)
{
return
false
}
const
hasLoading
=
loadingMarker
===
'loading'
// If the tree path holds at least one loading.js it will be optimistic
// If the tree path holds at least one loading.js it will be optimistic
if
(
hasLoading
)
{
if
(
hasLoading
)
{
return
true
return
true
}
}
// Above already catches the last segment case where `hasLoading` is true, so in this case it would always be `false`.
// Above already catches the last segment case where `hasLoading` is true, so in this case it would always be `false`.
if
(
isLastSegment
)
{
if
(
isLastSegment
)
{
return
false
return
false
}
}
// If the segments mismatch we can't resolve deeper into the tree
const
segmentMatches
=
matchSegment
(
existingSegment
,
segment
)
// If the existingParallelRoutes does not have a `children` parallelRouteKey we can't resolve deeper into the tree
// If the existingParallelRoutes does not have a `children` parallelRouteKey we can't resolve deeper into the tree
if
(
!
segmentMatches
||
!
existingParallelRoutes
.
children
)
{
if
(
!
existingParallelRoutes
.
children
)
{
return
hasLoading
return
hasLoading
}
}
...
@@ -188,9 +189,9 @@ const canOptimisticallyRender = (
...
@@ -188,9 +189,9 @@ const canOptimisticallyRender = (
const
createOptimisticTree
=
(
const
createOptimisticTree
=
(
segments
:
string
[],
segments
:
string
[],
flightRouterState
:
FlightRouterState
|
null
,
flightRouterState
:
FlightRouterState
|
null
,
isFirstSegment
:
boolean
,
_
isFirstSegment
:
boolean
,
parentRefetch
:
boolean
,
parentRefetch
:
boolean
,
href
?:
string
_
href
?:
string
):
FlightRouterState
=>
{
):
FlightRouterState
=>
{
const
[
existingSegment
,
existingParallelRoutes
]
=
flightRouterState
||
[
const
[
existingSegment
,
existingParallelRoutes
]
=
flightRouterState
||
[
null
,
null
,
...
@@ -232,10 +233,11 @@ const createOptimisticTree = (
...
@@ -232,10 +233,11 @@ const createOptimisticTree = (
result
[
3
]
=
'refetch'
result
[
3
]
=
'refetch'
}
}
// TODO-APP: Revisit
// Add url into the tree
// Add url into the tree
if
(
isFirstSegment
)
{
//
if (isFirstSegment) {
result
[
2
]
=
href
//
result[2] = href
}
//
}
// Copy the loading flag from existing tree
// Copy the loading flag from existing tree
if
(
flightRouterState
&&
flightRouterState
[
4
])
{
if
(
flightRouterState
&&
flightRouterState
[
4
])
{
...
@@ -250,15 +252,16 @@ const walkTreeWithFlightDataPath = (
...
@@ -250,15 +252,16 @@ const walkTreeWithFlightDataPath = (
flightRouterState
:
FlightRouterState
,
flightRouterState
:
FlightRouterState
,
treePatch
:
FlightRouterState
treePatch
:
FlightRouterState
):
FlightRouterState
=>
{
):
FlightRouterState
=>
{
const
[
segment
,
parallelRoutes
,
url
]
=
flightRouterState
const
[
segment
,
parallelRoutes
/* , url */
]
=
flightRouterState
// Root refresh
// Root refresh
if
(
flightSegmentPath
.
length
===
1
)
{
if
(
flightSegmentPath
.
length
===
1
)
{
const
tree
:
FlightRouterState
=
[...
treePatch
]
const
tree
:
FlightRouterState
=
[...
treePatch
]
if
(
url
)
{
// TODO-APP: revisit
tree
[
2
]
=
url
// if (url) {
}
// tree[2] = url
// }
return
tree
return
tree
}
}
...
@@ -286,13 +289,14 @@ const walkTreeWithFlightDataPath = (
...
@@ -286,13 +289,14 @@ const walkTreeWithFlightDataPath = (
},
},
]
]
if
(
url
)
{
// TODO-APP: Revisit
tree
[
2
]
=
url
// if (url) {
}
// tree[2] = url
// }
// Copy loading flag
// Copy loading flag
if
(
flight
SegmentPath
[
4
])
{
if
(
flight
RouterState
[
4
])
{
tree
[
4
]
=
flight
SegmentPath
[
4
]
tree
[
4
]
=
flight
RouterState
[
4
]
}
}
return
tree
return
tree
...
...
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