-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
fix: preserve search params on unspecified <Form> action #9060
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
15b96e5
fix: preserve search params on unspecified form action
brophdawg11 3310ee4
Merge branch 'dev' into brophdawg11/form-action-params
brophdawg11 b6e2c7f
stengthen index tests
brophdawg11 6f4bc0d
Add useFormAction tests for nested routes
brophdawg11 3b6fc11
account for splat routes and empty action
brophdawg11 0ccf84c
Merge branch 'dev' into brophdawg11/form-action-params
brophdawg11 4e5925f
add changeset
brophdawg11 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3467,7 +3467,7 @@ describe("a router", () => { | |
expect(t.router.state.navigation.formData).toBeUndefined(); | ||
}); | ||
|
||
it("merges URLSearchParams for formMethod=get", async () => { | ||
it("does not preserve existing 'action' URLSearchParams for formMethod='get'", async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a previous misunderstanding on my part - browser do indeed blow away query params on GET submissions. I thought it would just append them |
||
let t = setup({ | ||
routes: TASK_ROUTES, | ||
initialEntries: ["/"], | ||
|
@@ -3479,12 +3479,32 @@ describe("a router", () => { | |
expect(t.router.state.navigation.state).toBe("loading"); | ||
expect(t.router.state.navigation.location).toMatchObject({ | ||
pathname: "/tasks", | ||
search: "?key=1&key=2", | ||
search: "?key=2", | ||
}); | ||
expect(t.router.state.navigation.formMethod).toBeUndefined(); | ||
expect(t.router.state.navigation.formData).toBeUndefined(); | ||
}); | ||
|
||
it("preserves existing 'action' URLSearchParams for formMethod='post'", async () => { | ||
let t = setup({ | ||
routes: TASK_ROUTES, | ||
initialEntries: ["/"], | ||
}); | ||
await t.navigate("/tasks?key=1", { | ||
formMethod: "post", | ||
formData: createFormData({ key: "2" }), | ||
}); | ||
expect(t.router.state.navigation.state).toBe("submitting"); | ||
expect(t.router.state.navigation.location).toMatchObject({ | ||
pathname: "/tasks", | ||
search: "?key=1", | ||
}); | ||
expect(t.router.state.navigation.formMethod).toBe("post"); | ||
expect(t.router.state.navigation.formData).toEqual( | ||
createFormData({ key: "2" }) | ||
); | ||
}); | ||
|
||
it("returns a 400 error if binary data is attempted to be submitted using formMethod=GET", async () => { | ||
let t = setup({ | ||
routes: TASK_ROUTES, | ||
|
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
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.
I think this should still resolve the path based on
"."
if the action is undefined, no? Does that make a difference here? My reading ofresolveTo
makes me believe that it would if we were in a nested route situation.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.
I think that puts us back in the same scenario though where we lose search params? Down inside
useResolvedPath -> resolveTo -> parsePath
we end up with aPath
of{ pathname: '.' }
without anysearch
orhash
. By passing the currentlocation
when noaction
is specified we preserve those throughout?Just to be safe, I added a few tests for the nested route scenario to confirm they're handled - and they break if we change to
let path = useResolvedPath(action || '.')