Skip to content
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(react-router-dom): fix getSearchParamsForLocation in Firefox #10620

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/firefox-addons-and-web-extensions-bug.md
@@ -0,0 +1,5 @@
---
"react-router-dom": patch
---

Fixes an edge-case affecting web extensions in Firefox that use `URLSearchParams` and the `useSearchParams` hook.
1 change: 1 addition & 0 deletions contributors.yml
Expand Up @@ -219,3 +219,4 @@
- yuleicul
- zheng-chuang
- holynewbie
- smithki
9 changes: 7 additions & 2 deletions packages/react-router-dom/dom.ts
Expand Up @@ -97,13 +97,18 @@ export function getSearchParamsForLocation(
let searchParams = createSearchParams(locationSearch);

if (defaultSearchParams) {
for (let key of defaultSearchParams.keys()) {
// Use `defaultSearchParams.forEach(...)` here instead of iterating of
// `defaultSearchParams.keys()` to work-around a bug in Firefox related to
// web extensions. Relevant Bugzilla tickets:
// https://bugzilla.mozilla.org/show_bug.cgi?id=1414602
// https://bugzilla.mozilla.org/show_bug.cgi?id=1023984
defaultSearchParams.forEach((key) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the signature reversed here and key would be the second parameter?

Screenshot 2023-06-21 at 9 59 00 AM

This also tells me we've not got sufficient test coverage over this, so if you're interested in trying to add a test to around this against useSearchParams I'd like to get one added before we merge this. Otherwise I'll try to get some tests wired up when I have a chance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the signature reversed here and key would be the second parameter?

🤦‍♂️ Nice catch, I'll push an update.

As for tests, I'm not familiar enough with this source code to feel confident in providing new test coverage, but if you have some direction I can take a stab at it. Otherwise, it may be easier to pass that along to you in the interest of expediency.

if (!searchParams.has(key)) {
defaultSearchParams.getAll(key).forEach((value) => {
searchParams.append(key, value);
});
}
}
});
}

return searchParams;
Expand Down