-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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 issues with contextual routing and index params #12003
Conversation
🦋 Changeset detectedLatest commit: 41100b9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 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 |
</Route> | ||
), | ||
{ | ||
window: getWindow("/parent?index&index=keep"), |
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.
When we have an ?index
around from a prior submission, we were incorrectly letting that apply to a submit(data, { method: 'post' })
in the parent component and then it would try to submit to the child index route action and not the proper contextual parent route action
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 handled properly in useFormAction
(so Form
/fetcher.Form
didn't have the bug) but when using useSubmit
it goes straight to the router which does the path resolving, so we were missing the logic in router.navigate
/router.fetch
</Route> | ||
), | ||
{ | ||
window: getWindow("/parent?index&index=keep"), |
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.
Form
/fetcher.Form
did not have this issue since useFormAction
handled it - but the logic in useFormAction
to remove the ?index
param was naive and removed all index params, not preserving user-specified ones. This PR also fixes that issue
expect(container.innerHTML).toMatch(/(:r2a:|:rp:),my-key/) | ||
// React `useId()` results in something such as `:r2a:`, `:r2i:`, | ||
// `:rt:`, or `:rp:` depending on `DataBrowserRouter`/`DataHashRouter` | ||
expect(container.innerHTML).toMatch(/(:r[0-9]?[a-z]:),my-key/) |
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.
These internal react IDs seem to have changed with the new tests
params.delete("index"); | ||
path.search = params.toString() ? `?${params.toString()}` : ""; | ||
indexValues.filter((v) => v).forEach((v) => params.append("index", v)); |
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.
Preserve user-specified index
params inside useFormAction
// Remove existing ones when we're not | ||
let params = new URLSearchParams(path.search); | ||
let indexValues = params.getAll("index"); | ||
params.delete("index"); | ||
indexValues.filter((v) => v).forEach((v) => params.append("index", v)); | ||
let qs = params.toString(); | ||
path.search = qs ? `?${qs}` : ""; |
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.
Remove ?index
param when submitting to a non-index parent route
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
Closes remix-run/remix#8923