You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .changeset/raw-payload-submission.md
+46-10Lines changed: 46 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -2,21 +2,45 @@
2
2
"react-router-dom": minor
3
3
---
4
4
5
-
- Support submission of raw payloads through `useSubmit`/`fetcher.submit` by opting out of serialization into `request.formData` using `encType: null`. When opting-out of serialization, your data will be passed to the action in a new `payload` parameter:
5
+
- Support better submission and control of serialization of raw payloads through `useSubmit`/`fetcher.submit`. The default `encType` will still be `application/x-www-form-urlencoded` as it is today, but actions will now also receive a raw `payload` parameter when you submit a raw value (not an HTML element, `FormData`, or `URLSearchParams`).
6
+
7
+
The default behavior will still serialize into `FormData`:
You may opt out of this default serialization using `encType: null`:
6
26
7
27
```jsx
8
28
functionComponent() {
9
29
let submit =useSubmit();
10
30
submit({ key:"value" }, { encType:null });
31
+
// navigation.formEncType => null
32
+
// navigation.formData => undefined
33
+
// navigation.payload => { key: "Value" }
11
34
}
12
35
13
36
functionaction({ request, payload }) {
14
-
// payload => { key: 'value' }
15
-
// request.body => null
37
+
// request.headers.get("Content-Type") => null
38
+
// request.formData => undefined
39
+
// payload => { key: 'value' }
16
40
}
17
41
```
18
42
19
-
Since the default behavior in `useSubmit` today is to serialize to `application/x-www-form-urlencoded`, that will remain the behavior for `encType:undefined` in v6. But in v7, we plan to change the default behavior for `undefined` to skip serialization. In order to better prepare for this change, we encourage developers to add explicit content types to scenarios in which they are submitting raw JSON objects:
43
+
_Note: we plan to change the default behavior of `{ encType:undefined }`to match this "no serialization" behavior in React Router v7. In order to better prepare for this change, we encourage developers to add explicit content types to scenarios in which they are submitting raw JSON objects:_
0 commit comments