Skip to content

fix: disable 'Want to Read' button until JS loads #12139

Merged
jimchamp merged 3 commits into
internetarchive:masterfrom
bhardwajparth51:fix/want-to-read-js-fallback
Apr 15, 2026
Merged

fix: disable 'Want to Read' button until JS loads #12139
jimchamp merged 3 commits into
internetarchive:masterfrom
bhardwajparth51:fix/want-to-read-js-fallback

Conversation

@bhardwajparth51
Copy link
Copy Markdown
Contributor

Description

Closes #12042

This PR fixes the issue where clicking the "Want to Read" button before the page is fully loaded would lead to a broken JSON response. I've disabled the button in the initial HTML so users can't click it mid-load, and it gets re-enabled automatically once the JavaScript is ready to handle the click.

Technical

To get this working correctly, I had to touch a few different places:

  1. Added the disabled attribute to the main button in openlibrary/templates/my_books/primary_action.html
  2. Added some styles in static/css/components/generic-dropper.css to make sure the mouse cursor stays as a default arrow (rather than a pointer) while the button is disabled. I used a high-specificity selector to make sure it correctly overrides the global button styles.
    3.Updated ReadingLogForms.js strip the disabled attribute once the component initializes.

Testing

To verify the fix, you can simulate a slow load (or just disable JS) and go to any book page.

  • You'll see the "Want to Read" button is disabled and won't show a pointer cursor on hover.
  • Once the page is fully loaded, the button should become active and work exactly like before, with no more random JSON redirects.

Screenshots

simplescreenrecorder-2026-03-19_22.43.43.online-video-cutter.com.mp4
Screencast_from_19-03-26_10_15_32_PM_IST_.1.-compressed-file-converter-online.com.mp4

Stakeholders

@jimchamp

@github-actions github-actions Bot added the Priority: 2 Important, as time permits. [managed] label Mar 19, 2026
@bhardwajparth51 bhardwajparth51 changed the title Fix #12042: Disable 'Want to Read' button until JS loads to prevent J… fix: disable 'Want to Read' button until JS loads Mar 19, 2026
@bhardwajparth51 bhardwajparth51 force-pushed the fix/want-to-read-js-fallback branch from a7a83ff to 8fd5306 Compare March 19, 2026 17:27
@bhardwajparth51
Copy link
Copy Markdown
Contributor Author

decided to keep the button fully opaque (opacity: 1) while it's disabled. The main reason is to avoid that annoying flicker you sometimes see on fast connections where a button starts greyed out and then 'jumps' to its active color a split second later once JS loads. Since the script usually initializes almost instantly, I think it feels much smoother if the button looks ready from the start. I’ve added cursor: default so users still get the hint that it’s not clickable yet if they happen to hover over it early.

@bhardwajparth51 bhardwajparth51 force-pushed the fix/want-to-read-js-fallback branch from 8fd5306 to 1a53226 Compare March 19, 2026 17:31
@bhardwajparth51 bhardwajparth51 force-pushed the fix/want-to-read-js-fallback branch from 4e0ca39 to bdff092 Compare March 19, 2026 17:36
@github-actions github-actions Bot added the Needs: Response Issues which require feedback from lead label Mar 20, 2026
@bhardwajparth51
Copy link
Copy Markdown
Contributor Author

@jimchamp I noticed #12140 by @mekarpeles addresses the same issue. Happy to close this in favour of that PR, or contribute any differences if useful.

Comment on lines +116 to +118
if (this.primaryButton) {
this.primaryButton.removeAttribute('disabled')
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be moved outside of the if(!this.isDropperDisabled) block. Otherwise, clicking the "Add to List" button does not redirect to the login page.

@jimchamp jimchamp added Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] and removed Needs: Response Issues which require feedback from lead labels Apr 14, 2026
@mekarpeles
Copy link
Copy Markdown
Member

@bhardwajparth51 were you able to take this one over the finish line?

Comment thread openlibrary/plugins/openlibrary/js/my-books/MyBooksDropper/ReadingLogForms.js Outdated
Moves `removeAttribute` outside the if (!this.isDropperDisabled) guard as Jim suggested — this ensures the button is re-enabled for both logged-in and logged-out users. When isDropperDisabled is true (e.g. user not logged in), the button currently stays permanently disabled, so clicks never fire and the form never submits to the login redirect.
@github-actions github-actions Bot removed the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Apr 15, 2026
@mekarpeles mekarpeles requested a review from Copilot April 15, 2026 21:13
Comment thread static/css/components/generic-dropper.css Outdated
Comment thread static/css/components/generic-dropper.css Outdated
@mekarpeles
Copy link
Copy Markdown
Member

Worth noting that this will break the experience for those without js enabled (as the button will be permanently disabled). Let's just note this for @seabelis in case this becomes an issue for patrons.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Disables the “Want to Read” (reading log primary action) button during initial page load to prevent pre-JS clicks from submitting the form and landing users on a JSON response page.

Changes:

  • Renders the primary reading-log CTA button as disabled in the initial server-side template output.
  • Adds CSS to prevent the pointer cursor (and avoid disabled-state flicker) on the disabled primary button.
  • Updates ReadingLogForms.initialize() to re-enable the primary button once the JS component initializes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
openlibrary/templates/my_books/primary_action.html Disables the primary reading-log submit button in initial HTML.
static/css/components/generic-dropper.css Adds disabled-state cursor/opacity override for the primary button.
openlibrary/plugins/openlibrary/js/my-books/MyBooksDropper/ReadingLogForms.js Re-enables the primary button at component initialization time.

Comment thread openlibrary/templates/my_books/primary_action.html
* If dropper is disabled, no event listeners will be added.
*/
initialize() {
if (this.primaryButton) {
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initialize() removes disabled from primaryButton even when the dropper is marked disabled (generic-dropper--disabled). This conflicts with the method docstring (“If dropper is disabled, no event listeners will be added”) and can re-enable a control that the UI intends to keep disabled. Consider only re-enabling the button when !this.isDropperDisabled (or otherwise gating it on authentication/eligibility).

Suggested change
if (this.primaryButton) {
if (this.primaryButton && !this.isDropperDisabled) {

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this might be a good point? @jimchamp ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The this.isDropperDisabled flag is only set when the patron is logged out. When true, the dropper cannot be opened. It has nothing to do with the primary button's disabled attribute.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that the suggested code change puts us in the same position as we are now -- clicks on the "Add to List" button will not redirect to the login page.

Comment thread static/css/components/generic-dropper.css Outdated
* If dropper is disabled, no event listeners will be added.
*/
initialize() {
if (this.primaryButton) {
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New behavior is introduced where the primary reading-log button starts disabled in HTML and is enabled during initialize(). There are existing Jest unit tests for the my-books UI, but none cover ReadingLogForms.initialize(); adding a unit test that asserts the button is enabled after initialization (and stays disabled for disabled droppers, if applicable) would help prevent regressions.

Suggested change
if (this.primaryButton) {
if (this.primaryButton && !this.isDropperDisabled) {

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <[email protected]>
@jimchamp jimchamp merged commit eb004ce into internetarchive:master Apr 15, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority: 2 Important, as time permits. [managed]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clicking "want to read" before JS has loaded and run takes you to a .json dead end

4 participants