-
Notifications
You must be signed in to change notification settings - Fork 277
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
Support multiple Pagination components on the same page #2649
base: main
Are you sure you want to change the base?
Conversation
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
// Handle non-namespaced params (empty string namespace) | ||
if (activeNamespaces.includes('')) { | ||
params.delete('cursor'); | ||
params.delete('direction'); | ||
} | ||
|
||
activeNamespaces | ||
.filter((namespace) => namespace !== '') | ||
.forEach((namespace) => { | ||
const cursorParam = `${namespace}_cursor`; | ||
const directionParam = `${namespace}_direction`; | ||
|
||
params.delete(cursorParam); | ||
params.delete(directionParam); | ||
}); | ||
|
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.
Optionally, you could roll this into one by doing:
const namespacePrefix = namespace === '' ? '' : `${namespace}_`
const cursorParam = `${namespacePrefix}cursor`;
const directionParam = `${namespacePrefix}direction`;
Though tbh it would have been fine to give no special treatment to the empty namespace, and just used _cursor
and _direction
when working with it (although granted that might look ugly in the URL)
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.
Yess much cleaner, thanks!
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.
And yeah I thought _cursor
was a bit of an eye sore + would break existing links when folks upgrade.
WHY are these changes introduced?
Enables the use of multiple
<Pagination />
components on a single page.Resolves https://github.com/Shopify/hydrogen-internal/issues/124
WHAT is this pull request doing?
namespace
prop on the<Pagination />
component. If provided, the namespace value prepends the URL parameters - as in<namespace>_cursor
and<namespace>_direction
.cursor
anddirection
params are used.namespace
s are stored in the location state so we can:getPaginationVariables
utility to accept an optional namespace.HOW to test your changes?
app/routes/collections.all.tsx
with this contentapp/components/PaginatedResourceSection.tsx
with this contentnamespace
.Checklist