From c5ea4d243f7b7bb0eee3828454b53a3b3f1460e1 Mon Sep 17 00:00:00 2001 From: swdee Date: Thu, 19 Feb 2026 12:19:46 +1300 Subject: [PATCH] fix bug with manual form submission where a part does not exist but decodes properly which causes the camera to not redraw on page reload due to unclean shutdown. this is an existing bug in the scanner interface. steps to produce the issue: - have camera active - put in code in Input - info mode ticked - click submit button on page reload the camera does not reactivate --- .../pages/barcode_scan_controller.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/assets/controllers/pages/barcode_scan_controller.js b/assets/controllers/pages/barcode_scan_controller.js index 423f7b13..352c527c 100644 --- a/assets/controllers/pages/barcode_scan_controller.js +++ b/assets/controllers/pages/barcode_scan_controller.js @@ -30,6 +30,7 @@ export default class extends Controller { _submitting = false; _lastDecodedText = ""; _onInfoChange = null; + _onFormSubmit = null; connect() { // Prevent double init if connect fires twice @@ -44,6 +45,22 @@ export default class extends Controller { info.addEventListener("change", this._onInfoChange); } + // Stop camera cleanly before manual form submit (prevents broken camera after reload) + const form = document.getElementById("scan_dialog_form"); + if (form) { + this._onFormSubmit = () => { + try { + const p = this._scanner?.clear?.(); + if (p && typeof p.then === "function") p.catch(() => {}); + } catch (_) { + // ignore + } + }; + + // capture=true so we run before other handlers / navigation + form.addEventListener("submit", this._onFormSubmit, { capture: true }); + } + const isMobile = window.matchMedia("(max-width: 768px)").matches; //This function ensures, that the qrbox is 70% of the total viewport @@ -90,6 +107,13 @@ export default class extends Controller { } this._onInfoChange = null; + // remove the onForm submit handler + const form = document.getElementById("scan_dialog_form"); + if (form && this._onFormSubmit) { + form.removeEventListener("submit", this._onFormSubmit, { capture: true }); + } + this._onFormSubmit = null; + if (!scanner) return; try {