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
d27cdc04
Unverified
Commit
d27cdc04
authored
Feb 08, 2025
by
Hendrik Liebau
Committed by
GitHub
Feb 08, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow `"use cache"` with `output: 'export'` (#75794)
parent
a181122a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
84 additions
and
4 deletions
+84
-4
index.ts
packages/next/src/export/index.ts
+13
-4
layout.tsx
test/e2e/app-dir/use-cache-output-export/app/layout.tsx
+8
-0
page.tsx
test/e2e/app-dir/use-cache-output-export/app/page.tsx
+9
-0
next.config.js
test/e2e/app-dir/use-cache-output-export/next.config.js
+11
-0
use-cache-output-export.test.ts
...r/use-cache-output-export/use-cache-output-export.test.ts
+43
-0
No files found.
packages/next/src/export/index.ts
View file @
d27cdc04
...
...
@@ -55,6 +55,8 @@ import { TurborepoAccessTraceResult } from '../build/turborepo-access-trace'
import
{
createProgress
}
from
'../build/progress'
import
type
{
DeepReadonly
}
from
'../shared/lib/deep-readonly'
import
{
isInterceptionRouteRewrite
}
from
'../lib/generate-interception-routes-rewrites'
import
type
{
ActionManifest
}
from
'../build/webpack/plugins/flight-client-entry-plugin'
import
{
extractInfoFromServerReferenceId
}
from
'../shared/lib/server-reference-info'
export
class
ExportError
extends
Error
{
code
=
'NEXT_EXPORT_ERROR'
...
...
@@ -300,11 +302,11 @@ async function exportAppImpl(
}
}
let
serverActionsManifest
let
serverActionsManifest
:
ActionManifest
|
undefined
if
(
enabledDirectories
.
app
)
{
serverActionsManifest
=
require
(
join
(
distDir
,
SERVER_DIRECTORY
,
SERVER_REFERENCE_MANIFEST
+
'.json'
)
)
)
as
ActionManifest
if
(
nextConfig
.
output
===
'export'
)
{
const
routesManifest
=
require
(
join
(
distDir
,
ROUTES_MANIFEST
))
...
...
@@ -322,9 +324,16 @@ async function exportAppImpl(
}
}
const
actionIds
=
[
...
Object
.
keys
(
serverActionsManifest
.
node
),
...
Object
.
keys
(
serverActionsManifest
.
edge
),
]
if
(
Object
.
keys
(
serverActionsManifest
.
node
).
length
>
0
||
Object
.
keys
(
serverActionsManifest
.
edge
).
length
>
0
actionIds
.
some
(
(
actionId
)
=>
extractInfoFromServerReferenceId
(
actionId
).
type
===
'server-action'
)
)
{
throw
new
ExportError
(
`Server Actions are not supported with static export.\nRead more: https://nextjs.org/docs/app/building-your-application/deploying/static-exports#unsupported-features`
...
...
test/e2e/app-dir/use-cache-output-export/app/layout.tsx
0 → 100644
View file @
d27cdc04
import
{
ReactNode
}
from
'react'
export
default
function
Root
({
children
}:
{
children
:
ReactNode
})
{
return
(
<
html
>
<
body
>
{
children
}
</
body
>
</
html
>
)
}
test/e2e/app-dir/use-cache-output-export/app/page.tsx
0 → 100644
View file @
d27cdc04
'use cache'
export
default
async
function
Page
()
{
const
data
=
await
fetch
(
'https://next-data-api-endpoint.vercel.app/api/random'
).
then
((
response
)
=>
response
.
text
())
return
<
p
>
{
data
}
</
p
>
}
test/e2e/app-dir/use-cache-output-export/next.config.js
0 → 100644
View file @
d27cdc04
/**
* @type {import('next').NextConfig}
*/
const
nextConfig
=
{
experimental
:
{
useCache
:
true
,
},
output
:
'export'
,
}
module
.
exports
=
nextConfig
test/e2e/app-dir/use-cache-output-export/use-cache-output-export.test.ts
0 → 100644
View file @
d27cdc04
import
{
nextTestSetup
}
from
'e2e-utils'
import
{
renderViaHTTP
,
startCleanStaticServer
}
from
'next-test-utils'
import
{
join
}
from
'path'
import
{
AddressInfo
,
Server
}
from
'net'
describe
(
'use-cache-output-export'
,
()
=>
{
const
{
next
,
isNextStart
}
=
nextTestSetup
({
files
:
__dirname
,
skipDeployment
:
true
,
skipStart
:
process
.
env
.
NEXT_TEST_MODE
!==
'dev'
,
})
if
(
process
.
env
.
__NEXT_EXPERIMENTAL_PPR
===
'true'
)
{
return
it
.
skip
(
'for PPR'
,
()
=>
{
// PPR is not compatible with `output: 'export'`.
})
}
it
(
'should work'
,
async
()
=>
{
let
html
:
string
let
server
:
Server
|
undefined
if
(
isNextStart
)
{
const
{
cliOutput
}
=
await
next
.
build
()
expect
(
cliOutput
).
not
.
toInclude
(
'Server Actions are not supported with static export.'
)
server
=
await
startCleanStaticServer
(
join
(
next
.
testDir
,
'out'
))
const
{
port
}
=
server
.
address
()
as
AddressInfo
html
=
await
renderViaHTTP
(
port
,
'/'
)
}
else
{
html
=
await
next
.
render
(
'/'
)
}
expect
(
html
).
toMatch
(
/<p>
[
0,1
]\.\d
+<
\/
p>/
)
if
(
server
)
{
await
new
Promise
((
resolve
)
=>
server
.
close
(
resolve
))
}
})
})
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