Sync layout URL param when toggling list/grid view - #13337
Merged
RayBB merged 2 commits intoAug 17, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR syncs the list/grid layout toggle state to the current page URL via a layout query parameter, so the chosen view can be shared and consistently restored alongside existing query params (e.g., sort, q). It builds on existing server-side support for ?layout= (via get_remembered_layout()), adding client-side URL updates when the segmented control is toggled.
Changes:
- Update
ListBooks.updateLayout()to writelayoutinto the query string and callhistory.replaceState(preserving existing params). - Add Jest unit tests covering class toggling, URL param updates/preservation, cookie persistence, analytics tracking, and history behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| openlibrary/plugins/openlibrary/js/list_books.js | Syncs the selected layout to ?layout= in the URL using replaceState after toggling the view and persisting LBL. |
| tests/unit/js/listBooks.test.js | Adds unit tests validating layout toggling behavior, URL synchronization, cookie persistence, analytics tracking, and history behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+27
to
+29
| document.body.innerHTML = ''; | ||
| mockTrackEvent.mockClear(); | ||
| // Give each test a realistic URL with params worth preserving. |
RayBB
approved these changes
Aug 17, 2026
RayBB
left a comment
Collaborator
There was a problem hiding this comment.
I put it on testing and it's working excellently. Thanks for contributing!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Closes #13327
Feature: when the user toggles the List/Grid layout control, the URL now updates to reflect the chosen layout (e.g.
?layout=grid), so the current view can be shared. Follows @RayBB's direction on the issue:get_remembered_layout()already resolves?layout=server-side, this adds the client-side URL sync.Technical
ListBooks.updateLayout(): after toggling the class and setting theLBLcookie, thelayoutquery param is written viaURLSearchParamsandhistory.replaceState, preserving existing params likesort.replaceStaterather thanpushStateso toggling doesn't stack back-button entries (agreed on the issue).ol-segmented-control, the URL sync applies to lists, search, author, and reading log pages with no extra code.tests/unit/js/listBooks.test.js(modeled onsortOptions.test.js): 6 cases covering the class toggle, URL param write with param preservation, no duplicatelayoutparam, replaceState behavior,LBLcookie, and the analytics event. The two URL tests fail without this change. Test file drafted with AI assistance, then reviewed and verified locally, including a red/green check against the unpatched file.Testing
/search?q=the&sort=oldlayout=grid,qandsortpreservedlayout=detailslayoutvalue directly in the address bar and hit Enternpx jest tests/unit/js/listBooks.test.jspasses (6 tests)Screenshot
pr_demo_13327.mp4
Stakeholders
@RayBB