Skip to content

fix(print): keep menu popup open until print - #1380

Merged
khaira777 merged 2 commits into
mainfrom
fm/flocafe-menu-web-print-popup-lifecycle
Oct 26, 2026
Merged

khaira777 merged 2 commits into
mainfrom
fm/flocafe-menu-web-print-popup-lifecycle

Conversation

@khaira777

@khaira777 khaira777 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1369

Intent

Fix the P1 release-readiness regression from PR #1352 (#1352) at frontend/src/lib/printer/menu-web-print.ts:120 and frontend/src/components/products/PrintMenuModal.tsx:355-374: preserve the popup until menu printing completes. Currently the load listener in printMenuInBrowser is attached before navigating to a new document and does not reliably invoke printing after navigation, and PrintMenuModal immediately closes reservedWindow in its finally block right after printOnPaper or savePdf returns synchronously, before the navigated document loads and prints. Preserve the popup until menu printing completes and invoke focus() and print() after the menu document loads.

What Changed

  • Updated printMenuInBrowser in frontend/src/lib/printer/menu-web-print.ts to navigate the popup window to the menu blob URL before tracking document load readiness, invoke focus() and print() once the navigated menu document finishes loading, and revoke the blob URL and close the window on afterprint or error cleanup.
  • Updated PrintMenuModal in frontend/src/components/products/PrintMenuModal.tsx to track when a reserved popup window is handed off to printMenuInBrowser across paper, PDF browser fallback, and receipt thermal fallback paths so the finally block only closes reservedWindow when browser printing did not take ownership.
  • Added unit and modal lifecycle tests in tests/menu-printing.test.ts verifying post-navigation focus()/print() ordering, afterprint cleanup, and reservedWindow preservation or closure across all print destinations and failure paths.

Risk Assessment

✅ Low: The change is well-bounded to the browser menu print popup lifecycle in menu-web-print.ts and PrintMenuModal.tsx, directly addressing the regression from PR #1352 with behavioral unit tests covering paper, PDF fallback, receipt fallback, and error/empty-catalog cleanup paths.

Testing

Ran npm run test:script-coverage and npm run test:menu-printing (all 13 unit/integration tests passing), built the backend and static frontend, ran the existing Playwright e2e/menu-printing.spec.ts suite, and drove all five popup-lifecycle scenarios live in Chromium against tests/e2e-server.cjs without stubbing window.close while capturing eight visual screenshot artifacts.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Operator selects Paper (A4 / Letter) with descriptions and modifiers and clicks Print Menu; the reserved popup stays open across blob navigation, invokes focus() and print() after the menu document fi… ✅ pass live ~/.no-mistakes/evidence/01M5WHPBM6JXYZEG0ZCF41SQMP/scenario1-paper-print-popup-open.png
Operator selects Save as PDF in a browser without the Electron PDF bridge and clicks Save as PDF; the reserved popup stays open until the A4 blob menu document loads, invokes focus() and print(), and… ✅ pass live ~/.no-mistakes/evidence/01M5WHPBM6JXYZEG0ZCF41SQMP/scenario2-pdf-fallback-popup-open.png
Operator selects Receipt printer when the thermal print endpoint fails with HTTP 502; PrintMenuModal falls back to browser printing using the gesture-reserved popup without closing it prematurely, inv… ✅ pass live ~/.no-mistakes/evidence/01M5WHPBM6JXYZEG0ZCF41SQMP/scenario3-receipt-fallback-popup-open.png
When browser printing does not take ownership of the gesture-reserved popup (no matching products to print or thermal receipt printing succeeds directly), PrintMenuModal closes the unused reservedWind… ✅ pass live ~/.no-mistakes/evidence/01M5WHPBM6JXYZEG0ZCF41SQMP/scenario4-unused-popup-closed-empty-catalog.png
When the browser blocks popups (window.open returns null), clicking Print Menu catches MenuPopupBlockedError, shows the popup-blocked error toast, and keeps the Print Menu dialog open ✅ pass live ~/.no-mistakes/evidence/01M5WHPBM6JXYZEG0ZCF41SQMP/scenario5-blocked-popup-error-toast.png

Paper menu print popup open after blob navigation with focus() and print() invoked on loaded Letter document
Save as PDF browser fallback popup preserved across A4 blob document navigation and printing
Receipt printer 502 failure fallback to browser printing in preserved reserved popup
Unused reserved popup closed immediately and error toast shown when no products match criteria
Blocked popup surfaces MenuPopupBlockedError toast while keeping Print Menu dialog open
E2E Letter browser menu preview from e2e/menu-printing.spec.ts
E2E Receipt destination configuration in Print Menu modal from e2e/menu-printing.spec.ts
E2E A4 PDF browser preview from e2e/menu-printing.spec.ts

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Operator selects Paper (A4 / Letter) with descriptions and modifiers and clicks Print Menu; the reserved popup stays open across blob navigation, invokes focus() and print() after the menu document fi… ✅ pass live ~/.no-mistakes/evidence/01M5WHPBM6JXYZEG0ZCF41SQMP/scenario1-paper-print-popup-open.png
Operator selects Save as PDF in a browser without the Electron PDF bridge and clicks Save as PDF; the reserved popup stays open until the A4 blob menu document loads, invokes focus() and print(), and… ✅ pass live ~/.no-mistakes/evidence/01M5WHPBM6JXYZEG0ZCF41SQMP/scenario2-pdf-fallback-popup-open.png
Operator selects Receipt printer when the thermal print endpoint fails with HTTP 502; PrintMenuModal falls back to browser printing using the gesture-reserved popup without closing it prematurely, inv… ✅ pass live ~/.no-mistakes/evidence/01M5WHPBM6JXYZEG0ZCF41SQMP/scenario3-receipt-fallback-popup-open.png
When browser printing does not take ownership of the gesture-reserved popup (no matching products to print or thermal receipt printing succeeds directly), PrintMenuModal closes the unused reservedWind… ✅ pass live ~/.no-mistakes/evidence/01M5WHPBM6JXYZEG0ZCF41SQMP/scenario4-unused-popup-closed-empty-catalog.png
When the browser blocks popups (window.open returns null), clicking Print Menu catches MenuPopupBlockedError, shows the popup-blocked error toast, and keeps the Print Menu dialog open ✅ pass live ~/.no-mistakes/evidence/01M5WHPBM6JXYZEG0ZCF41SQMP/scenario5-blocked-popup-error-toast.png
  • npm run test:script-coverage
  • npm run test:menu-printing
  • npm run build && npm run build:frontend
  • cd frontend && E2E_BASE_URL=http://127.0.0.1:43001 E2E_KDS_BASE_URL=http://127.0.0.1:43002 E2E_SERVER_APP_BASE_URL=http://127.0.0.1:43003 FLO_E2E_EVIDENCE_DIR=~/.no-mistakes/evidence/01M5WHPBM6JXYZEG0ZCF41SQMP npx playwright test --config=playwright.config.ts --project=chromium e2e/menu-printing.spec.ts
  • Live Playwright Chromium verification against tests/e2e-server.cjs (without stubbing window.close) exercising Paper print, Save as PDF browser fallback, Receipt 502 fallback to browser printing, unused reservedWindow cleanup on empty catalog and direct thermal success, and MenuPopupBlockedError toast handling
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Attach the menu popup load listener after navigating to the blob URL, invoke focus() and print() once the menu document loads, and only revoke the blob URL and close the popup on afterprint. In PrintMenuModal, keep reservedWindow open when printMenuInBrowser takes ownership and close it only when browser printing does not start.

Fixes #1369
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@khaira777 khaira777 changed the title fix(frontend): preserve menu print popup until browser printing completes fix(print): keep menu popup open until print Oct 26, 2026
@khaira777
khaira777 enabled auto-merge (squash) October 26, 2026 19:12
@khaira777
khaira777 merged commit 76cf1cc into main Oct 26, 2026
38 of 41 checks passed
@khaira777
khaira777 deleted the fm/flocafe-menu-web-print-popup-lifecycle branch October 26, 2026 19:27
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.

fix(print): menu browser print closes popup before document loads and prints

1 participant