From cf10e9a2d6a61208774ed41e4d24a5941ba1dac1 Mon Sep 17 00:00:00 2001 From: giles Date: Thu, 9 Apr 2026 21:28:58 +0000 Subject: [PATCH] =?UTF-8?q?Fix:=20load=20HS=20modules=20as=20bytecode,=20n?= =?UTF-8?q?ot=20source=20=E2=80=94=20restores=20IO=20suspension=20chain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reverts the source-loading workaround. Bytecode modules go through the VM which handles IO suspension (perform/wait/fetch) correctly. The endModuleLoad sync copies VM globals to CEK env, so eval-expr-cek in hs-handler can find hs-on/hs-toggle-class!/etc. All three HS examples fully working on live site: Toggle Color — toggle classes on click Bounce — add class, wait 1s (IO suspend+resume), remove class Count Clicks — increment counter, update innerHTML Co-Authored-By: Claude Opus 4.6 (1M context) --- hosts/ocaml/browser/sx-platform.js | 16 +++------------- shared/static/wasm/sx-platform.js | 16 +++------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/hosts/ocaml/browser/sx-platform.js b/hosts/ocaml/browser/sx-platform.js index 59b6c263..50bfa3a7 100644 --- a/hosts/ocaml/browser/sx-platform.js +++ b/hosts/ocaml/browser/sx-platform.js @@ -506,19 +506,9 @@ // will see it as already loaded and skip rather than infinite-looping. _loadedLibs[name] = true; - // Load this module. - // Non-library modules (no space in name, e.g. "hs-runtime") use source - // loading so their defines go into the CEK global env — needed when - // eval-expr-cek evaluates compiled hyperscript at runtime. - var isLibrary = name.indexOf(' ') >= 0 || name === '_entry'; - var ok; - if (isLibrary) { - ok = loadBytecodeFile("sx/" + info.file); - if (!ok) { - var sxFile = info.file.replace(/\.sxbc$/, '.sx'); - ok = loadSxFile("sx/" + sxFile); - } - } else { + // Load this module (bytecode first, fallback to source) + var ok = loadBytecodeFile("sx/" + info.file); + if (!ok) { var sxFile = info.file.replace(/\.sxbc$/, '.sx'); ok = loadSxFile("sx/" + sxFile); } diff --git a/shared/static/wasm/sx-platform.js b/shared/static/wasm/sx-platform.js index 59b6c263..50bfa3a7 100644 --- a/shared/static/wasm/sx-platform.js +++ b/shared/static/wasm/sx-platform.js @@ -506,19 +506,9 @@ // will see it as already loaded and skip rather than infinite-looping. _loadedLibs[name] = true; - // Load this module. - // Non-library modules (no space in name, e.g. "hs-runtime") use source - // loading so their defines go into the CEK global env — needed when - // eval-expr-cek evaluates compiled hyperscript at runtime. - var isLibrary = name.indexOf(' ') >= 0 || name === '_entry'; - var ok; - if (isLibrary) { - ok = loadBytecodeFile("sx/" + info.file); - if (!ok) { - var sxFile = info.file.replace(/\.sxbc$/, '.sx'); - ok = loadSxFile("sx/" + sxFile); - } - } else { + // Load this module (bytecode first, fallback to source) + var ok = loadBytecodeFile("sx/" + info.file); + if (!ok) { var sxFile = info.file.replace(/\.sxbc$/, '.sx'); ok = loadSxFile("sx/" + sxFile); }