From 18f334a60e352f4c2f042e431cef2e9f769dd466 Mon Sep 17 00:00:00 2001 From: Joshua Horton Date: Wed, 9 Sep 2026 13:49:12 -0500 Subject: [PATCH] fix(web): handle 'unload' message while attempting model 'load' Fixes: KEYMAN-WEB-MD Build-bot: skip build:web Test-bot: skip --- .../predictive-text/worker-thread/src/main/index.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/web/src/engine/predictive-text/worker-thread/src/main/index.ts b/web/src/engine/predictive-text/worker-thread/src/main/index.ts index 262492674f..318256ba54 100644 --- a/web/src/engine/predictive-text/worker-thread/src/main/index.ts +++ b/web/src/engine/predictive-text/worker-thread/src/main/index.ts @@ -267,7 +267,11 @@ export class LMLayerWorker { try { this._importScripts(url); } catch (err) { + // Does not catch errors thrown within the imported script. + // Does catch errors with the model script's file-path. this.error("Error occurred when attempting to load dictionary", err); + + // Remain in the model-unloaded state; the load attempt was unsuccessful. } } @@ -312,7 +316,14 @@ export class LMLayerWorker { this.state = { name: 'modelless', handleMessage: (payload) => { - // ...that message must have been 'load'! + // It is possible to remain in this state after a model loading error. + // In such cases, the hosting engine may signal a model-unload. + if (payload.message === 'unload') { + // We are already in a "model unloaded" state; no work needed! + return; + } + + // ...otherwise, that message must have been 'load'! if (payload.message !== 'load') { throw new Error(`invalid message; expected 'load' but got ${payload.message}`); }