-
Notifications
You must be signed in to change notification settings - Fork 24.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
Implementation of URLSearchParams Methods #50043
Conversation
@cortinico Can you please check if this can be merged ? :) |
@cortinico @cipolleschi Can you please check if we can merge this :) |
This PR looks good to me, thanks for working on this. |
there are some lint warning though... can you go through them and fix them? |
Thanks for the review @cipolleschi . I have fixed the warnings . Can you check now |
CIs green .🚀 |
@cipolleschi @cortinico . Can we merge this please before 0.80 starts so that URL and URLSearchParams both are implemented in same version. |
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
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.
Pull Request Overview
This PR implements the full URLSearchParams API, extending its initialization options and adding support for various methods (delete, get, getAll, has, set, keys, values, entries, forEach, sort, toString) to align with web standards.
- Enhanced initialization of URLSearchParams to support string, record, and array inputs.
- Added comprehensive tests to validate the new behavior and fixed the URL initialization bug.
- Updated the URL component in rn-tester to include searchParams output for debugging.
Reviewed Changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated no comments.
File | Description |
---|---|
packages/rn-tester/js/examples/Urls/UrlExample.js | Added display of URLSearchParams in the URL example. |
packages/react-native/Libraries/Blob/tests/URL-test.js | Expanded tests for URLSearchParams covering various initialization types and method behaviors. |
packages/react-native/Libraries/Blob/URLSearchParams.js | Reimplemented URLSearchParams supporting multiple input types and methods in accordance with standards. |
packages/react-native/Libraries/Blob/URL.js | Fixed URL initialization to properly pass search parameters. |
Files not reviewed (2)
- packages/react-native/Libraries/Blob/URLSearchParams.js.flow: Language not supported
- packages/react-native/Libraries/tests/snapshots/public-api-test.js.snap: Language not supported
Comments suppressed due to low confidence (3)
packages/react-native/Libraries/Blob/URLSearchParams.js:70
- The keys method should not accept any parameters as per the URLSearchParams API; please remove the 'name: string' parameter.
keys(name: string): Iterator<string> {
packages/react-native/Libraries/Blob/URLSearchParams.js:74
- The values method should not define a parameter; remove the 'name: string' argument to conform with the standard API.
values(name: string): Iterator<string> {
packages/react-native/Libraries/Blob/URLSearchParams.js:85
- The entries method should not accept a parameter; please drop the 'name: string' parameter to align with the web standard.
entries(name: string): Iterator<[string, string]> {
Note Just experimenting by adding Copilot as a reviewer on this PR! 😄 Result: Found the 3 API issues under "Comments suppressed due to low confidence (3)" |
Thanks for the review @huntie and copilot too :) .I have fixed the comments and updated the test cases. Can you check now, |
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.
LGTM, thanks for actioning quickly! :) Just a couple super minor nits.
Nits fixed too :) |
@huntie has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Summary:
This PR addresses the following issues and enhances the functionality of
URLSearchParams
:Extended Initialization Parameters: Previously, only
Record<string, string>
was supported while initialising URLSearchParams. Now supportsstring
,Record<string, string>
, andArray<[string, string]>
(aligning with web standards).Added Implementation for
delete()
,get()
,getAll()
,has()
,sort()
, andset()
.Addition of Iteration Methods: Added
keys()
,values()
,entries()
, andforEach()
methods. Outputs are identical to web.Bug Fix: Incorrect Initialization from URL. Previously,
URLSearchParams
was initialized with an empty value when accessed viaurl.searchParams
, even if theURL
contained search parameters.Changelog:
[General][Added] Implementation for URLSearchParams
Test Plan:
Can be tested by below code
Tested on both hermes and JSC.
Hermes:-

JSC:-
