Unverified Commit 7425d511 authored by Josh Story's avatar Josh Story Committed by GitHub

Fix ServerAction rejection reason (#63744)

Recently the serverActionReducer was updated to no longer use React's
thenable type to carry resolution/rejection information. However the
rejection reason was not updated so now when a server action fails we
were rejecting with `undefined` rather than the rejected reason. This
change updates the reject to use the rejection value.


Closes NEXT-2943
parent 2fc408d6
...@@ -269,7 +269,7 @@ export function serverActionReducer( ...@@ -269,7 +269,7 @@ export function serverActionReducer(
}, },
(e: any) => { (e: any) => {
// When the server action is rejected we don't update the state and instead call the reject handler of the promise. // When the server action is rejected we don't update the state and instead call the reject handler of the promise.
reject(e.reason) reject(e)
return state return state
} }
......
...@@ -39,6 +39,23 @@ createNextDescribe( ...@@ -39,6 +39,23 @@ createNextDescribe(
await check(() => browser.elementById('count').text(), '3') await check(() => browser.elementById('count').text(), '3')
}) })
it('should report errors with bad inputs correctly', async () => {
const browser = await next.browser('/error-handling', {
pushErrorAsConsoleLog: true,
})
await browser.elementByCss('#submit').click()
const logs = await browser.log()
expect(
logs.some((log) =>
log.message.includes(
'Only plain objects, and a few built-ins, can be passed to Server Actions. Classes or null prototypes are not supported.'
)
)
).toBe(true)
})
it('should support headers and cookies', async () => { it('should support headers and cookies', async () => {
const browser = await next.browser('/header') const browser = await next.browser('/header')
......
'use server'
export async function action() {
return 'action result'
}
'use client'
import { action } from './actions'
export default function Page() {
return (
<main>
<p>
This button will call a server action and pass something unserializable
like a class instance. We expect this action to error with a reasonable
message explaning what happened
</p>
<button
id="submit"
onClick={async () => {
await action(new Foo())
}}
>
Submit
</button>
</main>
)
}
class Foo {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment