Repository navigation
Description
Summary
A host's ordinary, non-!important CSS still reaches into the widget. On https://shrimataji.org/test/kn/find-a-class/ the compact card's heading renders in the theme's NotoSerif Regular at rgb(184, 131, 131), not the widget's typeface and foreground. docs/embedding.md ("The reverse direction is now defended, with one documented exception") and CHANGELOG.md promise that only !important gets through.
This is not a Mesmerize quirk. The plugin's browser lane measured the production widget across 18 booting cells × 4 viewports: the typeface was lost on 61 of 72 page checks, on every theme tried, by element a 48 / button 32 / h2 23 / input 2.
The reset in src/styles/globals.css:94 (:where(.sy-atlas) :where(*:not(svg, svg *)) { all: revert }) has zero specificity. The baseline that restates font-family and color sits on .sy-atlas itself (globals.css:113) and reaches descendants only by inheritance. So any host rule that targets a descendant directly, at any specificity above zero, wins wherever no Tailwind utility of ours sets that property. Here it is Mesmerize's body h2 { font-family; color } (0,0,2) against <h2 class="text-sm font-semibold"> (src/views/CompactEmbedView/CompactEmbedView.tsx:73), which sets size and weight but not family or colour.
This ticket is now the shadow-DOM revisitation that #157 deferred and closed as not planned. #157's own bar for reopening was "a host we actually need to support ships CSS that breaks the widget, and cannot or will not change it". The fleet measurement clears that bar — and clears it for non-!important CSS, which #157 believed was already fully blocked.
Does shadow DOM definitely fix it?
For this failure class, yes. A host selector cannot match an element inside a shadow root at all — !important or not, at any specificity. Every leak measured above is selector matching (a, button, h2, input rules), so all of it stops.
Two things still cross, and both must be stated or the fix will be mis-scoped:
- Inherited properties cross the boundary from the host element
<sahaj-atlas>, exactly as they cross into any element. So the baseline atglobals.css:113is not replaced by shadow DOM — it is what makes the widget the root of its own world, and it must survive the move. Only theall: revertreset above it retires. - A host rule aimed at
sahaj-atlasitself still sets that element's own non-inherited properties — its box, its display, its margin. That is the host's slot and legitimately theirs.
So the honest claim is: shadow DOM closes host-selector reach completely, and leaves inheritance, which we already defend and would keep defending.
What it would cost
The mount itself is one line. @r2wc/[email protected] takes shadow?: "open" | "closed", so r2wc(Widget) at src/Widget.tsx:431 becomes r2wc(Widget, { shadow: 'open' }). Everything below is the actual price.
- The two style-tag ids are a documented host contract.
docs/embedding.md:953-961publishessahaj-atlas-styleandsahaj-atlas-fontsas "kept stable across releases precisely because host sites key off them". A shadow root moves the stylesheet out of the host's<head>and breaks that for any host who did. This is a breaking change fordocs/embedding.mdandCHANGELOG.md, not a detail. - The CSS injector has no shadow target.
vite-plugin-css-injected-by-js(vite.config.ts:228) appends todocument.head. It must be replaced, or post-processed into a stylesheet the root adopts. @font-facehas to stay in the document and is already correct there (src/styles/fonts.ts:136). Faces registered inside a shadow root are not applied. So the stylesheet splits into two permanent homes, and the'Atlas Rethink Sans'family-name hack stays for the same reason it exists now.document.activeElementreturns the host element across the boundary, and two of our own call sites read it:src/config/store.ts:241(the report modal's return-focus capture — breaking it drops a keyboard user at the top of the host page, the exact failure that comment exists to prevent) andsrc/views/CompactEmbedView/CompactEmbedView.tsx:214. Both needgetRootNode().- Radix's dismissible-layer and focus machinery is document-level, as is vaul's. Click-outside,
Esc, and focus trapping all route through it, and none of it is ours to patch. - Mapbox GL has known
document.elementFromPointtrouble in a shadow root, and@mapbox/[email protected]is itself a shadow-DOM custom element, so it would nest. - Turnstile injects its script into
document.head(src/hooks/use-turnstile.ts:77) and renders its challenge into our container. It gates the report-issue form, which delivers real email since fix(event): deliver report-issue submissions instead of alerting #103, so a silent failure there is not cosmetic.
What it would NOT cost — checked, so nobody re-derives it
- Portals are already shadow-shaped. Everything targets the theme root through
overlayContainer()(src/lib/overlay.ts:110), neverdocument.body(src/lib/scope.ts:17-18). This is the single largest obstacle in chore(ui): evaluate shadow DOM now that the CSS reset has a measured gap #157's list and it has since been built. - There is no slotted content. No
<slot>exists anywhere insrc/views/orsrc/components/, and the widget renders no host children — so there is no slotted subtree where host CSS would walk straight back in. position: fixedis unaffected. A shadow root creates no containing block, so the fixed layer,MapFrame, and the measuredcontain: layout/transformtable insrc/components/AGENTS.mdall stand.- Custom properties inherit through the boundary, so the brand palette keeps arriving exactly as it does now.
- The readiness marker is on
document.documentElement(src/lib/readiness.ts:77), so the smoke lane is unaffected.
What gets simpler
- The PostCSS scoping pass and its gate become unnecessary inside a shadow root:
scripts/postcss-scope-widget.mjs(513 lines),scripts/assert-css-scoped.mjs(281) andscripts/postcss-scope-widget.test.ts(352) — 1,146 lines — retire or re-aim, and selectors go back to being plain. - The reset's measured cost goes: a forced style recalc over 3,200 scoped nodes currently runs about 2× one outside the scope (41ms vs 20ms,
globals.css:76-80). - The SVG-exclusion trap (
globals.css:82-93) disappears with the reset that caused it.
Recommendation
Adopt it, with Phase 1 item 1 as the go/no-go. Neither fallback is a real alternative:
- Raising the reset's specificity cannot hold. The reset is
(0,0,0)deliberately (globals.css:45-52): it must stay under our own Tailwind utilities(0,1,0), so any raise is bounded above by our rules while a host's selector is bounded by nothing. A host adds one class and leads again. That route lowers 61/72 and never reaches 0. - Restating the baseline per element buys a green lane over an unchanged failure class. The measured losses are
font-familyandcolor, both inherited, so it would score 0/72 here while every non-inherited leak —text-decoration,background,border-radius— stands exactly where it is.
Shadow DOM is the only one of the three that is a boundary rather than a bet, and it retires 1,146 lines and the 2× recalc with it.
The condition: Radix's dismissible layer and vaul are document-level and not ours to patch, so that is the one cost that can kill the approach outright. If Phase 1 item 1 fails, take the per-element baseline plus an honest docs/embedding.md — not the specificity route.
Answer the style-id question before the spike. It is the only breaking cost in the list, and a grep of the known hosts settles it in minutes.
Approach
Two phases, one ticket, one PR.
Phase 1 — the spike, in a browser. Flip src/Widget.tsx:431 to { shadow: 'open' } on a branch and answer only the things no document can settle, each by observation in current Chrome and Safari:
- Radix dismiss /
Esc/ focus trap across the boundary, and the twodocument.activeElementreads above. This one is the go/no-go — settle it before paying for anything below. - Mapbox GL pointer hit-testing, and the geocoder nesting its own shadow root.
- Turnstile rendering and solving inside the root.
- The stylesheet's new home, and whether
display: contentson the theme root (src/Widget.tsx:81) still behaves. - That
@font-facemust stay indocument.head— confirm against the engines, not the folklore.
Phase 2 — adopt, or decline with the fallbacks. If adopted: migrate the injector, keep the globals.css:113 baseline, drop the all: revert reset, retire or re-aim the scoping pass and assert:css, and write the style-id break into docs/embedding.md and CHANGELOG.md. If declined: restate the inherited baseline on every scoped element rather than the root, and docs/embedding.md must stop promising that non-!important CSS is blocked, because it is not.
Acceptance criteria
- A host rule such as
body h2 { font-family: serif; color: red }, without!important, does not change any widget text. - A host rule carrying
!importantand targeting a widget descendant does not change it either, or the decision records why that was not bought. - Tailwind utilities inside the widget still win over whatever reset remains.
- Focus return from the report modal still lands on the opener, not the top of the host page.
- The report-issue form still renders, solves and submits its Turnstile challenge.
-
docs/embedding.mddescribes exactly what a host's CSS can and cannot reach, anddocs/embedding.md+CHANGELOG.mdrecord any change to the two published style-tag ids.
Verification checklist
-
pnpm build && pnpm review:embed; open/__review/hostile-css.htmlwith addedbody h2 { font-family: serif; color: red }andbody a { color: red !important }rules; the compact card heading and every link compute the widget's font family and foreground colour. - In the same page: open the report modal from the settings menu, close it, and confirm focus returns to the opener.
- In the same page: open a drawer and dismiss it by click-outside and by
Esc; drag the map and open the geocoder. -
pnpm lint && pnpm typecheck && pnpm test:run, thenpnpm build && pnpm size. - Re-run the plugin's browser lane in
sydevs/SahajAtlasWordpress(see test(browser): run the real widget in real themes, in a browser SahajAtlasWordpress#38) against a deploy of the branch; the 61/72 typeface losses go to 0/72. ⚠ There is nopnpm test:browserin this repo — that lane is the plugin's. - The same check on
https://shrimataji.org/test/kn/find-a-class/at 1280×720 after deploy.
Downstream impact
sydevs/SahajAtlasWordpress— owns the browser lane that measured this and is the acceptance evidence for the fix.- Embedding hosts — a shadow root changes where the stylesheet lives, which
docs/embedding.md:953-961currently publishes as stable.
Open questions
-
Which of the three candidate fixes?Shadow DOM is the one under evaluation, per the thread. The other two stay as Phase 2 fallbacks. -
Open or closed root?open. It keeps the widget inspectable and keeps our owngetRootNode()reads simple, and closed buys nothing a host cannot already defeat. - Do any current hosts actually key off
sahaj-atlas-styleorsahaj-atlas-fonts, or is the published contract unused and cheap to retire? Settle this first — it is the only breaking cost. - If Radix or Turnstile fails the spike, is the fallback a partial shadow root, or the per-element baseline?
Notes
Found while fixing #235. hostile-css.html uses only !important and single-element selectors, which is why the gap stayed unseen.
Supersedes #157, which closed as not planned on the premise this ticket disproves — that non-!important host CSS was fully blocked. #157's obstacle list is still the right list; this body records which entries have since been built (portals), which stand (Radix, Mapbox, fonts, the injector), and which are new (the published style-tag ids, Turnstile, our two document.activeElement reads).
⚠ Shadow DOM does not fix vaul's window-height arithmetic. That is a separate problem and must not be used to justify this one.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Hold Until
Projects
- StatusShow more project fieldsDone
Activity
Ardnived commentedon Oct 1, 2026
Measured across the fleet's free themes by the plugin's new browser lane (sydevs/SahajAtlasWordpress#38): production widget, WordPress 6.7, 18 booting cells × 4 viewports.
The widget's typeface was lost on 61 of 72 page checks. By element:
a48,button32,h223,input2. Every theme leaked at least one: Astra, OceanWP, Mesmerize, Esotera, Fluida, PopularFX, Seva Lite, Enigma, Twenty Twenty/Four/Five, and Astra under Elementor and Beaver Builder.So this is not a Mesmerize quirk. Any theme rule on
a,buttonorh2with specificity above zero beats the (0,0,0) reset.pnpm test:browserre-measures a fix; screenshots land intests/screenshots/.🤖 Written by the sydevs autonomous loop — see what this is
Ardnived commentedon Oct 1, 2026
@sydevs-bot Revise this ticket as a revisitation of the shadow dom approach. What are the pros and cons? What would we lose by implementing the shadow DOM and would it definitely fix the issue raised in this ticket?
sydevs-bot commentedon Oct 1, 2026
🤖 no session running
recent dispatches
Written by the sydevs dispatcher. Sessions never edit this comment.
sydevs-bot commentedon Oct 1, 2026
Revised as a shadow-DOM revisitation, per your ask. The body now leads with the three answers.
Would it fix this? Yes, completely, for host selectors — they cannot match inside a shadow root,
!importantor not. Two things still cross: inherited properties from<sahaj-atlas>, and rules aimed at that element itself. So the baseline atglobals.css:113stays; only theall: revertreset retires.The mount is one line —
@r2wc/[email protected]takesshadow: 'open'.What we would lose, the part worth your eye:
docs/embedding.md:953-961publishes two style-tag ids as stable "because host sites key off them". A shadow root breaks that. Also the CSS injector, Turnstile, and two of our owndocument.activeElementreads.What #157 feared and we already built: portals all target the theme root, not
document.body.Also raised Effort to Hard, and added
sydevs/SahajAtlasWordpressunder Downstream impact. Title unchanged.@sydevs-bot implementstarts the work.🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
Ardnived commentedon Oct 1, 2026
@sydevs-bot Do you recommend implement the shadow DOM?
7 remaining items
fix(a11y): carry the geocoder's live region across the shadow boundary
fix(a11y): patch the focus trap and hiding through the boundary
Merge origin/main into claude/fix-236-shadow-dom
Merge origin/main into claude/fix-232-sentry-dsn
fix(comments): rewrite the host-head premise in five more files
fix(comments): correct the rem premise in the src guide
test(lib): both shadow patches answer for the copy each consumer reso…
fix(widget): borders, shadows and the calendar inside the shadow root…
fix(ui): the drawer's views flicker in halfway down the panel inside …
fix(deps): lift the @swc/core pin to 1.16.21, matching WeMeditateWeb (#…