Skip to content

Commit 1c007be

Browse files
committed
no more returning undefined
1 parent 32ef719 commit 1c007be

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

Diff for: packages/next/src/server/app-render/action-handler.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ export async function handleAction({
482482
requestStore: RequestStore
483483
serverActions?: ServerActionsConfig
484484
ctx: AppRenderContext
485-
}): Promise<undefined | HandleActionResult> {
485+
}): Promise<HandleActionResult> {
486486
const contentType = req.headers['content-type']
487487
const { serverActionsManifest, page } = ctx.renderOpts
488488

@@ -498,7 +498,7 @@ export async function handleAction({
498498
// Note that this can be a false positive -- any multipart/urlencoded POST can get us here,
499499
// But won't know if it's a no-js action or not until we call `decodeAction` below.
500500
if (!isPotentialServerAction) {
501-
return
501+
return { type: 'not-an-action' }
502502
}
503503

504504
if (workStore.isStaticGeneration) {

Diff for: packages/next/src/server/app-render/app-render.tsx

+22-25
Original file line numberDiff line numberDiff line change
@@ -1518,33 +1518,30 @@ async function renderToHTMLOrFlightImpl(
15181518
ctx,
15191519
})
15201520

1521-
if (actionRequestResult) {
1522-
if (actionRequestResult.type === 'not-found') {
1523-
const notFoundLoaderTree = createNotFoundLoaderTree(loaderTree)
1524-
res.statusCode = 404
1525-
const stream = await renderToStreamWithTracing(
1526-
requestStore,
1527-
req,
1528-
res,
1529-
ctx,
1530-
workStore,
1531-
notFoundLoaderTree,
1532-
formState,
1533-
postponedState
1534-
)
1521+
if (actionRequestResult.type === 'not-found') {
1522+
const notFoundLoaderTree = createNotFoundLoaderTree(loaderTree)
1523+
res.statusCode = 404
1524+
const stream = await renderToStreamWithTracing(
1525+
requestStore,
1526+
req,
1527+
res,
1528+
ctx,
1529+
workStore,
1530+
notFoundLoaderTree,
1531+
formState,
1532+
postponedState
1533+
)
15351534

1536-
return new RenderResult(stream, { metadata })
1537-
} else if (actionRequestResult.type === 'done') {
1538-
if (actionRequestResult.result) {
1539-
actionRequestResult.result.assignMetadata(metadata)
1540-
return actionRequestResult.result
1541-
} else if (actionRequestResult.formState) {
1542-
formState = actionRequestResult.formState
1543-
}
1544-
} else if (actionRequestResult.type === 'not-an-action') {
1545-
// TODO: previously, these would be a 'done' with no `result` and no `formState`,
1546-
// so they'd fall through the branch above. Why does that work?
1535+
return new RenderResult(stream, { metadata })
1536+
} else if (actionRequestResult.type === 'done') {
1537+
if (actionRequestResult.result) {
1538+
actionRequestResult.result.assignMetadata(metadata)
1539+
return actionRequestResult.result
1540+
} else if (actionRequestResult.formState) {
1541+
formState = actionRequestResult.formState
15471542
}
1543+
} else if (actionRequestResult.type === 'not-an-action') {
1544+
// nothing to do here.
15481545
}
15491546
}
15501547

0 commit comments

Comments
 (0)