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
95adcd37
Commit
95adcd37
authored
Sep 22, 2025
by
Janka Uryga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tests
parent
9cf9183e
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
252 additions
and
0 deletions
+252
-0
layout.tsx
test/e2e/app-dir/async-server-references/app/layout.tsx
+16
-0
page.tsx
...e2e/app-dir/async-server-references/app/prefetch/page.tsx
+14
-0
async-module-with-actions.ts
...ces/app/prefetch/target-page/async-module-with-actions.ts
+7
-0
page.tsx
...async-server-references/app/prefetch/target-page/page.tsx
+12
-0
async-module-with-actions.ts
...-server-references/app/reply/async-module-with-actions.ts
+18
-0
client.tsx
.../e2e/app-dir/async-server-references/app/reply/client.tsx
+26
-0
page.tsx
test/e2e/app-dir/async-server-references/app/reply/page.tsx
+5
-0
async-module-with-actions.ts
...ver-references/app/use-cache/async-module-with-actions.ts
+10
-0
page.tsx
...2e/app-dir/async-server-references/app/use-cache/page.tsx
+24
-0
page.tsx
...-server-references/app/use-cache/redirect-target/page.tsx
+3
-0
async-server-references.test.ts
...r/async-server-references/async-server-references.test.ts
+74
-0
link-accordion.tsx
...dir/async-server-references/components/link-accordion.tsx
+33
-0
next.config.ts
test/e2e/app-dir/async-server-references/next.config.ts
+10
-0
No files found.
test/e2e/app-dir/async-server-references/app/layout.tsx
0 → 100644
View file @
95adcd37
export
const
metadata
=
{
title
:
'Next.js'
,
description
:
'Generated by Next.js'
,
}
export
default
function
RootLayout
({
children
,
}:
{
children
:
React
.
ReactNode
})
{
return
(
<
html
lang=
"en"
>
<
body
>
{
children
}
</
body
>
</
html
>
)
}
test/e2e/app-dir/async-server-references/app/prefetch/page.tsx
0 → 100644
View file @
95adcd37
import
{
LinkAccordion
}
from
'../../components/link-accordion'
export
default
async
function
Page
()
{
return
(
<
main
>
<
h1
>
A page that links to another page which uses an async server reference
</
h1
>
<
LinkAccordion
href=
"/prefetch/target-page"
>
/prefetch/target-page
</
LinkAccordion
>
</
main
>
)
}
test/e2e/app-dir/async-server-references/app/prefetch/target-page/async-module-with-actions.ts
0 → 100644
View file @
95adcd37
'use server'
await
Promise
.
resolve
()
// make this an async module
export
async
function
action
()
{
console
.
log
(
'hello from the server!'
)
}
test/e2e/app-dir/async-server-references/app/prefetch/target-page/page.tsx
0 → 100644
View file @
95adcd37
import
{
action
}
from
'./async-module-with-actions'
export
default
async
function
Page
()
{
return
(
<
main
id=
"target-page"
>
<
h1
>
A page that uses an async server reference
</
h1
>
<
form
action=
{
action
}
>
<
button
type=
"submit"
>
Submit
</
button
>
</
form
>
</
main
>
)
}
test/e2e/app-dir/async-server-references/app/reply/async-module-with-actions.ts
0 → 100644
View file @
95adcd37
'use server'
await
Promise
.
resolve
()
// make this an async module
const
EXPECTED_VALUE
=
1
export
async
function
runActionFromArgument
(
action
:
()
=>
Promise
<
number
>
)
{
console
.
log
(
'runActionFromArgument :: running action:'
,
action
)
const
result
=
await
action
()
if
(
result
!==
EXPECTED_VALUE
)
{
throw
new
Error
(
`Action did not return
${
EXPECTED_VALUE
}
`
)
}
}
export
async
function
myAction
():
Promise
<
1
>
{
console
.
log
(
'hello from the server!'
)
return
EXPECTED_VALUE
}
test/e2e/app-dir/async-server-references/app/reply/client.tsx
0 → 100644
View file @
95adcd37
'use client'
import
{
useActionState
}
from
'react'
import
{
runActionFromArgument
,
myAction
}
from
'./async-module-with-actions'
export
function
Client
()
{
const
[
state
,
dispatch
,
isPending
]
=
useActionState
(
async
()
=>
{
try
{
// This will execute the action passsed as an argument,
// and throw if something goes wrong.
await
runActionFromArgument
(
myAction
)
return
'ok'
}
catch
(
err
)
{
return
'error'
}
},
null
)
return
(
<
div
>
<
form
action=
{
dispatch
}
>
<
button
type=
"submit"
>
Submit
</
button
>
</
form
>
{
isPending
?
'Submitting...'
:
state
!==
null
&&
<
div
id=
"action-result"
>
{
state
}
</
div
>
}
</
div
>
)
}
test/e2e/app-dir/async-server-references/app/reply/page.tsx
0 → 100644
View file @
95adcd37
import
{
Client
}
from
'./client'
export
default
function
Page
()
{
return
<
Client
/>
}
test/e2e/app-dir/async-server-references/app/use-cache/async-module-with-actions.ts
0 → 100644
View file @
95adcd37
'use server'
import
{
redirect
}
from
'next/navigation'
await
Promise
.
resolve
()
// make this an async module
export
async
function
action
()
{
console
.
log
(
'hello from server! redirecting...'
)
redirect
(
'/use-cache/redirect-target'
)
}
test/e2e/app-dir/async-server-references/app/use-cache/page.tsx
0 → 100644
View file @
95adcd37
import
{
action
}
from
'./async-module-with-actions'
export
default
async
function
Page
()
{
return
(
<
main
>
<
h1
>
A page that uses a cached component whose result contains an async
server reference
</
h1
>
<
Cached
/>
</
main
>
)
}
async
function
Cached
()
{
'use cache'
// 'use cache' decodes and re-encodes RSC data on the server,
// so it can break if async references are not resolved correctly.
return
(
<
form
action=
{
action
}
>
<
button
type=
"submit"
>
Submit
</
button
>
</
form
>
)
}
test/e2e/app-dir/async-server-references/app/use-cache/redirect-target/page.tsx
0 → 100644
View file @
95adcd37
export
default
function
Page
()
{
return
<
main
id=
"redirect-target"
>
This page is a redirect target.
</
main
>
}
test/e2e/app-dir/async-server-references/async-server-references.test.ts
0 → 100644
View file @
95adcd37
import
{
nextTestSetup
}
from
'../../../lib/e2e-utils'
import
{
retry
}
from
'../../../lib/next-test-utils'
import
{
createRouterAct
}
from
'../segment-cache/router-act'
describe
(
'async server references'
,
()
=>
{
const
{
next
,
isNextDev
}
=
nextTestSetup
({
files
:
__dirname
,
})
// There's no prefetching in dev.
if
(
!
isNextDev
)
{
it
(
'does not crash when navigating with a prefetch'
,
async
()
=>
{
// This is reproducing a production error that happened with `clientSegmentCache`.
// When building the segments used by clientSegmentCache,
// we'd decode the action incorrectly, which resulted in an error being thrown inside the render.
// The error would be encoded in the RSC payload, and then thrown on the client
// when the prefetched segment was rendered during a navigation.
let
act
:
ReturnType
<
typeof
createRouterAct
>
const
browser
=
await
next
.
browser
(
'/prefetch'
,
{
beforePageLoad
(
page
)
{
act
=
createRouterAct
(
page
)
},
})
// Reveal the link to trigger a prefetch.
await
act
(
async
()
=>
{
await
browser
.
elementByCss
(
'[data-link-accordion="/prefetch/target-page"]'
)
.
click
()
},
[{
includes
:
'A page that uses an async server reference'
}])
// Navigate to the prefetched page.
await
browser
.
elementByCss
(
'a[href="/prefetch/target-page"]'
).
click
()
// We expect the navigation to not crash with "Application error: a client-side exception has occurred"
// (like it did when the bug was observed) to and display the target content.
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'main#target-page'
).
text
()).
toContain
(
'A page that uses an async server reference'
)
})
})
}
it
(
'decodes async server references from a action reply correctly'
,
async
()
=>
{
const
browser
=
await
next
.
browser
(
'/reply'
)
await
browser
.
elementByCss
(
'button[type="submit"]'
).
click
()
await
retry
(
async
()
=>
{
// If the action crashes during execution (due to incorrect argument decoding)
// Or returns the wrong value (indicating that it was resolved incorrectly),
// the form status will be "error".
// If everything works correctly, it'll be "ok".
expect
(
await
browser
.
elementByCss
(
'#action-result'
).
text
()).
toBe
(
'ok'
)
})
})
it
(
'correctly serializes and decodes async server references in cache functions'
,
async
()
=>
{
// 'use cache' decodes and re-encodes RSC data on the server,
// so it can break if async references are not resolved correctly.
// Incorrect decoding of async server references was causing it to crash during build,
// so if we built successfully, we know that it works at least partially.
// We should still verify that the server action works as expected.
const
browser
=
await
next
.
browser
(
'/use-cache'
)
// The page should display, and the action used in the cached component should work,
// triggering a redirect when executed.
await
browser
.
elementByCss
(
'button[type="submit"]'
).
click
()
await
retry
(
async
()
=>
{
expect
(
await
browser
.
elementByCss
(
'main#redirect-target'
).
text
()
).
toBeTruthy
()
})
})
})
test/e2e/app-dir/async-server-references/components/link-accordion.tsx
0 → 100644
View file @
95adcd37
'use client'
import
Link
,
{
type
LinkProps
}
from
'next/link'
import
{
useState
}
from
'react'
export
function
LinkAccordion
({
href
,
children
,
prefetch
,
}:
{
href
:
string
children
:
React
.
ReactNode
prefetch
?:
LinkProps
[
'prefetch'
]
})
{
const
[
isVisible
,
setIsVisible
]
=
useState
(
false
)
return
(
<>
<
input
type=
"checkbox"
checked=
{
isVisible
}
onChange=
{
()
=>
setIsVisible
(
!
isVisible
)
}
data
-
link
-
accordion=
{
href
}
/>
{
isVisible
?
(
<
Link
href=
{
href
}
prefetch=
{
prefetch
}
>
{
children
}
</
Link
>
)
:
(
<>
{
children
}
(link is hidden)
</>
)
}
</>
)
}
test/e2e/app-dir/async-server-references/next.config.ts
0 → 100644
View file @
95adcd37
import
type
{
NextConfig
}
from
'next'
const
nextConfig
:
NextConfig
=
{
experimental
:
{
useCache
:
true
,
clientSegmentCache
:
true
,
},
}
export
default
nextConfig
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