From b95e34130f416388f9333fa57fde32e7156ec60d Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sat, 1 Aug 2026 10:50:20 +0200 Subject: [PATCH 1/3] Fix watch mode never executing new code with --workers=1 --- lib/Supervisor.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Supervisor.js b/lib/Supervisor.js index 43fcbd38..c8155757 100644 --- a/lib/Supervisor.js +++ b/lib/Supervisor.js @@ -272,6 +272,8 @@ function run(elmTestVersion, pipeFilename, report, processes, dest, watch) { // If just one process, run single-threaded. if (processes === 1) { var { run } = require(dest); + // Allow the generated file to be `require`d again (for watch mode). + delete require.cache[dest]; var send = run( 0, /** @type { (response: any) => void } */ From 59d95a997f06eaa065daae54c2f9e391478e7c76 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sat, 1 Aug 2026 10:50:30 +0200 Subject: [PATCH 2/3] Fix watch mode failing after first reload with --workers=1 Previously, we were accidentally writing `Elm` to the global object, and Elm has checks in place for this: > Your page is loading multiple Elm scripts with a module named Elm.Test.Generated.Main. Maybe a duplicate script is getting loaded accidentally? If not, rename one of them so I know which is which! This commit fixes the wrapper around the Elm JS code so that we write to a temporary, local object instead. --- lib/Generate.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Generate.js b/lib/Generate.js index c2e799f2..bb47c4cf 100644 --- a/lib/Generate.js +++ b/lib/Generate.js @@ -23,10 +23,10 @@ function prepareCompiledJsFile(pipeFilename, dest) { const content = fs.readFileSync(dest, 'utf8'); const finalContent = ` ${before} -var Elm = (function(module) { +var Elm = (function() { ${patch(content)} return this.Elm; -})({}); +}).call({}); var pipeFilename = ${JSON.stringify(pipeFilename)}; ${after} `.trim(); From dca4feec3a3ad7b2e335d09344c2c5e1a2a04196 Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Sat, 1 Aug 2026 12:38:31 +0200 Subject: [PATCH 3/3] Fix memory leak in single-threaded watch mode --- templates/after.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/after.js b/templates/after.js index 0689d426..05898f84 100644 --- a/templates/after.js +++ b/templates/after.js @@ -1,5 +1,7 @@ function run(index, receive) { var app = Elm.Test.Generated.Main.init({ flags: index }); + // Without this, each run leaks memory in single-threaded mode: + Elm = null; app.ports.elmTestPort__send.subscribe(receive); return app.ports.elmTestPort__receive.send; }