Repository navigation
feat(widget): split the embed into a smart loader and an element bundle - #150
Merged
Merged
Conversation
The snippet is now one script tag, and configuration rides on its URL: <script type="module" src="https://…/auto.js?key=…&map=false"></script> `<sahaj-atlas>` and all nine attributes are gone. The loader creates the element where the tag sits and reads every setting off its own `src`. Three entries: `auto.js` (the loader), `embed.js` (the element bundle it imports dynamically), and `embed.classic.js` (a non-module bridge for Wix's Custom Element and any platform that cannot set type="module"; emitted by a plugin because output format is a whole-build setting). Why the URL rather than attributes: WordPress `wp_kses` strips <script> and unknown attributes for anyone below Administrator — and for every Site Administrator on multisite — while Wix supplies a bare script URL plus its own attribute panel. One mechanism on the URL behaves identically on all of them, and the only thing a sanitizer can now destroy is the whole snippet, which is a visible failure rather than a widget that mounts half-configured. Measured: a host now pays 3.0 KiB gz instead of 372.2 KiB up front, with the widget fetched only as the element nears the viewport. `pnpm size` gains a `loader` graph budgeted an order of magnitude tighter than the other two, plus an assertion that `embed.js` is never reachable from `auto.js` by a STATIC import — that seam is the whole split, and losing it would look fine while silently restoring the full eager payload. Also: teardown now waits a moment before releasing the API key and clearing the query cache. Moving a node fires disconnect then connect, and Elementor's "Optimized Markup" does exactly that, so a builder rearranging its canvas was wiping an hour of warm cache mid-session. The reason the teardown exists — an element re-added under a different key must not authenticate as the first — is unchanged, so it is deferred rather than removed. The loader duplicates rather than imports the few values it shares with the widget, since one value import would put a shared chunk between the graphs and undo the split; `src/loader/literals.test.ts` pins the copies, including a behavioural pin of `safeLoaderPath` against `safePath` over the hostile-input table and of the false/0 rule against `attributeEnabled`. Browser-verified against a real cross-origin host page: `embed.js` is not fetched until the element scrolls into view (3 JS files before, 16 after), and a remove/re-insert of the element re-renders with no ownership warning. Closes #149 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Deploying sahajatlas-design with
|
| Latest commit: |
9830876
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d67828b5.sahajatlas-design.pages.dev |
| Branch Preview URL: | https://feat-smart-loader.sahajatlas-design.pages.dev |
Deploying sahajatlas with
|
| Latest commit: |
9830876
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://dab92626.sahajatlas.pages.dev |
| Branch Preview URL: | https://feat-smart-loader.sahajatlas.pages.dev |
…dgetable The loader budget as first written was 3.4 KiB against a measured 3.0 — and a credentialed build ships 3.5, so PRODUCTION would have failed a gate CI cannot reproduce. Exactly the interaction CLAUDE.md warns about, hit on the first small graph this repo has ever budgeted. Measured, uncredentialed vs credentialed: standalone 370.2 -> 372.3 (+2.1) embed 372.2 -> 374.3 (+2.1) loader 3.0 -> 3.5 (+0.5) The absolute cost of the per-chunk debug-ID snippet is small; the RATIO is not, because it scales with chunk count rather than bytes. 0.5 KiB is 17% of the loader graph and 0.6% of the embed's. So on a graph this small the ratchet rule and the leave-headroom-for-Sentry rule are mathematically unsatisfiable together: a budget high enough to clear the credentialed build (>3.5) leaves spare that a flat 15% calls "far under budget", and the numbers satisfying both sit in a window about 0.03 KiB wide. That is a knife edge, not a budget, and the next person to touch the loader would have hit it with no idea why. SLACK_FLOOR_KIB = 1 resolves it without weakening anything. On the big graphs 15% is far larger and still governs, so their ratchet behaviour is byte-for-byte unchanged; the floor only applies where the percentage would be tighter than the known, unavoidable delta between what CI can measure and what production ships. Verified that the ratchet still fires on a genuine win in both regimes. Loader budget goes to 3.8, which clears the credentialed build with room and stays inside the floor. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Review feedback on #149. The configuration surface moves from twelve parameters to six — `key`, `locale`, `map`, `routing`, `atlas`, `compact` — by removing two whole classes of setting rather than porting them. **No privacy opt-outs.** `analytics`, `geolocation` and `error-reporting` are gone, and the `privacy` singleton with them; the three flows are unconditional. Each is designed so it does not need a switch: analytics is cookieless and aggregate, crash reports carry no cookies, breadcrumbs or session replay and reduce the host page to origin + path, and the location lookup is a keyless once-per-session city lookup whose answer is discarded. Recorded in `use-ip-location.ts` for whoever revisits it: an IP is personal data in the EU and the visitor is on the HOST's page, so if a host ever does need to refuse a flow, the answer is a client-record setting — the embed URL is not where somebody else's compliance posture should live, because anyone who can edit a page can change it. **Identity belongs to the client record.** `name`, `primary-color` and `secondary-color` are gone. A tenant's name and palette are the same on every page they embed on, so per-embed copies only create the opportunity for two pages of one site to disagree. **`mount` is gone, and cannot be auto-detected here.** Path routing needs to know which prefix of the pathname is the host's and which is the widget's, and on a deep link the loader sees `/map/nl/amsterdam` with no way to tell where the split is until the region tree loads. It is also the same value SahajCloud composes canonicals from, so a second copy on a script tag could disagree with the one the canonical was built from — and a canonical naming a URL that does not restore the view is the exact failure canonicals exist to prevent. It comes from the client record. `detect.ts` loses `mountMatches` with it and now reports what the page can support rather than claiming to have verified a server fact no client-side probe can see. **`base-path` becomes `atlas`, and becomes a default rather than an override.** A route already on the page's `?atlas=` always wins, because that is a visitor who deep-linked or followed a shared link; the script's value is the host saying "when nobody asked for anything, start here". Both sources go through `safeLoaderPath` — the page's is the more likely of the two to be adversarial. **Multiple embeds are NOT unblocked, and the reason is the URL.** Two widgets would both write the same `?atlas=` and fight over it on every navigation, so one-per-page stands until routing answers that. What removing `mount` did expose is a hole: `resolveElement` adopts any pre-existing element, which is right for Wix and wrong for a page carrying the snippet twice — the second loader would silently adopt the first one's widget and discard its own config. The loader now marks what it claims and refuses a claimed element with a console warning. Browser-verified: a page at `?atlas=/nl/amsterdam&p=123` with a script carrying `atlas=/gb/london` boots at `/nl/amsterdam`, the host's `p=123` survives untouched, and a duplicate snippet renders nothing and warns by name. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Review feedback on #149: why is `embed.classic.js` emitted by a bespoke plugin rather than built like `auto.js`? It shouldn't be — my justification was wrong. The plugin's docblock claimed output format is a whole-build setting, so one classic file could not come out of a module build. True in general, and beside the point here: **the shim has no imports and no exports, so there is no module syntax for the format to change.** It compiles to itself. Verified on the emitted artifact, which is byte-for-byte a plain IIFE-free statement list with no `import`, no `export` and no "use strict" wrapper. So it becomes `src/loader/classic.ts`, a third entry mapped to `embed.classic.js` by `entryFileNames` exactly as the loader is. That deletes `scripts/emit-classic-shim.mjs` and the hand-written source string inside it, and the file gains what every other source file has: typechecking, linting, minification, and a diff that reads as code rather than as a template literal. The real invariant was never about format — it is that this one file must stay free of module syntax, because it is the only module in the build that may be executed as a classic script, where `import` is a syntax error rather than a feature. Nothing enforced that before; the plugin merely made it true by construction, which is not the same as checking it. `check-bundle-size.mjs` now asserts the emitted file contains no module syntax, and the assertion was proven to bite by injecting an import into the artifact and watching the gate fail. That failure mode is otherwise invisible: the widget would break only on the platforms with no other route to it, and every other check would stay green. Browser-verified in a Wix-shaped install — a platform-created <sahaj-atlas> plus a non-module <script src="embed.classic.js?key=…&map=false&locale=fr">. The shim injected a module script for auto.js carrying the whole query string, the loader adopted the platform's element rather than creating a second, and the widget rendered. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
4 tasks
Removes `embed.classic.js`, reverting a94a567 and the shim it converted. The bridge existed for one case: a platform that writes the `<script>` tag itself and may not set `type="module"`. It is NOT about browser support — every browser in the bundle's floor does modules — and it does not apply to WordPress, Squarespace or Weebly, all of which have the host paste a full tag. The only candidate is Wix's Custom Element, which takes a bare Server URL. Whether Wix injects a module script is unverified, and could not be settled from outside: the docs never say, the editor offers no choice, and the runtime chunk that injects the script only loads on a page that actually uses a Custom Element — neither Wix client has one, so all 20 parastorage chunks on sahajayoga.ca/free-classes were fetched and none contains the dispatch. So it was a second documented install path justified by a belief we could not check, on a platform where — measured — no client currently embeds the atlas at all. Nothing live depends on it, and an unverified second way to do something is exactly what ossifies into a permanent one. Restoring it is a known ~15-line job if #152 finds it necessary: this commit's parent has the source, the build entry, the no-module-syntax assertion and the smoke coverage, all reviewed and browser-verified in a Wix-shaped install. `auto.js` deliberately keeps its two static imports rather than being made loadable as a classic script. Dropping them means dropping `__vitePreload`, which is what fetches the widget's chunks in parallel on reveal — a real waterfall traded for a hypothetical platform. Refs #152 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This was referenced Aug 18, 2026
Ardnived
added a commit
that referenced
this pull request
Aug 19, 2026
* feat(ui): de-brand the widget and keep host CSS out of it Stage B of the white-label programme, and the one that states the goal literally. The loader made the embed cheap (#150) and query routing made it indexable (#155); this is the part a visitor sees. **Nothing names the product any more.** The landmark's accessible name, the "on Sahaj Atlas" link on the share and registration cards, the app-level error title, the ICS `PRODID`, the page title and the typeface family — all neutral, across all ten locales. A ratchet spec walks the locale bundles and a named list of copy-carrying source files and fails if a brand string returns; it also asserts the pattern leaves `sahaj-atlas`, `sy-atlas` and the origins alone, because those are DOM identifiers hosts key off rather than copy. ⚠ `UID:event-<id>@atlas.sydevelopers.com` is deliberately unchanged and now says so at the line: it is the calendar dedupe key, and moving it would make every previously-exported event reappear as a second entry in somebody's calendar. **`EventSummary` is deleted**, carrying over the one Atlas-side piece of the blocked Stage C. It rendered both the brand label and an outbound link to `event.webUrl` — a link that was never correct, and that becomes a link from the host's page back to the host's page once canonicals point at the owning client. Without it the component was a two-call-site alias over `EventFacts`. **JSON-LD no longer credits We Meditate for every event in the world.** The organizer comes from the client record and is omitted entirely when unknown: an absent optional property is better structured data than a confidently false one. **Host CSS is kept out**, via an unlayered `all: revert` over the scope subtree plus an inherited-property baseline. Three things about it were verified in a browser rather than assumed, and two were wrong on the first attempt: - The baseline was written inside `@layer base` and therefore LOST to the unlayered reset directly above it — the widget rendered in the host's font with the host's letter-spacing. That is the `@layer` trap the rule's own comment warns about, fired at ourselves; it is unlayered now. - Against a deliberately hostile stylesheet, non-`!important` host rules are fully blocked. **`!important` rules are not**, and cannot be: outranking them needs `all: revert !important`, which would beat our own styles and leave the widget unstyled. Documented for hosts, and the reason #157 exists. - Cost measured rather than guessed: a forced recalc over 3,200 nodes inside the scope is ~2x one outside (41ms vs 20ms over five recalcs). Accepted — full recalcs are rare and the list is bounded by MAX_REVEAL. **And one bug fix that is not branding**: the `theme` localStorage key was the bare string `theme`, so a host page storing its own preference under that name had it read and overwritten. Namespaced to `atlas.theme`, with a one-time read of the old key so nobody loses a choice they already made. Closes #156 Refs #157 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * fix(test): stop pinning the SPA shell by its brand name The root smoke spec asserted `<title>Sahaj Atlas`, so de-branding the page title failed it. The spec was only ever trying to prove "this is our shell rather than an error page or the SPA fallback" — and a brand string is the wrong anchor for that, in the worst way: it breaks precisely when the product does what this programme set out to make it do. Re-anchored on two structural markers that are actually load-bearing — the `#syatlas` mount point and the `sy-atlas` scope class on <html> — plus a non-empty title, which is the part that genuinely distinguishes a rendered shell from a stray response. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * refactor(event): namespace the calendar UID to the CMS, not the widget host The back-compat constraint I stated does not apply — the calendar export is not live, so there are no already-exported entries to keep matching. Removing it does not make the UID free, though. A different rule survives and is the stronger one: **it must stay tenant-independent.** The same class can be exported from several client embeds — a visitor might reach it from the national site and again from a city one — and those must land in a calendar as ONE entry. Anything client-derived in this string turns each embed into a separate event for the same class. So it moves from `@atlas.sydevelopers.com` to `@cloud.sydevelopers.com`: the host part is an opaque namespace rather than a link, and the CMS is where the id actually comes from. The old value pointed at an origin that is being consolidated (#148) while the canonical moves to per-owner domains — neither of which should be able to change an identifier whose whole job is to stay put. The dedupe rule is now asserted rather than only described. Refs #156 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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.
Closes #149.
The snippet is now one script tag, and configuration rides on its URL:
<sahaj-atlas>and all nine attributes are gone. The loader creates the element where the tagsits and reads every setting off its own
src.What changed
Three entries.
auto.js(the loader),embed.js(the element bundle it imports dynamically),and
embed.classic.js— a non-module bridge for Wix's Custom Element and any platform thatcannot set
type="module". The shim is emitted by a plugin rather than built as a third Rollupentry because output format is a whole-build setting, and it bridges by injecting a module
<script>rather than callingimport():document.currentScriptis null inside a dynamicimport's callback, so an
import()bridge would lose the query string the whole configurationsurface rides on.
Why the URL rather than attributes. WordPress
wp_ksesstrips<script>and unknownattributes for anyone below Administrator — and for every Site Administrator on multisite —
while Wix supplies a bare script URL plus its own attribute panel. One mechanism on the URL
behaves identically on all of them, and the only thing a sanitizer can now destroy is the whole
snippet, which is a visible failure rather than a widget that mounts half-configured.
The measured win.
The widget is fetched only as the element nears the viewport. That lands directly on the host
page's LCP and INP, which are ranking signals for the pages the wider programme is trying to get
indexed.
Two gates.
pnpm sizegains aloadergraph budgeted an order of magnitude tighter than theother two, plus an assertion that
embed.jsis never reachable fromauto.jsby a staticimport. That seam is the whole split: replacing the dynamic
import()with a top-level one wouldlook fine and work fine, while silently restoring the full eager payload for every host. The
budget alone would catch it as a number; the assertion names the mistake.
A page-builder fix. Teardown now waits a moment before releasing the API key and clearing the
query cache. Moving a node fires disconnect then connect, and Elementor's "Optimized Markup" does
exactly that — so a builder rearranging its canvas was wiping an hour of warm cache mid-session
and refetching the whole feed. The reason the teardown exists (an element re-added under a
different key must not authenticate as the first) is unchanged, so it is deferred rather than
removed.
Element.moveBefore()does not help: no Safari support, and it is the host who wouldhave to call it.
Duplication, and why it is safe
The loader imports nothing from
src/at runtime — one value import would put a shared chunkbetween the graphs and undo the split. So a few values exist twice, and
src/loader/literals.test.tspins them: the element name, a behavioural pin ofsafeLoaderPathagainstsafePathover the whole hostile-input table (//evil.example, theleading backslash, TAB/LF/CR), and the
false/0rule againstattributeEnabled. Samearrangement
src/lib/scope.tsandscripts/postcss-scope-widget.test.tsalready use across thePostCSS boundary.
Verification
lint,typecheck,test:run(1132 passing, 109 new),build,size,ladle:build,audit:checkall green.Browser-verified against a real cross-origin host page, because the two properties that
matter most are not expressible in either lane:
16 after, with
embed.jsabsent from the first set and present in the second.configuration-error screen.
No jsdom spec was added. The detection predicate, the config parser and the report payload are
all pure and covered in the node lane; the parts that are not pure are agreements with a real
browser, and per this repo's own lesson a pure spec can only pin what our function decides, never
whether the runtime agrees.
Known residue, deliberately left
The widget still writes
#!to the host URL at boot (claimFragment). That is hash routing,which the routing ticket removes outright — this PR moves the configuration surface and changes
no routing behaviour.
base-pathis likewise parsed and passed through unchanged, so this dropsno existing capability on the way.
🤖 Generated with Claude Code