Duplicate match page elements do not respond to clicks
Problem
When trying to add a book, if a matching record already exists, clicking 'Add' keeps the user at https://openlibrary.org/books/add where it displays books that could be potential matches. If valid, instead of adding the new book, the natural thing to do is to click on one of the matches. However, doing so does not lead to anything. Clicking on 'Continue' also does not do anything.
Reproducing the bug
- Try adding https://html5forwebdesigners.com/ as a new record and perform the steps above
- Observe that it navigates to https://openlibrary.org/books/add
- Try interacting with any of the relevant page elements.
- Expected behavior: The new book is not added and appropriate next steps follow.
- Actual behavior: Nothing happens
Context
- Browser (Chrome, Safari, Firefox, etc):
- OS (Windows, Mac, etc):
- Logged in (Y/N):
- Environment (prod, dev, local): prod
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.
I'm looking into this and am happy to take it on.
Thank you @Saad259 for submitting this issue!
⚠️ Contributors, this issue will be ready to work on once:
- [ ] Triage — maintainers will add
Priority: *andLead: @*to replaceNeeds: TriageandNeeds: Lead - [ ] Needs: Breakdown — concrete implementation steps have been added
Context
The root cause is a JavaScript crash at module load time that silently prevents all click handlers on the /books/add check page from being registered.
Where the bug lives: openlibrary/plugins/openlibrary/js/add-book.js
At module scope (outside any function), add-book.js contains:
const i18nStrings = JSON.parse(document.querySelector('form[name=edit]').dataset.i18n);
The form in templates/books/add.html has a data-i18n="..." attribute. The form in templates/books/check.html — the page shown when potential matches are found — does not. So .dataset.i18n is undefined, JSON.parse(undefined) throws a SyntaxError, and initAddBookImport() (which registers click handlers for the match list and "Continue" button) never runs.
index.js lines 300–302 correctly detects id="addbook" on the check page and imports add-book.js, so the module is loaded — but the crash prevents the export from completing.
Related: PR #12733 recently fixed a separate AttributeError on the same check.html template.
Issue Assessment
Action items:
- [ ] Add environment details to the bug report (browser, OS, logged-in status) — minor, but useful for reproducing
- [ ] Add implementation steps to the Breakdown section
Suggested breakdown:
- [ ] Move the module-level
const i18nStrings = JSON.parse(...)andconst addBookForm = ...declarations to insideinitAddBookImport()inadd-book.js— these are only used within that function and its callbacks, so there is no functional change. This prevents the crash on pages that haveid="addbook"but nodata-i18nattribute (i.e.check.html). (Potential Good First Issue) - [ ] Add or update a test that loads the check page and verifies that clicking a match result and clicking "Continue" both trigger form submission
Full triage checklist (maintainers / Richy)
- [x] Triage — labels reviewed (Type: Bug confirmed; Needs: Breakdown, Triage, Lead retained)
- [x] Problem / opportunity — clear: interactive elements on potential-match page are non-functional
- [x] Scope — well-scoped; single JS bug with a clear fix path
- [x] Justification — impacts any user whose book submission triggers the duplicate-check page
- [ ] Success & testing criteria — not defined; no acceptance criteria or test plan stated
- [ ] Proposal & breakdown — breakdown section is empty
- [x] Environment & repro steps — repro steps present; environment fields partially filled (prod noted, browser/OS/auth blank)
- [ ] Risks, concerns, open questions — none called out (low risk: fix is additive/defensive)
- [x] Richy context — codebase reviewed; root cause identified in
add-book.js+check.html; PR #12733 noted as related - [x] References — screenshot present
[!NOTE] This comment was automatically generated by Richy, via PAM, Open Library's Project AI Manager, on behalf of @mekarpeles. Richy is designed to provide status visibility, perform basic project management functions and relevant codebase research, and provide actionable feedback so contributors aren't left waiting.
Okay so I have looked at add-book.js, add.html, check.html, and index.js directly. Here's what I've found:
- In
add-book.jsthe DOM access statements are being called at module scope outsideinitAddBookImport() add.html's form hasdata-i18n="$json_encode(i18n_strings)";check.html's form (same id="addbook" / name="edit") doesn't have that attribute.- The module loads and crashes at
check.htmlbeforeinitAddBookImport()ever runs. Since the chain has nocatch(), the failure is silent so nothing happens visibly on click. - For comparison,
signup.jshas an identical pattern but all the DOM-dependent code lives inside the exportedinitSignupForm()function - There is also no test coverage currently for
add-book.js. I'm happy to followsignup.test.jsto add one
Ready to work on this.