openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Checked out button triggers page reload instead of being inactive

Open MahdiiFakhfakh opened this issue 7 months ago • 4 comments

Problem

When viewing a book that is already checked out on Open Library, clicking the "Checked out" button causes the page to reload.

Image

Reproducing the bug

  1. Go to any book that is cuurently checked out
  2. Click on the Checked out" button
  • Expected behavior: The button should be inactive (disabled) or non-clickable
  • Actual behavior: Clicking the button triggers a page reload

Context

  • Browser (Chrome, Safari, Firefox, etc):
  • OS (Windows, Mac, etc):
  • Logged in (Y/N):N
  • Environment (prod, dev, local): prod

Breakdown

Implementation Details (for maintainers) The issue may be caused by the button being inside a form and defaulting to type="submit", which triggers a page reload when clicked

Requirements Checklist

  • Prevent any form of page reload when clicking "Checked out"

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.

MahdiiFakhfakh avatar Apr 27 '26 15:04 MahdiiFakhfakh

Thank you @MahdiiFakhfakh for submitting this issue!

⚠️ Contributors, this issue will be ready to work on once:

  • [x] Triage — maintainers will add Priority: * and Lead: @* to replace Needs: Triage and Needs: Lead

Context

The button is defined in openlibrary/macros/LoanStatus.html (lines 125–133) as an <a> tag with href="$work_key":

<a
  href="$work_key"
  class="cta-btn cta-btn--missing"
  title="This book is currently checked out, please check back later."
>Checked Out</a>

Clicking it navigates to $work_key — which, when already on the book's work page, reloads the current page. This is the same root cause as #12149 (where the same button in the homepage carousel redirects to / because $work_key is null in that context). PR #12152 is an open fix targeting the carousel context; any fix here should be coordinated with that PR.

Additionally, the CSS class cta-btn--missing has no definition in static/css/components/buttonCta.css, so the button has no visual disabled state.

Issue Assessment

Open questions

  • Is this reproducible specifically on the book's own page (e.g. /works/OL...) or also in the homepage carousel? The behavior differs by context: on the book page the link reloads; on the carousel it redirects to /. The browser and OS fields in the bug report are blank — please fill those in.
  • Should the button remain as an <a> linking to the book page (matching behavior of the cover image), or become a non-interactive element? These are two distinct UX approaches and the right answer affects the fix.

Action items

  • [ ] Fill in the browser and OS fields in the bug report.
  • [ ] Correct the diagnosis: the button is not inside a form. It is an <a> tag whose href attribute triggers navigation. The type="submit" framing does not apply here.

Suggested breakdown

This is closely related to #12149; fixes should be coordinated with PR #12152.

  • [ ] In openlibrary/macros/LoanStatus.html lines 125–133: change the <a href="$work_key"> to a non-interactive element (e.g. <button disabled> or <span>) so clicking does nothing — or update href to point to the book page URL if the linking approach is preferred. — Could be Good First Issue once triaged: single-template change, well-bounded.
  • [ ] In static/css/components/buttonCta.css: define .cta-btn--missing with a visual disabled state (muted color, cursor: default, pointer-events: none). — Could be Good First Issue once triaged: isolated CSS change.
  • [ ] Verify the tooltip (title attribute) still renders correctly after the element type changes.
  • [ ] Test in both contexts: book page and homepage carousel (coordinate with #12149 / PR #12152).
Full triage checklist (maintainers / Pam)
  • [ ] Triage — correct labels applied or removed: Needs: Breakdown, Needs: Investigation, Needs: Design, Needs: Staff Decision, Needs: Staff / Admin, Good First Issue, Blocked, Blocker
  • [x] Problem / opportunity — problem is clear, audience identified, actionable
  • [x] Scope — issue is well-scoped; does not try to do too many things; split suggested if needed
  • [ ] Justification — reasoning and impact stated; sufficient for leads to prioritize (note: does it include urgency / why now?)
  • [ ] Success & testing criteria — defines what "done" looks like, verifiable by a contributor without asking; what must be tested
  • [x] Proposal & breakdown — concrete plan present; checklist or sub-issues actionable for a contributor
  • [ ] If bug: environment & repro steps — browser and OS fields left blank; steps are present but incomplete
  • [ ] Risks, concerns, open questions — UX decision (disabled vs. linked) not yet resolved; affects implementation approach
  • [x] Pam context — relevant code reviewed; related issue #12149 and PR #12152 identified
  • [x] References — screenshot present

[!NOTE] This comment was automatically generated by Pam, Open Library's Project AI Manager, on behalf of @mekarpeles. Pam 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.

mekarpeles avatar Apr 27 '26 15:04 mekarpeles

Hi! I'd like to be assigned to this issue. I've already investigated the root cause and have a fix ready.

Plan:

  • In openlibrary/macros/LoanStatus.html (lines 125–133): replace the <a href="$work_key"> with a <button disabled> so it's non-interactive and won't trigger navigation
  • In static/css/components/buttonCta.css: add a .cta-btn--missing style with cursor: default, pointer-events: none, and a muted color for a clear visual disabled state
  • Coordinate with PR #12152 to avoid conflicts on the carousel context

Could someone please assign this to me? Thanks!

ragini-pandey avatar Apr 28 '26 06:04 ragini-pandey

@ragini-pandey sure! Please note that this button can be called from multiple contexts.

From carousels and search, we would want this to bring the patron to the book page.

On the book page, we'd want it to be disabled / not a link.

It may work like this already?

mekarpeles avatar May 02 '26 04:05 mekarpeles

This seems to be totally fixed now. I was able to reproduce when you made it but since the deploy yesterday it's better. Probably fixed by: https://github.com/internetarchive/openlibrary/pull/12152

RayBB avatar May 08 '26 16:05 RayBB