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
14842ac7
Commit
14842ac7
authored
Apr 10, 2026
by
Jimmy Lai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cover flat export fallbacks and fix resume path
parent
f26ce518
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
407 additions
and
3 deletions
+407
-3
output-export-fallback.test.ts
packages/next/src/client/output-export-fallback.test.ts
+18
-0
output-export-fallback.ts
packages/next/src/client/output-export-fallback.ts
+2
-2
node-web-streams-helper.ts
...s/next/src/server/stream-utils/node-web-streams-helper.ts
+1
-1
dynamic-fallback-cache-components-flat.test.ts
...xport/test/dynamic-fallback-cache-components-flat.test.ts
+288
-0
dynamic-fallback-cache-components.test.ts
...dir-export/test/dynamic-fallback-cache-components.test.ts
+62
-0
dynamic-fallback-known-params-cache-components.test.ts
...st/dynamic-fallback-known-params-cache-components.test.ts
+36
-0
No files found.
packages/next/src/client/output-export-fallback.test.ts
View file @
14842ac7
...
...
@@ -3,6 +3,7 @@ import {
fetchOutputExportDataResponse
,
fetchOutputExportFallbackResponse
,
getOutputExportFallbackCandidates
,
stripOutputExportDataSuffix
,
}
from
'./output-export-fallback'
describe
(
'output export fallback helpers'
,
()
=>
{
...
...
@@ -40,6 +41,23 @@ describe('output export fallback helpers', () => {
).
toBe
(
'https://example.com/blog/post/index.txt'
)
})
it
(
'strips the export data suffix back to the fallback document path'
,
()
=>
{
expect
(
stripOutputExportDataSuffix
(
new
URL
(
'https://example.com/blog/post/index.txt'
)
).
href
).
toBe
(
'https://example.com/blog/post'
)
expect
(
stripOutputExportDataSuffix
(
new
URL
(
'https://example.com/blog/post.txt'
))
.
href
).
toBe
(
'https://example.com/blog/post.html'
)
expect
(
stripOutputExportDataSuffix
(
new
URL
(
'https://example.com/index.txt'
)).
href
).
toBe
(
'https://example.com/'
)
})
it
(
'tries both flat and trailing-slash data files'
,
async
()
=>
{
const
fetchMock
=
jest
.
fn
(
async
(
input
:
RequestInfo
|
URL
)
=>
{
const
url
=
String
(
input
)
...
...
packages/next/src/client/output-export-fallback.ts
View file @
14842ac7
...
...
@@ -28,9 +28,9 @@ export function addOutputExportDataSuffix(url: URL): URL {
export
function
stripOutputExportDataSuffix
(
url
:
URL
):
URL
{
const
nextUrl
=
new
URL
(
url
)
if
(
nextUrl
.
pathname
.
endsWith
(
'/index.txt'
))
{
nextUrl
.
pathname
=
nextUrl
.
pathname
.
slice
(
0
,
-
9
)
nextUrl
.
pathname
=
nextUrl
.
pathname
.
slice
(
0
,
-
10
)
||
'/'
}
else
if
(
nextUrl
.
pathname
.
endsWith
(
'.txt'
))
{
nextUrl
.
pathname
=
nextUrl
.
pathname
.
slice
(
0
,
-
4
)
nextUrl
.
pathname
=
`
${
nextUrl
.
pathname
.
slice
(
0
,
-
4
)}
.html`
}
return
nextUrl
}
...
...
packages/next/src/server/stream-utils/node-web-streams-helper.ts
View file @
14842ac7
...
...
@@ -535,7 +535,7 @@ function createClientResumeScriptInsertionTransformStream(): TransformStream<
undefined
// headers[NEXT_URL]
)
const
searchStr
=
`
${
NEXT_RSC_UNION_QUERY
}
=
${
cacheBustingHeader
}
`
const
NEXT_CLIENT_RESUME_SCRIPT
=
`<script>try{var u=sessionStorage.getItem('
${
originalUrlSessionKey
}
');var r=location.pathname;if(u){r=r.endsWith('/')?r+'index.txt':r+'.txt'}__NEXT_CLIENT_RESUME=fetch(r+'?
${
searchStr
}
',{credentials:'same-origin',headers:{'
${
RSC_HEADER
}
': '1','
${
NEXT_ROUTER_PREFETCH_HEADER
}
': '1','
${
NEXT_ROUTER_SEGMENT_PREFETCH_HEADER
}
': '
${
segmentPath
}
'}});if(u){window.
${
originalUrlGlobalKey
}
=u;history.replaceState(null,'',u);sessionStorage.removeItem('
${
originalUrlSessionKey
}
')}}catch{}</script>`
const
NEXT_CLIENT_RESUME_SCRIPT
=
`<script>try{var u=sessionStorage.getItem('
${
originalUrlSessionKey
}
');var r=location.pathname;if(u){r=r.endsWith('
.html')?r.slice(0,-5)+'.txt':r.endsWith('
/')?r+'index.txt':r+'.txt'}__NEXT_CLIENT_RESUME=fetch(r+'?
${
searchStr
}
',{credentials:'same-origin',headers:{'
${
RSC_HEADER
}
': '1','
${
NEXT_ROUTER_PREFETCH_HEADER
}
': '1','
${
NEXT_ROUTER_SEGMENT_PREFETCH_HEADER
}
': '
${
segmentPath
}
'}});if(u){window.
${
originalUrlGlobalKey
}
=u;history.replaceState(null,'',u);sessionStorage.removeItem('
${
originalUrlSessionKey
}
')}}catch{}</script>`
let
didAlreadyInsert
=
false
return
new
TransformStream
({
...
...
test/e2e/app-dir-export/test/dynamic-fallback-cache-components-flat.test.ts
0 → 100644
View file @
14842ac7
import
{
join
}
from
'path'
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
findPort
,
retry
,
stopApp
}
from
'next-test-utils'
import
webdriver
from
'next-webdriver'
import
fs
from
'fs-extra'
import
express
from
'express'
import
http
from
'http'
import
{
createReadStream
}
from
'fs'
const
{
next
,
skipped
,
isNextDev
}
=
nextTestSetup
({
files
:
join
(
__dirname
,
'..'
),
skipDeployment
:
true
,
skipStart
:
true
,
disableAutoSkewProtection
:
true
,
})
if
(
skipped
)
{
describe
.
skip
(
'app dir - output export dynamic routes with Cache Components without trailing slashes'
,
()
=>
{})
}
else
{
const
describeProduction
=
isNextDev
?
describe
.
skip
:
describe
describeProduction
(
'app dir - output export dynamic routes with Cache Components without trailing slashes'
,
()
=>
{
let
port
:
number
let
stopOrKill
:
(()
=>
Promise
<
void
>
)
|
undefined
beforeAll
(
async
()
=>
{
await
next
.
patchFile
(
'next.config.js'
,
(
content
)
=>
content
.
replace
(
'trailingSlash: true,'
,
`trailingSlash: false,
cacheComponents: true,`
)
)
await
next
.
patchFile
(
'app/another/[slug]/slug-client.js'
,
`'use client'
import { useParams } from 'next/navigation'
export default function SlugClient() {
const params = useParams()
return <h1>{params.slug}</h1>
}
`
)
await
next
.
patchFile
(
'app/another/[slug]/page.js'
,
()
=>
`import Link from 'next/link'
import { Suspense } from 'react'
import SlugClient from './slug-client'
export default function Page() {
return (
<main>
<Suspense fallback={<h1>Loading slug...</h1>}>
<SlugClient />
</Suspense>
<ul>
<li>
<Link href="/another">Visit another page</Link>
</li>
<li>
<Link href="/org/acme/chat/thread-flat">Visit org thread</Link>
</li>
</ul>
</main>
)
}
`
)
await
next
.
patchFile
(
'app/org/page.js'
,
`import Link from 'next/link'
export default function OrgIndexPage() {
return (
<main>
<h1>Org index</h1>
<ul>
<li>
<Link href="/org/acme/chat/thread-123">Visit org chat thread 123</Link>
</li>
</ul>
</main>
)
}
`
)
await
next
.
patchFile
(
'app/org/[org]/org-client.js'
,
`'use client'
import { useParams } from 'next/navigation'
export default function OrgClient() {
const params = useParams()
return <p id="org-name">Org {params.org}</p>
}
`
)
await
next
.
patchFile
(
'app/org/[org]/layout.js'
,
`import { Suspense } from 'react'
import OrgClient from './org-client'
export default function OrgLayout({ children }) {
return (
<main>
<Suspense fallback={<p id="org-name">Loading org...</p>}>
<OrgClient />
</Suspense>
{children}
</main>
)
}
`
)
await
next
.
patchFile
(
'app/org/[org]/chat/[thread]/thread-client.js'
,
`'use client'
import { useParams } from 'next/navigation'
export default function OrgThreadClient() {
const params = useParams()
return <h1>{params.org}:{params.thread}</h1>
}
`
)
await
next
.
patchFile
(
'app/org/[org]/chat/[thread]/page.js'
,
`import Link from 'next/link'
import { Suspense } from 'react'
import OrgThreadClient from './thread-client'
export default function OrgThreadPage() {
return (
<>
<Suspense fallback={<h1>Loading org thread...</h1>}>
<OrgThreadClient />
</Suspense>
<ul>
<li>
<Link href="/org">Visit org index</Link>
</li>
</ul>
</>
)
}
`
)
await
next
.
deleteFile
(
'app/api/json/route.js'
)
await
next
.
deleteFile
(
'app/api/txt/route.js'
)
await
next
.
patchFile
(
'app/another/page.js'
,
(
content
)
=>
content
.
replace
(
` <li>
<Link href="/image-import">image import page</Link>
</li>`
,
` <li>
<Link href="/another/third">another third page</Link>
</li>
<li>
<Link href="/image-import">image import page</Link>
</li>`
)
)
await
next
.
build
()
port
=
await
findPort
()
const
app
=
express
()
const
server
=
http
.
createServer
(
app
)
const
outDir
=
join
(
next
.
testDir
,
'out'
)
const
fallbackHtml
=
join
(
outDir
,
'_fallback.html'
)
app
.
use
(
express
.
static
(
outDir
,
{
extensions
:
[
'html'
],
redirect
:
false
,
})
)
app
.
use
((
req
,
res
)
=>
{
createReadStream
(
fallbackHtml
).
pipe
(
res
)
})
await
new
Promise
<
void
>
((
resolve
)
=>
server
.
listen
(
port
,
resolve
))
stopOrKill
=
()
=>
stopApp
(
server
)
})
afterAll
(
async
()
=>
{
if
(
stopOrKill
)
{
await
stopOrKill
()
}
await
next
.
destroy
()
})
it
(
'writes flat fallback artifacts for trailingSlash false'
,
async
()
=>
{
const
outDir
=
join
(
next
.
testDir
,
'out'
)
expect
(
await
fs
.
pathExists
(
join
(
outDir
,
'_fallback.html'
))).
toBe
(
true
)
expect
(
await
fs
.
pathExists
(
join
(
outDir
,
'another'
,
'__fallback.html'
))
).
toBe
(
true
)
expect
(
await
fs
.
pathExists
(
join
(
outDir
,
'another'
,
'__fallback.txt'
))
).
toBe
(
true
)
expect
(
await
fs
.
pathExists
(
join
(
outDir
,
'org'
,
'__fallback.txt'
))).
toBe
(
true
)
expect
(
await
fs
.
pathExists
(
join
(
outDir
,
'another'
,
'__fallback'
,
'index.html'
)
)
).
toBe
(
false
)
})
it
(
'renders an unenumerated slug on hard load and client navigation without adding a trailing slash'
,
async
()
=>
{
const
browser
=
await
webdriver
(
port
,
'/another/third'
)
try
{
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'third'
)
expect
(
await
browser
.
eval
(
'window.location.pathname'
)).
toBe
(
'/another/third'
)
})
await
browser
.
elementByCss
(
'a[href="/another"]'
).
click
()
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'Another'
)
expect
(
await
browser
.
eval
(
'window.location.pathname'
)).
toBe
(
'/another'
)
})
await
browser
.
elementByCss
(
'a[href="/another/third"]'
).
click
()
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'third'
)
expect
(
await
browser
.
eval
(
'window.location.pathname'
)).
toBe
(
'/another/third'
)
})
}
finally
{
await
browser
.
close
()
}
})
it
(
'preserves search params and hash for nested fallback routes without trailing slashes'
,
async
()
=>
{
const
browser
=
await
webdriver
(
port
,
'/org/umbrella/chat/thread-flat?view=full#messages'
)
try
{
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'#org-name'
).
text
()).
toBe
(
'Org umbrella'
)
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'umbrella:thread-flat'
)
expect
(
await
browser
.
eval
(
'window.location.pathname + window.location.search + window.location.hash'
)
).
toBe
(
'/org/umbrella/chat/thread-flat?view=full#messages'
)
})
}
finally
{
await
browser
.
close
()
}
})
}
)
}
test/e2e/app-dir-export/test/dynamic-fallback-cache-components.test.ts
View file @
14842ac7
...
...
@@ -790,6 +790,68 @@ export default function OrgThreadPage() {
}
})
it
(
'preserves search params and hash across fallback hard loads'
,
async
()
=>
{
const
browser
=
await
webdriver
(
port
,
'/another/query-param/?tab=notes#anchor'
)
try
{
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'query-param'
)
expect
(
await
browser
.
eval
(
'window.location.pathname + window.location.search + window.location.hash'
)
).
toBe
(
'/another/query-param/?tab=notes#anchor'
)
})
}
finally
{
await
browser
.
close
()
}
})
it
(
'supports a longer history sequence across static and fallback routes'
,
async
()
=>
{
const
browser
=
await
webdriver
(
port
,
'/another/history-one/'
)
try
{
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'history-one'
)
})
await
browser
.
elementByCss
(
'a[href="/another/"]'
).
click
()
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'Another'
)
})
await
browser
.
elementByCss
(
'a[href="/another/third/"]'
).
click
()
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'third'
)
})
await
browser
.
back
()
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'Another'
)
})
await
browser
.
back
()
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'history-one'
)
})
await
browser
.
forward
()
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'Another'
)
})
await
browser
.
forward
()
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'third'
)
})
}
finally
{
await
browser
.
close
()
}
})
it
(
'shows Suspense fallback UI during hard load of a fallback route'
,
async
()
=>
{
const
browser
=
await
webdriver
(
port
,
'/another/suspense-test/'
)
...
...
test/e2e/app-dir-export/test/dynamic-fallback-known-params-cache-components.test.ts
View file @
14842ac7
...
...
@@ -391,6 +391,42 @@ export default function OrgThreadPage() {
await
browser
.
close
()
}
})
it
(
'preserves history across prerendered and fallback routes with search params'
,
async
()
=>
{
const
browser
=
await
webdriver
(
port
,
'/another/first/?mode=known'
)
try
{
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'first'
)
expect
(
await
browser
.
eval
(
'window.location.search'
)).
toBe
(
'?mode=known'
)
})
await
browser
.
elementByCss
(
'a[href="/another/third/"]'
).
click
()
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'third'
)
expect
(
await
browser
.
eval
(
'window.location.pathname'
)).
toBe
(
'/another/third/'
)
})
await
browser
.
back
()
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'first'
)
expect
(
await
browser
.
eval
(
'window.location.search'
)).
toBe
(
'?mode=known'
)
})
await
browser
.
forward
()
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'h1'
).
text
()).
toBe
(
'third'
)
})
}
finally
{
await
browser
.
close
()
}
})
}
)
}
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