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
ccd6c4b2
Unverified
Commit
ccd6c4b2
authored
Nov 08, 2023
by
JJ Kasper
Committed by
GitHub
Nov 08, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix resume stream handling (#58159)
Ensures we don't await un-necessarily.
parent
7e368c2e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
6 deletions
+70
-6
app-render.tsx
packages/next/src/server/app-render/app-render.tsx
+5
-6
page.js
...standalone-mode/required-server-files/app/delayed/page.js
+30
-0
required-server-files-ppr.test.ts
...e/required-server-files/required-server-files-ppr.test.ts
+35
-0
No files found.
packages/next/src/server/app-render/app-render.tsx
View file @
ccd6c4b2
...
@@ -611,12 +611,11 @@ async function renderToHTMLOrFlightImpl(
...
@@ -611,12 +611,11 @@ async function renderToHTMLOrFlightImpl(
const
hasPostponed
=
typeof
renderOpts
.
postponed
===
'string'
const
hasPostponed
=
typeof
renderOpts
.
postponed
===
'string'
let
stringifiedFlightPayloadPromise
=
let
stringifiedFlightPayloadPromise
=
isStaticGeneration
isStaticGeneration
||
hasPostponed
?
generateFlight
(
ctx
)
?
generateFlight
(
ctx
)
.
then
((
renderResult
)
=>
renderResult
.
toUnchunkedString
(
true
))
.
then
((
renderResult
)
=>
renderResult
.
toUnchunkedString
(
true
))
.
catch
(()
=>
null
)
.
catch
(()
=>
null
)
:
Promise
.
resolve
(
null
)
:
Promise
.
resolve
(
null
)
// Get the nonce from the incoming request if it has one.
// Get the nonce from the incoming request if it has one.
const
csp
=
req
.
headers
[
'content-security-policy'
]
const
csp
=
req
.
headers
[
'content-security-policy'
]
...
...
test/production/standalone-mode/required-server-files/app/delayed/page.js
0 → 100644
View file @
ccd6c4b2
import
{
Suspense
}
from
'react'
import
{
cookies
}
from
'next/headers'
export
default
function
Page
()
{
return
(
<>
<
p
>
delayed
page
<
/p
>
<
Suspense
fallback
=
{
'loading 1...'
}
>
<
Time
/>
<
/Suspense
>
<
Suspense
fallback
=
{
'loading 2...'
}
>
<
Random
/>
<
/Suspense
>
<
/
>
)
}
async
function
Time
()
{
cookies
()
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
1000
))
return
<
p
id
=
"time"
>
{
Date
.
now
()}
<
/p
>
}
async
function
Random
()
{
cookies
()
await
new
Promise
((
resolve
)
=>
setTimeout
(
resolve
,
4000
))
return
<
p
id
=
"random"
>
{
Math
.
random
()}
<
/p
>
}
test/production/standalone-mode/required-server-files/required-server-files-ppr.test.ts
View file @
ccd6c4b2
...
@@ -15,6 +15,7 @@ describe('required server files app router', () => {
...
@@ -15,6 +15,7 @@ describe('required server files app router', () => {
let
next
:
NextInstance
let
next
:
NextInstance
let
server
let
server
let
appPort
let
appPort
let
delayedPostpone
const
setupNext
=
async
({
const
setupNext
=
async
({
nextEnv
,
nextEnv
,
...
@@ -50,6 +51,9 @@ describe('required server files app router', () => {
...
@@ -50,6 +51,9 @@ describe('required server files app router', () => {
})
})
await
next
.
stop
()
await
next
.
stop
()
delayedPostpone
=
(
await
next
.
readJSON
(
'.next/server/app/delayed.meta'
))
.
postponed
await
fs
.
move
(
await
fs
.
move
(
join
(
next
.
testDir
,
'.next/standalone'
),
join
(
next
.
testDir
,
'.next/standalone'
),
join
(
next
.
testDir
,
'standalone'
)
join
(
next
.
testDir
,
'standalone'
)
...
@@ -106,6 +110,37 @@ describe('required server files app router', () => {
...
@@ -106,6 +110,37 @@ describe('required server files app router', () => {
expect
(
next
.
cliOutput
).
not
.
toContain
(
'ERR_INVALID_URL'
)
expect
(
next
.
cliOutput
).
not
.
toContain
(
'ERR_INVALID_URL'
)
})
})
it
(
'should properly stream resume'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/delayed'
,
undefined
,
{
headers
:
{
'x-matched-path'
:
'/_next/postponed/resume/delayed'
,
},
method
:
'POST'
,
body
:
delayedPostpone
,
})
let
chunks
=
[]
for
await
(
const
chunk
of
res
.
body
)
{
chunks
.
push
({
time
:
Date
.
now
(),
chunk
:
chunk
.
toString
(),
})
}
const
firstSuspense
=
chunks
.
find
((
item
)
=>
item
.
chunk
.
includes
(
'time'
))
const
secondSuspense
=
chunks
.
find
((
item
)
=>
item
.
chunk
.
includes
(
'random'
))
console
.
log
({
firstSuspense
,
secondSuspense
,
})
expect
(
secondSuspense
.
time
-
firstSuspense
.
time
).
toBeGreaterThanOrEqual
(
2
*
1000
)
})
it
(
'should properly handle prerender for bot request'
,
async
()
=>
{
it
(
'should properly handle prerender for bot request'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/isr/first'
,
undefined
,
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/isr/first'
,
undefined
,
{
headers
:
{
headers
:
{
...
...
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