Skip to content

fix(printer): use @page size:auto so thermal receipts print full-size#625

Draft
kilbot wants to merge 1 commit into
mainfrom
fix/receipt-print-page-size
Draft

fix(printer): use @page size:auto so thermal receipts print full-size#625
kilbot wants to merge 1 commit into
mainfrom
fix/receipt-print-page-size

Conversation

@kilbot

@kilbot kilbot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Problem

After updating to a 1.9.x build, printing to a thermal receipt printer via the system print dialog produces a tiny, unreadable receipt floated at the top of the page instead of one that fills the 80mm roll.

Root cause

buildPrintableReceiptHtml emitted @page { size: 80mm } (or 58mm) for thermal templates. A single length in the CSS size descriptor sets both page dimensions → an 80mm × 80mm square page (verified in headless Chromium: the generated HTML renders to an 80.1×80.1mm PDF). Electron prints through the interactive window.print() dialog (apps/electron/src/main/print-external-url.ts, via a data: URL from system-print-adapter.electron.ts), which honours @page; the browser then shrinks that square onto the printer's real roll paper (80 (72) × 297mm) → the tiny result.

Why the previous value wasn't the fix either

Before a499ded9c, this emitted ${paperWidth} auto (80mm auto). But the @page size grammar is <length>{1,2} | auto | <page-size> — there is no "length + auto" form. 80mm auto is invalid; browsers ignore it and fall back to Letter/A4 (confirmed: 215.9×279.4mm). That was the P1 Codex finding on #429, which a499ded9c "fixed" by switching to the valid-but-square 80mm. So:

Value Valid? Result
80mm auto (pre-a499ded9c) ❌ invalid ignored → prints on Letter/A4 (tiny)
80mm (shipped v1.9.0–v1.9.6) ✅ valid 80mm square → tiny/chopped
auto (this PR) ✅ valid uses the printer's roll paper, content shrink-fits to the roll width

CSS @page size cannot express a fixed-width, content-height page, so we defer to the printer's own paper.

Fix

Emit @page { size: auto; margin: 0; } for thermal templates (A4 unchanged). The browser uses the thermal printer's selected roll paper (e.g. 80×297mm) and shrink-fits the receipt content to the roll width.

Tradeoff: this relies on the user's printer being set to its thermal roll paper (which it is for a thermal printer). It does not force an 80mm width if a thermal template is sent to an A4 printer — an uncommon case. A width-forcing alternative would require measuring the rendered height and emitting a valid two-length size: 80mm <height>mm, which needs changes in the Electron main print flow (submodule) and was deliberately deferred.

Testing

  • packages/printer vitest: 409 passed, incl. updated assertions that thermal emits size: auto and guards against both broken forms (80mm square and invalid 80mm auto); added 58mm coverage.
  • pnpm run lint — 0 errors; pnpm typecheck --force — passes.
  • Reproduced the square page box (80.1×80.1mm) and the invalid-auto Letter fallback (215.9×279.4mm) in headless Chromium.

⚠️ Remaining validation

Headless/PDF backends don't model a thermal printer's roll paper, so the size: auto render must be confirmed on a real thermal printer (e.g. the PRP-250C in the original report) before release. This is the one step I can't do here.

Merchant workaround (no update needed)

  • Settings → Printing → switch the receipt template back to the standard/A4 template, or
  • configure the thermal printer as a direct ESC/POS connection (Network / USB / Bluetooth), which bypasses this HTML print path entirely.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kilbot has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The pageSize computation for thermal (non-a4) receipt widths in buildPrintableReceiptHtml was changed to append "auto" to the width value, allowing flowing height instead of a fixed square page size. Corresponding tests were updated to reflect this new @page sizing string.

Changes

Thermal page sizing fix

Layer / File(s) Summary
Page sizing logic and test updates
packages/printer/src/print-html.ts, packages/printer/src/__tests__/print-html.test.ts
pageSize for thermal widths now uses "<width> auto" instead of a fixed width, with a comment explaining the fix; tests for 80mm/58mm and prepareSystemPrintHtml updated to expect the new @page sizing string.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Poem

A rabbit hopped to print a bill,
The paper squished, undersized still.
"Auto height!" the rabbit cried,
Now receipts flow long and wide.
Tests confirm the fix held tight — 🐇🧾

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: changing thermal receipt printing to use @page size:auto for full-size output.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/receipt-print-page-size

Comment @coderabbitai help to get the list of available commands.

@kilbot kilbot marked this pull request as draft July 6, 2026 11:21
@kilbot

kilbot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

⚠️ Hold — do not merge as-is. This restores @page { size: 80mm auto }, but per CSS Paged Media the size descriptor has no <length> auto form — it's invalid syntax that browsers ignore, falling back to Letter/A4 (confirmed: headless Chromium renders the generated HTML at 215.9×279.4mm). That's exactly the bug Codex flagged as P1 on #429, which a499ded9c fixed by switching to a valid single length 80mm.

The real problem: CSS @page size cannot express "fixed width, content-driven height". 80mm (valid) → 80mm square → the tiny-receipt bug; 80mm auto (invalid) → ignored → Letter. Both wrong.

Reworking toward a spec-valid fix (either size: auto to honour the printer's selected roll paper, or a two-length size with a real/measured height). Converting to draft.

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

📊 Test Coverage Report

Package Statements Branches Functions Lines
@wcpos/core 🔴 23.1% 🔴 26.9% 🔴 22.3% 🔴 22.6%
@wcpos/components 🔴 24.6% 🔴 27.3% 🔴 16.8% 🔴 24.3%
@wcpos/database 🟡 60.2% 🔴 55.0% 🟡 62.7% 🔴 59.7%
@wcpos/hooks 🔴 52.4% 🔴 50.1% 🔴 45.0% 🔴 52.4%
@wcpos/utils 🔴 55.9% 🟡 61.5% 🟡 71.4% 🔴 53.8%
@wcpos/query 🟢 83.9% 🟡 76.9% 🟡 77.7% 🟢 84.0%
Average 🔴 50.0% 🔴 49.6% 🔴 49.3% 🔴 49.5%
Coverage Legend
  • 🟢 Good (≥80%)
  • 🟡 Moderate (60-79%)
  • 🔴 Needs improvement (<60%)
  • ⚪ No coverage data
--- 🤖 Updated by GitHub Actions • [View full report](https://github.com/wcpos/monorepo/actions/runs/28787520448)

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployment Summary

Item Status
Preview URL ❌ Failed to deploy
E2E Tests ⏭️ Skipped
Commit a0d6d41

🤖 Updated by GitHub Actions

The system/HTML print path emitted `@page { size: 80mm }` (or 58mm) for
thermal receipt templates. A single CSS length in the `size` descriptor sets
*both* page dimensions, so the page box became an 80mm×80mm square. Electron
prints via the interactive `window.print()` dialog, which honours `@page`, then
shrinks that square onto the printer's roll paper (e.g. 80×297mm), rendering the
receipt tiny and unreadable.

The previous value `${paperWidth} auto` is not a fix either: the `@page size`
grammar is `<length>{1,2} | auto | <page-size>`, so `80mm auto` is invalid and
browsers ignore it, falling back to Letter/A4 (this was the P1 Codex finding on
#429 that a499ded changed to the square `80mm`). CSS cannot express a
fixed-width, content-height page.

Emit `size: auto` for thermal so the browser uses the thermal printer's own
roll paper and shrink-fits the content to the roll width. Update the print-html
tests to assert `size: auto` and guard against both broken forms; add 58mm
coverage. Ships broken in v1.9.0–v1.9.6.

Final on-device confirmation on a real thermal printer still recommended.
@kilbot kilbot force-pushed the fix/receipt-print-page-size branch from fbb7aee to e17e833 Compare July 6, 2026 16:38
@kilbot kilbot changed the title fix(printer): restore auto page height so thermal receipts print full-size fix(printer): use @page size:auto so thermal receipts print full-size Jul 6, 2026
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