Skip to content

fix(handout): resolve real product names on the printable handout - #31

Merged
arsalan-arshad merged 2 commits into
mainfrom
fix/handout-product-titles
Nov 9, 2026
Merged

arsalan-arshad merged 2 commits into
mainfrom
fix/handout-product-titles

Conversation

@arsalan-arshad

Copy link
Copy Markdown
Owner

Summary

The printable handout (/apps/protocols/<token>?handout=1) showed "Item 1" and "Item 2" instead of product names, because protocol lines stored in Postgres hold only variantGid, productHandle, quantity and usageNote (Spike S6 Option A) and the handout was static HTML with no hydration. The client page already hydrates names in the browser from /products/<handle>.js; the handout now does the same.

Changes

  • app/lib/protocols/handout.js
    • Uses enriched titles when a resolver supplies them; otherwise renders "Loading product..." for lines with a productHandle, and "Unavailable product" otherwise (never "Item N").
    • Emits data-product-handle, data-variant-id and data-variant-gid on each tr.line-row.
    • Inline script fetches /products/<handle>.js on the storefront origin, matches the variant, sets the title, and shows an "Out of stock" or "Unavailable product" badge with strikethrough styling when relevant.
    • Print button: removed the inline onclick, so one click now opens one print dialog. The handler waits for hydration (rejections are caught) and uses an in-flight flag to ignore rapid repeat clicks.
    • escapeHtml stays on every interpolated value.
  • app/lib/protocols/routes.js: /apps/protocols?handout=1 without a token now returns 404.

Verification

  • npm test: 599 passing, 0 failing.
  • New unit tests: no "Item N" fallback, placeholder and data attributes, unavailable styling, no inline onclick, exactly one window.print( call site, and no {{, }}, {% or %} anywhere in the output (the page is served as application/liquid).
  • New route tests: stub resolver returns names, production wiring (variantResolver: undefined), unavailable variants, cross-shop token returns 404, missing token returns 404.
  • Independently checked by rendering the real handout in a DOM with stubbed /products/*.js responses: names resolved, unavailable and out-of-stock rows badged, one click gave one print call, a rapid double click gave one, and failed fetches still printed once.

Known limitations

  • Names need JavaScript. With JS disabled the handout shows "Loading product..." (same as the client page).
  • If a /products/<handle>.js request never returns, the Print button waits on it (follow-up: cap the wait at about 3 seconds).
  • Out-of-stock and unavailable items are struck through and badged at print time.
  • A single-variant product whose variant title equals its product title reads "Name - Name", same as the client page today. Out of scope here.

Constraints

  • No new Admin scopes (read_orders only), no new database columns, no stored title snapshots, no client-identifying data, no new dependencies.

@arsalan-arshad
arsalan-arshad merged commit 1d46bfb into main Nov 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant