Repository navigation
fix(widget): three host conditions leave a blank slot, unreported - #240
Merged
Merged
Conversation
… 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]>
Deploying sahajatlas with
|
| 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 |
Deploying sahajatlas-design with
|
| 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 |
11 tasks
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.
Summary
requestIdleCallbackto throw, or never call back, now gets a mounted widget.embed.jsload logs one[sahaj-atlas]line and leaves no unhandled rejection.translate="no", so page translators no longer crash the widget.docs/embedding.mdnames 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 aroundrequestIdleCallback, and a once-guard. This mirrorslib/embed-announce.ts, copied rather than imported across the seam..catchonimport('../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../Widgetmocked at the seam.src/Widget.tsx—translate="no"onBootSurface's root and on the theme wrapper.src/Widget.translate.test.ts— walksWidget.tsx's AST and asserts that every element carryingWIDGET_SCOPE_CLASShastranslate="no".Contract impact
docs/embedding.mdandCHANGELOG.mdchanged (host-observable):[sahaj-atlas] could not load the widget …translate="no").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
/maphost needs nothing.Test results
.claude/skills/pr-prep/check.sh): ✓ lint, typecheck,test:run(127 files, 1626 tests)src/loader/index.test.ts4 passed,src/Widget.translate.test.ts2 passed.catchthat rethrows, the unhandled-rejection assertion fails.pnpm build: ✓ (assert:css,assert:maps)pnpm size: ✓. loader 2.7 KiB / 3.5 (was 2.6 onmain), 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:embedon/__review/sidebar-mapless.html, withclients/mestubbed. Each ran on this branch and, as a control, on a build ofmain.mainrequestIdleCallbackthrows (addInitScript).sy-atlas,pageerror: host patchrequestIdleCallbacknever calls back.sy-atlas, silent**/embed.js→ 404[sahaj-atlas]lines,pageerror: Failed to fetch dynamically imported module[sahaj-atlas] could not load the widget …line, 0 pageerrorstranslatenull"no"googtrans=/en/fr<font>rewrites inside the widget ("Cours de méditation gratuits")A classic
<script src="/auto.js?…">(notype="module") givesSyntaxError: Cannot use import statement outside a moduleand 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, blockembed.jsin DevTools' network panel, reload, and expect one[sahaj-atlas] could not load the widgetline.Notes for reviewer
timeoutthe loader already passed torequestIdleCallback. 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.translate="no". The docs therefore tell hosts to addsahaj-atlasto the plugin's excluded elements if it does not, rather than claiming coverage.mainand leaves it alone here.Detail
index.tsrather than an extracted helper. Both guarantees live in the wiring: a.catchthat 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 readsdocument.currentScriptand callsstart(). The spec therefore stubs a minimaldocument/window/HTMLElement(node lane, no jsdom) and re-imports the module per case withvi.resetModules()+vi.doMock('../Widget', …). A throwing factory gives the rejected chunk.Atlaselement would boot the router, i18n and the loader config for one attribute.Widget.theme-root.test.tsxpins 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.BootSurfacealso gets the attribute. It renders no text today. Every element carrying the scope class now opts out, which keeps the invariant one sentence long.[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