Skip to content

Commit 2b0906d

Browse files
committed
Fix dual-module bug in playground dev rewrite
The playground's dev-mode rewrite sent 'squint-cljs/core.js' through /js/squint-local/core.js (the 38-byte root shim that re-exports from ./src/squint/core.js). Vite transformed that shim's relative import into a /@fs/.../src/squint/core.js URL. Meanwhile the same import inside already-served runtime files (test.js, multi.js, etc.) was left as a bare specifier and resolved by the browser via the importmap to /src/squint/core.js. Two URLs, same file — and ES-module caching treats them as two separate modules. Each gets its own _metaSym; with-meta written through the user side becomes invisible to meta reads inside the runtime, which is why deftest'd tests surfaced as 'anonymous' in :begin-test-var events. Rewrite 'squint-cljs/{,src/squint/}X' straight to /src/squint/X so user code and importmap-resolved imports converge on one URL, one module instance. Confirmed against a live Vite+Playwright repro: before, sameModule=false; after, sameModule=true and deftest names surface correctly end-to-end.
1 parent df5a87e commit 2b0906d

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

playground/public/js/main_js.mjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,18 @@ let evalCode = async (code) => {
108108
// opaque origin that can't resolve relative specifiers. Anchor on the
109109
// page origin — import.meta.url can point to an unexpected bundle path
110110
// under Vite.
111-
const localBase = `${window.location.origin}/js/squint-local/`;
112-
js = js.replaceAll("'squint-cljs/", `'${localBase}`);
111+
//
112+
// Route everything through /src/squint/ (matching the importmap) so
113+
// user-compiled code and the runtime modules (test.js, multi.js) end
114+
// up importing the SAME URL for core.js. Previously user code went
115+
// via /js/squint-local/core.js → Vite-transformed shim →
116+
// /@fs/.../src/squint/core.js, while the runtime's bare specifier
117+
// resolved via the importmap to /src/squint/core.js — two URLs,
118+
// two ES-module instances, two _metaSym symbols, and with-meta
119+
// written through one was invisible to meta in the other.
120+
const base = `${window.location.origin}/src/squint/`;
121+
js = js.replaceAll("'squint-cljs/src/squint/", `'${base}`);
122+
js = js.replaceAll("'squint-cljs/", `'${base}`);
113123
}
114124
JSEditor(js);
115125
if (!repl) {

0 commit comments

Comments
 (0)