Repository navigation
fix(frontend): align browser labels with canonical print pipeline - #487
Merged
Merged
Conversation
Contributor
Greptile SummaryThe PR routes browser receipt labels and text direction through the shared PrintDocument language and catalog pipeline while retaining browser-specific wording and layout.
Confidence Score: 5/5The PR appears safe to merge, with no concrete changed-code defect identified in the supported browser printing paths. Current callers resolve nonempty validated language tuples, preload selected locale bundles where asynchronous loading is possible, and escape semantic labels before inserting them into receipt HTML; the updated tests cover supported RTL localization and catalog fallback.
|
| Filename | Overview |
|---|---|
| frontend/src/lib/printer/web-print.ts | Replaces the browser-specific translator path with resolved print languages, semantic document labels, canonical fallback resolution, and document-derived direction. |
| frontend/src/app/(dashboard)/print-test/page.tsx | Preloads resolved receipt-language bundles before synchronously generating downloadable test HTML. |
| tests/browser-receipts.test.ts | Adds coverage for canonical Persian browser labels and English fallback for an unknown language. |
| tests/print-parity.test.ts | Extends semantic parity checks to browser HTML catalog labels and fallback behavior. |
| docs/merchant-print-templates.md | Clarifies shared label resolution versus structural template fallback and links the responsible implementation and tests. |
| docs/printers.md | Documents the shared browser/WebUSB label resolver while preserving renderer-specific wording and layout differences. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
Policy[Receipt language policy] --> Resolver[resolveBillPrintLanguages]
Resolver --> Loader[ensurePrintLanguagesLoaded]
Resolver --> Bridge[Frontend PrintDocument bridge]
Loader --> Bridge
Bridge --> Document[Semantic PrintDocument]
Document --> Labels[Canonical label resolver]
Labels --> HTML[Browser receipt HTML]
Document --> Direction[Registry-derived direction]
Direction --> HTML
Reviews (1): Last reviewed commit: "no-mistakes(document): Clarify receipt p..." | Re-trigger Greptile
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.
Intent
Implement FloCafe issue #480 by aligning browser printing label resolution in frontend/src/lib/printer/web-print.ts with the canonical shared PrintDocument label pipeline used by the other semantic renderers. Route browser label lookup through the shared frontend PrintDocument bridge, canonical catalog resolver, receipt language policy, and registry-derived direction, while preserving existing browser user-visible output for supported locales, including Persian/RTL direction, localized labels, merchant-template label overrides where applicable, and unknown-label English fallback behavior. Keep browser/LAN printing independent of Electron APIs; preserve popup/print-preview and WebUSB behavior; do not alter ESC/POS transport bytes or unrelated printer profiles. Extend existing browser/semantic/parity printing tests for representative receipt and POS labels across supported locale/RTL paths plus fallback behavior, update the relevant printing capability documentation to narrow the browser-label exception and link the enforcing code/tests, and run focused printing tests, lint, backend/frontend builds, i18n checks, and required validation. Use a descriptive conventional PR title and PR body containing Fixes #480 Refs #438 Refs #444; do not merge the PR.
What Changed
PrintDocumentbridge, canonical catalog resolver, receipt-language policy, and registry-derived direction while preserving browser-specific wording, layout, and fallback behavior.Fixes #480
Refs #438
Refs #444
Risk Assessment
✅ Low: The scoped browser label refactor is bounded, preserves existing supported-locale wording and RTL behavior, routes through the shared policy/document resolver, and does not alter ESC/POS transport paths.
Testing
Exercised focused browser, PrintDocument, semantic parity, WebUSB, popup, merchant-template, receipt-policy, and locale-regression paths; captured reviewer-visible HTML/PNG evidence and removed test-created dependency directories. Repository-wide lint/build/static checks were not run because this assigned test phase explicitly prohibited them.
/Users/gurkiratkhaira/.no-mistakes/evidence/01M0QVVTNSK343VQRMP7PX3K6S/01_persian_receipt_rial_persian_digits.png)/Users/gurkiratkhaira/.no-mistakes/evidence/01M0QVVTNSK343VQRMP7PX3K6S/05_english_receipt_baseline.png)/Users/gurkiratkhaira/.no-mistakes/evidence/01M0QVVTNSK343VQRMP7PX3K6S/web_print_bill_fa_ir.png)/Users/gurkiratkhaira/.no-mistakes/evidence/01M0QVVTNSK343VQRMP7PX3K6S/popup_window_simulation.png)/Users/gurkiratkhaira/.no-mistakes/evidence/01M0QVVTNSK343VQRMP7PX3K6S/fallback_receipt_80mm_preview.png)Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 3 issues found → auto-fixed (2) ✅
frontend/src/lib/printer/web-print.ts:262-generateBillHtmlnow follows receipt policy, but onlyprintWebBillpreloads locale bundles. The direct HTML preview caller can therefore produce English labels with Persian RTL direction on a cold start when policy is fixed tofa. Preload resolved languages before synchronous preview generation.docs/printers.md:26- The documentation claims labels do not diverge by transport, but browser intentionally preserves wording such asGrand Totalversus WebUSBTOTAL. Document shared resolver parity while retaining surface-specific wording.docs/merchant-print-templates.md:201- The required intent asks for links to enforcing code/tests. The documentation namesweb-print.tsandprint-document.ts, but fallback warning ownership is inusePrinter.ts/warnings.ts, and the tests are referenced only generically. Please confirm correcting these links and owners.🔧 Fix: Fix preview locale preload and clarify label parity
1 warning still open:
docs/merchant-print-templates.md:202- The required intent says to “update the relevant printing capability documentation to narrow the browser-label exception and link the enforcing code/tests.” The new section namesweb-print.ts,print-document.ts, and generic browser/parity tests, but merchant-template fallback is actually produced byfrontend/src/hooks/usePrinter.tsusingfrontend/src/lib/printer/warnings.ts, with behavioral tests intests/printer.test.ts. Correct the documentation links and owners.🔧 Fix: Link merchant fallback ownership and behavioral coverage
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
EVIDENCE_DIR=... REQUIRE_VISUAL_EVIDENCE=1 npm run test:browser-receiptsnpm run test:print-paritynpm run test:print-documentnpm run test:print-labelsnpx ts-node --transpile-only -P tests/tsconfig.json tests/printer.test.tsnpm run test:merchant-print-templatesEVIDENCE_DIR=... npm run test:printer-fallback-and-popup-verificationEVIDENCE_DIR=... npm run test:i18n-audit-remediationsnpx ts-node --transpile-only -P tests/tsconfig.json tests/print-language-settings.test.tsnpm run test:decoupled-ui-localeVisual inspection of generated receipt and popup PNGs viaview_imageFinalgit status --short --untracked-files=alland transient-artifact cleanup✅ **Document** - passed
✅ No issues found.
eslint: command not found).✅ **Push** - passed
✅ No issues found.