Repository navigation
fix(build): pin the entry files to revalidate instead of going stale - #151
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: |
4efeef2
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://81271672.sahajatlas-design.pages.dev |
| Branch Preview URL: | https://fix-loader-cache-headers.sahajatlas-design.pages.dev |
Deploying sahajatlas with
|
| Latest commit: |
4efeef2
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://1be7b41d.sahajatlas.pages.dev |
| Branch Preview URL: | https://fix-loader-cache-headers.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]>
Ardnived
force-pushed
the
fix/loader-cache-headers
branch
from
August 14, 2026 17:25
61a5e81 to
2d48faa
Compare
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]>
Ardnived
force-pushed
the
fix/loader-cache-headers
branch
from
August 14, 2026 22:42
2d48faa to
c34747d
Compare
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]>
Ardnived
force-pushed
the
fix/loader-cache-headers
branch
from
August 18, 2026 15:18
c34747d to
b6f8011
Compare
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]>
`public/_headers` deliberately left `embed.js` outside the `/assets/*` immutable rule and said in a comment that it "must stay revalidated". Nothing enforced it, so the platform default applied — and the default is per-host: sahajatlas.com public, max-age=14400, must-revalidate sahajatlas.pages.dev public, max-age=0, must-revalidate Four hours of freshness on an unhashed file that imports content-hashed chunks by name is precisely the failure docs/embedding.md warns hosts about: a stale loader asks for chunk names the deploy no longer serves, and the widget dies with no fallback. It was invisible because every check anyone had run was against `pages.dev`, the host that already behaved. Pins `Cache-Control: public, max-age=0, must-revalidate` and `Access-Control-Allow-Origin: *` on all three root entry files. CORS is pinned for the reason the neighbouring rules give: a type="module" script is fetched in CORS mode, so a rendering requirement should not rest on a platform default. Adds a smoke spec, because this is a deploy-time fact no local gate can see. It asserts the parsed max-age rather than the header string, so it describes the property rather than a spelling; it asserts content type rather than status, since `_redirects` answers 200 text/html for a missing file; and it checks the `/*` noindex rule still coexists, since Pages applies every matching rule and joins repeated values with a comma. This is Part 1 of #148. Part 2 — repointing atlas.sydevelopers.com and retiring the legacy `syatlas` project — is deliberately NOT here: those origins are serving live clients the previous version of the app and must keep doing so until this rewrite is stable. Part of #148 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Ardnived
force-pushed
the
fix/loader-cache-headers
branch
from
August 18, 2026 16:00
b6f8011 to
4efeef2
Compare
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.
Part 1 of #148. Stacked on #150 — the header rule names the entry files that PR creates, so
review/merge that one first.
The defect
public/_headersdeliberately leftembed.jsoutside the/assets/*immutable rule and said ina comment that it "must stay revalidated". Nothing enforced it, so the platform default applied
— and the default is per-host:
Cache-Controlon the entry filesahajatlas.compublic, max-age=14400, must-revalidatesahajatlas.pages.devpublic, max-age=0, must-revalidateFour hours of freshness on an unhashed file that imports content-hashed chunks by name is
precisely the failure
docs/embedding.mdwarns hosts about: a stale copy asks for chunk names thedeploy no longer serves, and the widget dies with no fallback.
It went unnoticed because every check anyone had run was against
pages.dev— the host thatalready behaved. A comment stating an intention is not a mechanism.
The fix
Pins
Cache-Control: public, max-age=0, must-revalidateandAccess-Control-Allow-Origin: *onall three root entry files.
max-age=0rather thanno-storebecause a conditional request thatanswers 304 is cheap, and it keeps the browser cache useful while making staleness impossible.
CORS is pinned for the reason the neighbouring rules already give: a
type="module"script isfetched in CORS mode, so a rendering requirement should not rest on a platform default.
The smoke spec
This is a deploy-time fact no local gate can see —
_headersis inert text until Cloudflare Pagesreads it out of the build output. Three properties, each chosen to describe behaviour rather than
spelling:
max-age, not the header string, so a future rule could sayno-cacheor adds-maxagewithout a false failure — andimmutableis asserted absent._redirectsanswers 200text/htmlfor a missingfile, so a status check would pass while every header assertion described an HTML page.
/*noindex rule still coexists, since Pages applies every matching rule andjoins repeated values with a comma.
What is NOT here, and why
Part 2 — repointing
atlas.sydevelopers.comand retiring the legacysyatlasproject — isdeliberately excluded. Those origins are serving live clients the previous version of the app,
and must keep doing so until this rewrite is stable. Consolidation is the programme's final step,
not a prerequisite; #148 stays open for it.
One consequence worth carrying to that day: because the legacy origins hold all the real traffic,
sahajatlas.comwill reach cutover having been exercised by nobody. The switch needs its ownend-to-end verification rather than an assumption that live use already found the problems.
Verification
lint,typecheck,test:run,build,size,ladle:build,audit:checkall green. Thebuilt
dist/_headerswas checked to carry the new rules verbatim, since Pages reads it from theoutput rather than the repo.
🤖 Generated with Claude Code