Repository navigation
fix(loader): auto.js runs as a classic script, so Wix can load it - #409
Merged
Merged
Conversation
Wix's Custom Element writes `<script src="…/auto.js?key=…">` into `<head>` with no `type`, observed on a live client site (sahajayoga.ca). `auto.js` was the ES-module loader, with a static import of rolldown's preload helper, so the browser threw "Cannot use import statement outside a module" and nothing of the widget ran. #152 asked exactly this question and was closed unanswered; #349 then documented the Custom Element path. `auto.js` is now a classic-script bridge (`src/loader/bridge.ts`, ~300 B gz) that inserts the loader as `<script type="module" src="loader.js?…">`. It works whichever way a host loads it, so the Wix Install tab and every existing snippet stay as they are. The loader keeps finding the host's `auto.js` tag for its settings and position, as it did when it ran as a module. - `pnpm build` now runs `assert:classic`: the built `auto.js` must compile as a classic script, start `loader.js` with the host's query and nonce both as a script and as a module, and leave nothing on the global object. The embed smoke spec runs the same audit on the deployed bytes. - `loader.js` is unhashed and revalidated like the other two root files. - The loader budget moves 3.2 → 3.6 KiB: 2.78 uncredentialed, 3.26 in an offline credentialed build, since the bridge is a chunk of its own. - The per-edit selection ceiling ratchets 21 → 22 for the new spec. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
This was referenced Nov 15, 2026
This was referenced Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A Wix client (sahajayoga.ca, testing at
/sahajatlastesting) followed the Install tab and got a blank page withUncaught SyntaxError: Cannot use import statement outside a module.Wix's Custom Element writes the Server URL as
<script src="https://sahajatlas.com/auto.js?key=…">in<head>, with notype. Observed in headless Chromium on their live page.auto.jswas the ES-module loader, starting with a staticimport … from "./assets/preload-helper-….js", so as a classic script it never parsed. This is the open question in #152 ("does Wix load it as a module or a classic script?"). That issue was closed without the test, and #349 then documented the Custom Element path as working.Their setup is otherwise correct:
<sahaj-atlas>is on the page at 1366×845, and their Velo router already reaches/api/atlas/wix/route.What changes
auto.jsis now a classic-script bridge (src/loader/bridge.ts, 300 B gz). It inserts<script type="module" src="loader.js?<same query>">, copying the host tag's nonce. It works whether the host loads it as a module or a classic script, so no snippet, Install tab, WordPress plugin or WeMeditateWeb change is needed.loader.js(unhashed, revalidated likeauto.jsandembed.js). It finds the host'sauto.jstag for its settings and position, which it already did when it ran as a module.assert:classic(part ofpnpm build, so a bad bridge can't deploy). It runs the builtauto.jsin avmcontext with a stub page:loader.jswith the host's query and nonce, both as a classic script and as a module;vite.config.tsalready accepts them.tests/smoke/embed.smoke.test.tsruns the same audit on the deployedauto.js, and checksloader.jsas the loader. Production smoke covers the credentialed build.docs/embedding.md:type="module"goes from "required" to "keep it", because a classic tag in the body blocks the host page's parsing.loader.js, and the caching notes cover all three root files.Performance
Measured with an A/B on WeMeditate's
/map, a full-page embed visible on load (the worst case for an extra hop). Each figure is the median of 5 runs, in ms:The extra request overlaps downloads the page already makes, so time to a working widget barely moves. Embeds below the fold pay nothing visible. I kept
loader.jsunhashed rather than hashing it to save the repeat-visit revalidation. The A/B above revalidated it on every visit and showed no effect on ready time, and hashing would need a post-hash rewrite ofauto.jsthat interacts withflattenEntryImportsand the source maps.Budgets
scripts/AGENTS.mdrecords the new +0.5 KiB gap.assert-classic-bridge.test.ts, which reads the bridge source throughrepo-source. The hook took 3.3 s for the widest edit and 4.4 s fori18n.ts, median of 3 runs on 11 cores. Both are recorded indocs/testing.md.Security notes (loader and headers paths touched)
new URL('./loader.js', script.src)plus that tag's own query string. It reads no other host input.script[src*="auto.js"], the same lookup the loader has used since feat(widget): split the embed into a smart loader and an element bundle #149. A page whose first match is some other vendor'sauto.jswould already lose its configuration today.[sahaj-atlas]prefix._headersgains oneCache-Controlrule for/loader.js, anddeploy-headers.test.tsstill holds the no-overlap rule.Test plan
.claude/skills/pr-prep/check.sh(lint, typecheck, 2080 unit tests)pnpm build(uncredentialed and offline-credentialed),pnpm size./literals, which creates a shared chunk. It also rejects today's productionauto.js("Cannot use import statement outside a module").embed.smoke.test.tspasses againstvite previewof this build and fails against today'ssahajatlas.com.sahajatlas.comon the client's live Wix page: Wix's classic tag insertedloader.jsas a module, the readiness marker was set, and the map rendered. The embed report and Sentry were blocked, so nothing was recorded against the client./map(atype="module"host): boots, with readiness marker.🤖 Generated with Claude Code