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
261614d9
Unverified
Commit
261614d9
authored
Dec 01, 2025
by
Sebastian "Sebbie" Silbermann
Committed by
GitHub
Dec 01, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[test] Deflake `app-dir-prevent-304-caching` (#86693)
parent
6eed9a05
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
4 deletions
+44
-4
base.ts
test/lib/next-modes/base.ts
+5
-0
next-start.ts
test/lib/next-modes/next-start.ts
+34
-0
index.test.ts
test/production/app-dir-prevent-304-caching/index.test.ts
+5
-4
No files found.
test/lib/next-modes/base.ts
View file @
261614d9
...
@@ -904,4 +904,9 @@ export class NextInstance {
...
@@ -904,4 +904,9 @@ export class NextInstance {
return
this
.
cliOutput
.
slice
(
length
)
return
this
.
cliOutput
.
slice
(
length
)
}
}
}
}
public
async
waitForMinPrerenderAge
(
minAgeMS
:
number
):
Promise
<
void
>
{
// For tests we usually have a low revalidate time.
// We assume the prerender is old enough by default for those small revalidation times.
}
}
}
test/lib/next-modes/next-start.ts
View file @
261614d9
...
@@ -10,6 +10,8 @@ export class NextStartInstance extends NextInstance {
...
@@ -10,6 +10,8 @@ export class NextStartInstance extends NextInstance {
private
_buildId
:
string
private
_buildId
:
string
private
_cliOutput
:
string
=
''
private
_cliOutput
:
string
=
''
private
_prerenderFinishedTimeMS
:
number
|
null
=
null
public
get
buildId
()
{
public
get
buildId
()
{
return
this
.
_buildId
return
this
.
_buildId
}
}
...
@@ -80,6 +82,16 @@ export class NextStartInstance extends NextInstance {
...
@@ -80,6 +82,16 @@ export class NextStartInstance extends NextInstance {
)
)
else
resolve
()
else
resolve
()
})
})
const
prerenderedCallback
=
(
msg
:
string
)
=>
{
const
colorStrippedMsg
=
stripAnsi
(
msg
)
// This stage happens after all prerenders have finished.
const
prerenderFinishedPattern
=
/Finalizing page optimization/
if
(
prerenderFinishedPattern
.
test
(
colorStrippedMsg
))
{
this
.
_prerenderFinishedTimeMS
=
performance
.
now
()
this
.
off
(
'stdout'
,
prerenderedCallback
)
}
}
this
.
on
(
'stdout'
,
prerenderedCallback
)
}
catch
(
err
)
{
}
catch
(
err
)
{
require
(
'console'
).
error
(
require
(
'console'
).
error
(
`Failed to run
${
shellQuote
(
buildArgs
)}
`
,
`Failed to run
${
shellQuote
(
buildArgs
)}
`
,
...
@@ -227,4 +239,26 @@ export class NextStartInstance extends NextInstance {
...
@@ -227,4 +239,26 @@ export class NextStartInstance extends NextInstance {
})
})
})
})
}
}
public
async
waitForMinPrerenderAge
(
minAgeMS
:
number
):
Promise
<
void
>
{
if
(
this
.
_prerenderFinishedTimeMS
===
null
)
{
throw
new
Error
(
'Could not determine when prerender finished. '
+
`Cannot guarantee a minimum prerender age of
${
minAgeMS
}
ms.`
)
}
const
prerenderAge
=
performance
.
now
()
-
this
.
_prerenderFinishedTimeMS
const
minWaitTime
=
minAgeMS
-
prerenderAge
if
(
minWaitTime
>
0
)
{
console
.
log
(
'Need to wait %dms to guarantee prerender age of %dms'
,
minWaitTime
,
minAgeMS
)
await
new
Promise
((
resolve
)
=>
{
setTimeout
(
resolve
,
minWaitTime
)
})
}
}
}
}
test/production/app-dir-prevent-304-caching/index.test.ts
View file @
261614d9
...
@@ -18,9 +18,10 @@ describe('app-dir-prevent-304-caching', () => {
...
@@ -18,9 +18,10 @@ describe('app-dir-prevent-304-caching', () => {
// https://github.com/vercel/next.js/issues/56580
// https://github.com/vercel/next.js/issues/56580
it
(
'should not cache 304 status'
,
async
()
=>
{
it
(
'should not cache 304 status'
,
async
()
=>
{
// Fresh call
// Ensure the first request hits a stale page triggering background revalidation.
const
rFresh
=
await
fetchViaHTTP
(
next
.
url
,
'/'
)
await
next
.
waitForMinPrerenderAge
(
1000
+
50
)
expect
(
rFresh
.
status
).
toBe
(
200
)
const
rStale
=
await
fetchViaHTTP
(
next
.
url
,
'/'
)
expect
(
rStale
.
status
).
toBe
(
200
)
await
waitFor
(
500
)
await
waitFor
(
500
)
...
@@ -31,7 +32,7 @@ describe('app-dir-prevent-304-caching', () => {
...
@@ -31,7 +32,7 @@ describe('app-dir-prevent-304-caching', () => {
{},
{},
{
{
headers
:
{
headers
:
{
'If-None-Match'
:
r
Fresh
.
headers
.
get
(
'etag'
),
'If-None-Match'
:
r
Stale
.
headers
.
get
(
'etag'
),
},
},
}
}
)
)
...
...
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