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
This commit is contained in:
swdee 2026-02-19 12:19:46 +13:00
parent 4865f07a09
commit c5ea4d243f

View file

@ -30,6 +30,7 @@ export default class extends Controller {
_submitting = false; _submitting = false;
_lastDecodedText = ""; _lastDecodedText = "";
_onInfoChange = null; _onInfoChange = null;
_onFormSubmit = null;
connect() { connect() {
// Prevent double init if connect fires twice // Prevent double init if connect fires twice
@ -44,6 +45,22 @@ export default class extends Controller {
info.addEventListener("change", this._onInfoChange); 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; const isMobile = window.matchMedia("(max-width: 768px)").matches;
//This function ensures, that the qrbox is 70% of the total viewport //This function ensures, that the qrbox is 70% of the total viewport
@ -90,6 +107,13 @@ export default class extends Controller {
} }
this._onInfoChange = null; 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; if (!scanner) return;
try { try {