-
-
Notifications
You must be signed in to change notification settings - Fork 956
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
Cannot properly replace URL while paginating #1211
Comments
Moreover, returning a non-undefined I think @sinedied ran into this issue and described it here, but I'm not sure if it was clear or captured as a bug. Here is the sequence of URLs the Pagination API is creating for @sinedied. I'm seeing the same pattern -- i.e. appending instead of replacing.
The docs say
To me, that means the returned Got options will completely replace the previous request's Got options, not merge or append to the previous request's Got options. However, I could see the benefit of a merge so that things like e.g. |
Actually if it's
|
|
Actually I think it's a regression |
But if |
const got = require('got');
const options = got.mergeOptions({
url: new URL('http://localhost:41285'),
searchParams: new URLSearchParams('page=0')
}, {
url: 'http://localhost:41285/?page=1',
searchParams: undefined
});
options.url.href;
// 10.7.0 => http://localhost:41285/?page=1
// latest => http://localhost:41285/?page=0&page=0 |
If it's |
In Got 12 setting |
Describe the bug
When using the pagination API, it is desirable to remove the original searchParams for subsequent pages if the full URL for the next page is returned from the API. This is so that the search params on the query string of the returned URL can be used instead of the original searchParams.
As per this comment, this should be possible by returning
searchParams: undefined
from thepaginate
function, but this actually causes the original searchParams to take precedence, and any params on the query string in the returned URL are removed. What's more, the original searchParams are duplicated in the resulting URL.Actual behavior
Original searchParams should not be added to URL.
Expected behavior
Original searchParams are duplicated in resulting URL, and search params inside the returned URL are overwritten/removed.
Code to reproduce
Using the Facebook Graph API, which returns the 'next page' URL as described above.
As an aside, setting
searchParams: ''
in the return object frompaginate
is a workaround to this issue, and results in the desired behaviour.Checklist
The text was updated successfully, but these errors were encountered: