-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🗺 Alternate submission encodings #10413
Merged
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
4d58d0e
Revert "Revert "Add better control over submission serialization (#1…
brophdawg11 97ec257
Revert "Revert "Support direct handlers in useSubmit/fetcher.submit/f…
brophdawg11 ac1f5fc
Update router to leverage body instead of payload
brophdawg11 1bc5cfa
DRY up navigation/fetcher creation
brophdawg11 68153da
Switch react-router-dom layer over to use body instead of payload
brophdawg11 3337a52
Fix up type errors
brophdawg11 d1783e8
Bundle
brophdawg11 beeac89
Remove inline action support from useSubmit
brophdawg11 a1b69ac
Change router.fetch API to accept inline action in href slot
brophdawg11 737adbf
Remove no-longer-needed FormData serialization from react-router-dom
brophdawg11 8c3c94e
Bump bundle
brophdawg11 a1e3909
Disallow json + text encTypes from <Form>
brophdawg11 9695f7c
Remove changes to data router example
brophdawg11 8d34552
Update docs to reflect new APIs
brophdawg11 53dbf3a
Docs updates
brophdawg11 97989cf
Add tests for memory routers
brophdawg11 aafc535
Update unit tests workflows
brophdawg11 6456850
Remode node latest since node 20 have issues with react native
brophdawg11 fd54df8
Merge branch 'dev' into brophdawg11/better-actions
brophdawg11 3a09823
Bump bundle
brophdawg11 55e6ef4
Few updates and a TODO or two
brophdawg11 4b38668
Fix type error
brophdawg11 495d9a2
Remove inline loaders/actions support
brophdawg11 56e66e1
Fix some tests
brophdawg11 8e27ab4
Drop bundle
brophdawg11 f8ddea6
Bump
brophdawg11 fe87f25
Updates
brophdawg11 fc044bb
Fix lint issues
brophdawg11 9a137cc
Don't throw on wrong encTypre and add support for string encoding
brophdawg11 ad03283
Bump bundle
brophdawg11 004123d
Handle invalid body submissions with a 400 error
brophdawg11 32aad46
Bump bundle
brophdawg11 8a7df27
MAke text/json/formData mutually exclusive
brophdawg11 253cca7
Add support for <Form encType=text/plain>
brophdawg11 64a932a
Merge branch 'dev' into brophdawg11/better-actions
brophdawg11 f4c7713
Bundle
brophdawg11 a42d81c
Merge branch 'dev' into brophdawg11/better-actions
brophdawg11 7c929c5
Merge branch 'dev' into brophdawg11/better-actions
brophdawg11 ea983e4
Movve text after json
brophdawg11 f8a71dc
Missed a spot
brophdawg11 2b586c9
Error on json/text GET submissions
brophdawg11 d849944
Report fetcher submission errors outward
brophdawg11 153c054
Fix test
brophdawg11 e22ec53
Bump bundle
brophdawg11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
"@remix-run/router": minor | ||
--- | ||
|
||
Add support for `application/json` and `text/plain` encodings for `router.navigate`/`router.fetch` submissions. To leverage these encodings, pass your data in a `body` parameter and specify the desired `formEncType`: | ||
|
||
```js | ||
// By default, the encoding is "application/x-www-form-urlencoded" | ||
router.navigate("/", { | ||
formMethod: "post", | ||
body: { key: "value" }, | ||
}); | ||
|
||
function action({ request }) { | ||
// request.formData => FormData instance with entry [key=value] | ||
// request.text => "key=value" | ||
} | ||
``` | ||
|
||
```js | ||
// Pass `formEncType` to opt-into a different encoding | ||
router.navigate("/", { | ||
formMethod: "post", | ||
formEncType: "application/json", | ||
body: { key: "value" }, | ||
}); | ||
|
||
function action({ request }) { | ||
// request.json => { key: "value" } | ||
// request.text => '{ "key":"value" }' | ||
} | ||
``` | ||
|
||
```js | ||
router.navigate("/", { | ||
formMethod: "post", | ||
formEncType: "text/plain", | ||
body: "Text submission", | ||
}); | ||
|
||
function action({ request }) { | ||
// request.text => "Text submission" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
"react-router-dom": minor | ||
--- | ||
|
||
Add support for `application/json` and `text/plain` encodings for `useSubmit`/`fetcher.submit`. To reflect these additional types, `useNavigation`/`useFetcher` now also contain `navigation.json`/`navigation.text` and `fetcher.json`/`fetcher.text` which are getter functions mimicking `request.json` and `request.text`. Just as a `Request` does, if you access one of these methods for the incorrect encoding type, it will throw an Error (i.e. accessing `navigation.formData` when `navigation.formEncType` is `application/json`). | ||
|
||
```jsx | ||
// The default behavior will still serialize as FormData | ||
function Component() { | ||
let navigation = useNavigation(); | ||
let submit = useSubmit(); | ||
submit({ key: "value" }); | ||
// navigation.formEncType => "application/x-www-form-urlencoded" | ||
// navigation.formData => FormData instance | ||
// navigation.text => "key=value" | ||
} | ||
|
||
function action({ request }) { | ||
// request.headers.get("Content-Type") => "application/x-www-form-urlencoded" | ||
// request.formData => FormData instance | ||
// request.text => "key=value" | ||
} | ||
``` | ||
|
||
```js | ||
// Opt-into JSON encoding with `encType: "application/json"` | ||
function Component() { | ||
let submit = useSubmit(); | ||
submit({ key: "value" }, { encType: "application/json" }); | ||
// navigation.formEncType => "application/json" | ||
// navigation.json => { key: "value" } | ||
// navigation.text => '{"key":"value"}' | ||
} | ||
|
||
function action({ request }) { | ||
// request.headers.get("Content-Type") => "application/json" | ||
// request.json => { key: "value" } | ||
// request.text => '{"key":"value"}' | ||
} | ||
``` | ||
|
||
```js | ||
// Opt-into JSON encoding with `encType: "application/json"` | ||
function Component() { | ||
let submit = useSubmit(); | ||
submit("Text submission", { encType: "text/plain" }); | ||
// navigation.formEncType => "text/plain" | ||
// navigation.text => "Text submission" | ||
} | ||
|
||
function action({ request }) { | ||
// request.headers.get("Content-Type") => "text/plain" | ||
// request.text => "Text submission" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's consider making text/formData/json all mutually exclusive to avoid buffering large bodies in memory