-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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(remix-react): GET form submissions should replace current search params #4046
Conversation
🦋 Changeset detectedLatest commit: 2afce3f The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
for (let [name, value] of formData) { | ||
if (typeof value === "string") { | ||
url.searchParams.append(name, value); |
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.
This was the underlying problem, now that our default behavior for no action was to include search params, we were just appending to them here instead of starting with an empty set on GET submissions
As a temporary workaround, you can put an |
@jenseng Yeah that should do the trick for now. You can also just do |
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.
Great explanation and repro!
1be103d
to
2afce3f
Compare
🤖 Hello there, We just published version Thanks! |
@brophdawg11 How to preserve then current search params? Mapping search params to hidden inputs is not convenient. |
That would be my recommendation - I don't find it all that inconvenient: let [params] = useSearchParams();
...
<Form>
{Array.from(params.entries()).map(([k, v], idx) => (
<input type="hidden" name={k} defaultValue={v} key={idx} />
))} |
The recent work done in #3697 uncovered a previously unknown bug where we do not match default browser behavior. By default, non-JS
<form method="get">
will replace any existing search parameters in the URL, but our behavior has been to append (without first resetting the params) since #814.Default browser behavior is shown in this code sandbox. You may have to open it in a new window and load it with some existing query params, and then submit the form. I.e., https://e26g6e.sse.codesandbox.io/?junk=value
This new Remix behavior also has the side effect of no longer including the
?index
in the destination URL (even though it is included in the form action). This should have no impact since GET submissions run all relevant loaders.action
prop is omitted #3697/parent?foo=1
<form action="/parent?index&foo=1">
/parent?index&foo=1&bar=2
<form action="/parent?index&foo=1&bar=2">
/parent?foo=1
<form action="/parent?index&foo=1">
/parent?bar=2
<form action="/parent?index&bar=2">
Closes: #4044
Testing Strategy:
form-test
integration tests