Fix: crash on /books/add check page that prevents selecting matches o…#13085
Open
dvvrtmshra wants to merge 2 commits into
Open
Fix: crash on /books/add check page that prevents selecting matches o…#13085dvvrtmshra wants to merge 2 commits into
dvvrtmshra wants to merge 2 commits into
Conversation
for more information, see https://pre-commit.ci
Collaborator
|
Thanks for the PR, @dvvrtmshra! @mekarpeles is assigned to this PR and currently has:
PR triage checklist (maintainers / Richy)
Note This comment was automatically generated by PAM, Open Library's Project AI Manager. PAM provides status visibility, performs basic project management functions, and gives actionable feedback so contributors aren't left waiting. |
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 #12974
Technical
add-book.jsparsedi18nStringsfromform[name=edit]'sdata-i18nattribute at module scope, so it ran immediately on import rather than when the module's exported function was called.index.jsloads this module on any page withid="addbook"in the DOM — that includestemplates/books/check.html(the "possible matches found" page), not justtemplates/books/add.html. Butcheck.html's form doesn't have adata-i18nattribute, so.dataset.i18nisundefined, andJSON.parse(undefined)threw aSyntaxErrorbeforeinitAddBookImport()could ever run. That meant the click handlers for match-list links and the "Continue" button — which are registered insideinitAddBookImport()— never got attached oncheck.html.Fix: moved the
addBookFormlookup andi18nStringsassignment insideinitAddBookImport(), placed after the click-handler registrations.i18nStringsstays declared at module scope (aslet, assigned rather than initialized) sincevalidatePublishDate()— a separate function outsideinitAddBookImport()— also reads from it. This means the click handlers now always get wired up regardless of whetherdata-i18nis present, while ID-validation/publish-date logic (which only applies onadd.html, where the relevant fields exist) is unaffected.No functional change to
add.html's existing behavior.Testing
/books/addand start adding a book likely to have existing matches (e.g. a well-known ISBN or title).check.html) is shown with potential matches listed.none-of-theseinstead of doing nothing.add.htmlstill works unaffected: go to/books/add, enter an ISBN, confirm validation/auto-complete for ISBN/LCCN/OCLC fields still works, and confirm the publish-date-in-future validation still fires correctly on blur.Screenshot
Stakeholders
@mekarpeles