Bug: Preview Button on Homepage Does Nothing When Clicked
Problem
Description: Clicking the "Preview" button on the Open Library homepage does not open the book preview or navigate to any page. The button appears clickable but produces no result.
https://github.com/user-attachments/assets/01f6d788-0c5d-4934-b947-ee46602f86cb
Reproducing the bug
Steps to Reproduce
- Go to https://openlibrary.org/
- Find a book on the homepage with a "Preview" button
- Click the "Preview" button
- Nothing happens
Expected Behavior: Clicking the Preview button should open the book preview (e.g., navigate to /books/OL24152177M or open the embedded reader).
Actual Behavior: Nothing happens. No navigation, no modal, no error visible to the user.
Context
Environment
- Browser: Google Chrome (latest)
- OS: Windows 11/ Ubuntu 22.04
- Page: https://openlibrary.org/ (Homepage)
- Date observed: February 19, 2026
Breakdown
Implementation Details (for maintainers)
Requirements Checklist
- [ ]
Related files
Stakeholders
Instructions for Contributors
- Please run these commands to ensure your repository is up to date before creating a new branch to work on this issue and each time after pushing code to Github, because the pre-commit bot may add commits to your PRs upstream.
Hi @mekarpeles @cdrini , I'd love to be assigned this issue and take a shot at fixing it.
I've already done a little bit of digging and the bug seems to be that the #bookPreview floater div isn't present in the homepage DOM, so when the cta-btn--preview click handler fires via colorbox, there's nothing to render. I found this might be related to #2612 back in 2019, just resurfacing on the homepage carousel context rather than the edition page.
My plan is to trace the cta-btn--preview binding in the JS, check whether AvailabilityButton.html or home/index.html needs to include the floater, and explore whether it's cleaner to dynamically build the iframe from a data- attribute on the button rather than relying on a pre-rendered hidden div.
This is my first open source contribution, but I've done a little bit of homework on the codebase and I'm serious about seeing it through. Would you be willing to assign this to me? I would love to take this on. Thanks!
Hi @mekarpeles @cdrini @RayBB, I filed this issue and have been investigating the fix.
The root cause appears to be that initPreviewDialogs binds click handlers at page load, but carousel content is injected lazily afterward, so those buttons never receive handlers.
The expected behavior is for the Preview button to open the Internet Archive BookReader inline on the same page. The fix should ensure the handler is bound whenever new carousel content enters the DOM.
Proposed Changes
dialog.js
- Update
initPreviewDialogsto accept an optionalcontextparameter (defaulting todocument) - Scope the
.cta-btn--previewselector to the providedcontext - Guard against double-binding using
.not('.cboxElement')to avoid re-initializing already-bound buttons
lazy-carousel.js
- Import
initPreviewDialogsfrom./dialog - Call
initPreviewDialogs(newElem)after new carousel content is inserted into the DOM
This keeps the fix minimal and avoids rebinding the entire document on each carousel load.
I'd be happy to take this on and open a draft PR if this approach sounds good. Happy to coordinate with @Saad259 as well. Thanks!
@bhardwajparth51 @mekarpeles @cdrini @RayBB That's a cleaner diagnosis than where I landed and a good catch on the lazy-loading timing. I'd love to coordinate and help get this across the line. Happy to take on any part of the implementation or testing if you'd like to split it up!
@bhardwajparth51 go ahead and try to open a PR with a fix. Though, I'm not sure if this will be easy to test locally.
On many pages (books page, search page) we have some load_once logic which ensures the internet archive modal is available (once, invisibly) on the page. I think this isn't the case on the homepage.
Root Cause
-
Missing modal HTML - The BookPreview modal is not present on the homepage. The modal is rendered by the BookPreview macro via render_once, but lazy carousels do not call this macro server-side.
-
Event handlers not bound - initPreviewDialogs binds click handlers at page load, but carousel content is injected via AJAX afterward.
Recommended Fix
Part 1: Add modal to homepage
In home/index.html add this line to render the modal HTML:
$:macros.BookPreview('')
Part 2: Bind handlers to lazy content
Modify dialog.js to accept an optional context parameter, then call initPreviewDialogs from lazy-carousel.js after content insertion.