Skip to content

Commit 09959ff

Browse files
committed
remove handling for urlencoded actions
1 parent 668982a commit 09959ff

File tree

3 files changed

+21
-59
lines changed

3 files changed

+21
-59
lines changed

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

+12-45
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,6 @@ import { synchronizeMutableCookies } from '../async-storage/request-store'
4949
import type { TemporaryReferenceSet } from 'react-server-dom-webpack/server.edge'
5050
import { workUnitAsyncStorage } from '../app-render/work-unit-async-storage.external'
5151

52-
function formDataFromSearchQueryString(query: string) {
53-
const searchParams = new URLSearchParams(query)
54-
const formData = new FormData()
55-
for (const [key, value] of searchParams) {
56-
formData.append(key, value)
57-
}
58-
return formData
59-
}
60-
6152
function nodeHeadersToRecord(
6253
headers: IncomingHttpHeaders | OutgoingHttpHeaders
6354
) {
@@ -482,13 +473,8 @@ export async function handleAction({
482473
const contentType = req.headers['content-type']
483474
const { serverActionsManifest, page } = ctx.renderOpts
484475

485-
const {
486-
actionId,
487-
isURLEncodedAction,
488-
isMultipartAction,
489-
isFetchAction,
490-
isServerAction,
491-
} = getServerActionRequestMetadata(req)
476+
const { actionId, isMultipartAction, isFetchAction, isServerAction } =
477+
getServerActionRequestMetadata(req)
492478

493479
// If it's not a Server Action, skip handling.
494480
if (!isServerAction) {
@@ -726,21 +712,11 @@ export async function handleAction({
726712
}
727713

728714
const actionData = Buffer.concat(chunks).toString('utf-8')
729-
730-
if (isURLEncodedAction) {
731-
const formData = formDataFromSearchQueryString(actionData)
732-
boundActionArguments = await decodeReply(
733-
formData,
734-
serverModuleMap,
735-
{ temporaryReferences }
736-
)
737-
} else {
738-
boundActionArguments = await decodeReply(
739-
actionData,
740-
serverModuleMap,
741-
{ temporaryReferences }
742-
)
743-
}
715+
boundActionArguments = await decodeReply(
716+
actionData,
717+
serverModuleMap,
718+
{ temporaryReferences }
719+
)
744720
}
745721
} else if (
746722
// The type check here ensures that `req` is correctly typed, and the
@@ -882,20 +858,11 @@ export async function handleAction({
882858

883859
const actionData = Buffer.concat(chunks).toString('utf-8')
884860

885-
if (isURLEncodedAction) {
886-
const formData = formDataFromSearchQueryString(actionData)
887-
boundActionArguments = await decodeReply(
888-
formData,
889-
serverModuleMap,
890-
{ temporaryReferences }
891-
)
892-
} else {
893-
boundActionArguments = await decodeReply(
894-
actionData,
895-
serverModuleMap,
896-
{ temporaryReferences }
897-
)
898-
}
861+
boundActionArguments = await decodeReply(
862+
actionData,
863+
serverModuleMap,
864+
{ temporaryReferences }
865+
)
899866
}
900867
} else {
901868
throw new Error('Invariant: Unknown request type.')

Diff for: packages/next/src/server/lib/server-action-request-meta.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export function getServerActionRequestMetadata(
77
req: IncomingMessage | BaseNextRequest | NextRequest
88
): {
99
actionId: string | null
10-
isURLEncodedAction: boolean
1110
isMultipartAction: boolean
1211
isFetchAction: boolean
1312
isServerAction: boolean
@@ -23,9 +22,8 @@ export function getServerActionRequestMetadata(
2322
contentType = req.headers['content-type'] ?? null
2423
}
2524

26-
const isURLEncodedAction = Boolean(
27-
req.method === 'POST' && contentType === 'application/x-www-form-urlencoded'
28-
)
25+
// might be a no-js action or a fetch action that uses FormData.
26+
// we can't tell at this point, we need to run it through `decodeAction` to make sure.
2927
const isMultipartAction = Boolean(
3028
req.method === 'POST' && contentType?.startsWith('multipart/form-data')
3129
)
@@ -35,13 +33,10 @@ export function getServerActionRequestMetadata(
3533
req.method === 'POST'
3634
)
3735

38-
const isServerAction = Boolean(
39-
isFetchAction || isURLEncodedAction || isMultipartAction
40-
)
36+
const isServerAction = Boolean(isFetchAction || isMultipartAction)
4137

4238
return {
4339
actionId,
44-
isURLEncodedAction,
4540
isMultipartAction,
4641
isFetchAction,
4742
isServerAction,

Diff for: test/e2e/app-dir/actions/app-action.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -795,10 +795,10 @@ describe('app-dir action handling', () => {
795795
await next.fetch('/server', {
796796
method: 'POST',
797797
headers: {
798-
'content-type': 'application/x-www-form-urlencoded',
798+
'content-type': 'text/plain',
799799
'next-action': 'abc123',
800800
},
801-
body: 'foo=bar',
801+
body: '["foo","bar"]',
802802
})
803803

804804
await retry(async () =>
@@ -1627,7 +1627,7 @@ describe('app-dir action handling', () => {
16271627
})
16281628

16291629
describe('redirects', () => {
1630-
it('redirects properly when server action handler uses `redirect`', async () => {
1630+
it('redirects properly when route handler uses `redirect`', async () => {
16311631
const postRequests = []
16321632
const responseCodes = []
16331633

@@ -1656,12 +1656,12 @@ describe('app-dir action handling', () => {
16561656
expect(await browser.url()).toContain('success=true')
16571657
})
16581658

1659-
// verify that the POST request was only made to the action handler
1659+
// verify that the POST request was only made to the route handler
16601660
expect(postRequests).toEqual(['/redirects/api-redirect'])
16611661
expect(responseCodes).toEqual([303])
16621662
})
16631663

1664-
it('redirects properly when server action handler uses `permanentRedirect`', async () => {
1664+
it('redirects properly when route handler uses `permanentRedirect`', async () => {
16651665
const postRequests = []
16661666
const responseCodes = []
16671667

@@ -1689,7 +1689,7 @@ describe('app-dir action handling', () => {
16891689
await retry(async () => {
16901690
expect(await browser.url()).toContain('success=true')
16911691
})
1692-
// verify that the POST request was only made to the action handler
1692+
// verify that the POST request was only made to the route handler
16931693
expect(postRequests).toEqual(['/redirects/api-redirect-permanent'])
16941694
expect(responseCodes).toEqual([303])
16951695
})

0 commit comments

Comments
 (0)