Skip to content

fix(widget): three host conditions leave a blank slot, unreported - #240

Merged
Ardnived merged 4 commits into
mainfrom
fix/239-loader-blank-slot
Oct 1, 2026
Merged

Ardnived merged 4 commits into
mainfrom
fix/239-loader-blank-slot

Conversation

@Ardnived

@Ardnived Ardnived commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • A host that patches requestIdleCallback to throw, or never call back, now gets a mounted widget.
  • A failed embed.js load logs one [sahaj-atlas] line and leaves no unhandled rejection.
  • Both scope roots carry translate="no", so page translators no longer crash the widget.
  • docs/embedding.md names the stripped-type="module" failure, its symptom, and the fix.

Changes

  • src/loader/index.ts — whenIdle(): a 2 s deadline timer on both paths, a try/catch around requestIdleCallback, and a once-guard. This mirrors lib/embed-announce.ts, copied rather than imported across the seam. .catch on import('../Widget'). error() takes the browser's error as a second console argument.
  • src/loader/index.test.ts — new node-lane spec. It imports the real entry, whose top level is the host path, with ../Widget mocked at the seam.
  • src/Widget.tsx — translate="no" on BootSurface's root and on the theme wrapper.
  • src/Widget.translate.test.ts — walks Widget.tsx's AST and asserts that every element carrying WIDGET_SCOPE_CLASS has translate="no".

Contract impact

docs/embedding.md and CHANGELOG.md changed (host-observable):

  • New console line: [sahaj-atlas] could not load the widget …
  • Page translators skip the widget (translate="no").
  • Three new Troubleshooting rows: the stripped module type, the new console line, and a translator that ignores the attribute.

No new parameter, origin, CSP or Permissions-Policy change. Consumers to check: SahajAtlasWordpress. The stripped-module row is the failure its loopback check (sydevs/SahajAtlasWordpress#39) detects, so its message can link the row. WeMeditateWeb's /map host needs nothing.

Test results

  • Lean gate (.claude/skills/pr-prep/check.sh): ✓ lint, typecheck, test:run (127 files, 1626 tests)
  • Targeted specs: src/loader/index.test.ts 4 passed, src/Widget.translate.test.ts 2 passed
  • Each new case failed once against the unfixed code. Two had to be checked by reintroducing a defect at the site, because the unfixed code could not fail them:
    • Without the once-guard, boot runs twice.
    • With a .catch that rethrows, the unhandled-rejection assertion fails.
  • pnpm build: ✓ (assert:css, assert:maps)
  • pnpm size: ✓. loader 2.7 KiB / 3.5 (was 2.6 on main), embed 303.7 / 308, standalone 301.9 / 308. No shared chunk across the loader seam.

Manual verification

These checks ran in Playwright against pnpm build + pnpm review:embed on /__review/sidebar-mapless.html, with clients/me stubbed. Each ran on this branch and, as a control, on a build of main.

Check main this branch
requestIdleCallback throws (addInitScript) no .sy-atlas, pageerror: host patch mounted, 0 pageerrors
requestIdleCallback never calls back no .sy-atlas, silent mounted, 0 pageerrors
**/embed.js → 404 0 [sahaj-atlas] lines, pageerror: Failed to fetch dynamically imported module exactly 1 [sahaj-atlas] could not load the widget … line, 0 pageerrors
scope root translate null "no"
Google translate element, googtrans=/en/fr 2 <font> rewrites inside the widget ("Cours de méditation gratuits") 0 inside the widget, host text translated, 0 pageerrors

A classic <script src="/auto.js?…"> (no type="module") gives SyntaxError: Cannot use import statement outside a module and no <sahaj-atlas> element. This is the symptom the new Troubleshooting row names.

A reviewer can repeat one check by hand. Run pnpm build && pnpm review:embed, open /__review/sidebar-mapless.html, block embed.js in DevTools' network panel, reload, and expect one [sahaj-atlas] could not load the widget line.

Notes for reviewer

  • The idle deadline (2 s) matches the timeout the loader already passed to requestIdleCallback. A host whose shim never calls back therefore boots at most 2 s late.
  • translate="no" also opts the widget out of the browser's own page translation (Chrome's "Translate this page"). This is the trade the ticket chose: an untranslated widget, rather than one that crashes. The widget's settings menu still switches language.
  • I could not confirm whether Weglot's JS mode honours translate="no". The docs therefore tell hosts to add sahaj-atlas to the plugin's excluded elements if it does not, rather than claiming coverage.
  • In the translate run, the backend (local SahajCloud on :3000) was down, so the widget showed its data-error view. The local run did not reproduce the crash itself. It does show the precondition: Google rewrites React-owned text on main and leaves it alone here.
Detail
  • Why the loader spec imports index.ts rather than an extracted helper. Both guarantees live in the wiring: a .catch that was never attached looks like a working one to any test of the pieces (docs/testing.md, "A passing unit spec is not evidence…"). The entry's top level reads document.currentScript and calls start(). The spec therefore stubs a minimal document/window/HTMLElement (node lane, no jsdom) and re-imports the module per case with vi.resetModules() + vi.doMock('../Widget', …). A throwing factory gives the rejected chunk.
  • Why the translate pin reads source. Rendering the real Atlas element would boot the router, i18n and the loader config for one attribute. Widget.theme-root.test.tsx pins its wiring the same way. The spec walks the AST rather than matching text, so a reformat cannot hide a scope root. It asserts exactly two roots, so a broken walker cannot pass with nothing to check.
  • BootSurface also gets the attribute. It renders no text today. Every element carrying the scope class now opts out, which keeps the invariant one sentence long.
  • The other [sahaj-atlas] lines in the mounted runs (could not record this embed, view boundary, translations (en)) come from the unreachable local backend. They appear identically in the unpatched baseline.

Closes #239

🤖 Generated with Claude Code

Ardnived and others added 4 commits October 1, 2026 11:55
… failed widget chunk

The loader called requestIdleCallback with no guard and imported the widget
with no .catch. A host that patched the idle API to throw left an unhandled
rejection and an empty slot; one that never called back left an empty slot
and nothing at all. A 404'd or blocked embed.js did the same, anonymously.

The idle wait now mirrors lib/embed-announce.ts (copied, not imported, across
the loader seam): a 2 s deadline timer runs on both paths, a throw falls
through to the next task, and a once-guard keeps boot from running twice. A
failed import logs one "[sahaj-atlas] could not load the widget" line with
the browser's error, and rejects nothing.

The spec imports the real entry with ../Widget mocked at the seam; each case
fails against the unfixed loader.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Google Translate, GTranslate and Weglot's JS mode rewrite text nodes React
owns, so the widget's next update throws (removeChild / insertBefore) and
lands on the error screen. Both scope roots in Widget.tsx now carry
translate="no"; the widget localises itself.

Widget.translate.test.ts walks Widget.tsx's AST for every element carrying
WIDGET_SCOPE_CLASS and pins the attribute on each.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…fixes

Troubleshooting gains three rows: "Cannot use import statement outside a
module" (an optimizer or HTML5-cleanup filter dropped type="module", or
combined auto.js into a classic bundle — exclude auto.js), the loader's new
"could not load the widget" line, and a translator that ignores
translate="no". The language section says page translators now skip the
widget, and the script-tag rules point at the module-type row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2ceb0ee
Status: ✅  Deploy successful!
Preview URL: https://a268bc09.sahajatlas.pages.dev
Branch Preview URL: https://fix-239-loader-blank-slot.sahajatlas.pages.dev

View logs

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2ceb0ee
Status: ✅  Deploy successful!
Preview URL: https://5ac382cb.sahajatlas-design.pages.dev
Branch Preview URL: https://fix-239-loader-blank-slot.sahajatlas-design.pages.dev

View logs

@Ardnived
Ardnived merged commit 1e4e67f into main Oct 1, 2026
10 checks passed
@Ardnived
Ardnived deleted the fix/239-loader-blank-slot branch October 1, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fix(widget): three host conditions leave a blank slot, unreported

1 participant