Skip to content

fix(ui): host CSS without !important still restyles widget text - #243

Merged
sydevs-bot merged 20 commits into
mainfrom
claude/fix-236-shadow-dom
Oct 4, 2026
Merged

sydevs-bot merged 20 commits into
mainfrom
claude/fix-236-shadow-dom

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The widget renders in an open shadow root, so a host selector cannot match inside it at any specificity, !important or not.
  • The all: revert reset retires, with its 2× style recalc and its SVG-geometry trap. The inherited baseline on .sy-atlas stays — that half was never about selectors.
  • Three dependency patches carry Radix's focus trap, its mount auto-focus, and aria-hidden's hiding across the boundary. Without them a modal would not trap focus and a screen reader would not have the rest of the page hidden from it.
  • Breaking for hosts: sahaj-atlas-style is gone, and a host's own children of <sahaj-atlas> stop rendering. sahaj-atlas-fonts is unchanged. One hidden aria-live node is added to the host's <body>.

The decision was made — both libraries are patched

The earlier revision of this body handed up a go/no-go: Radix's dismissable layer survives the boundary, but @radix-ui/react-focus-scope reads document.activeElement and event.target, both of which retarget to <sahaj-atlas> inside a root, so the trap went inert and aria-hidden's hideOthers hid nothing.

That is now fixed rather than documented (92ab070). patches/@[email protected] resolves those reads through the boundary and exempts a relatedTarget equal to our own host; patches/[email protected] keeps the real target and descends into the kept root. [email protected] needed nothing — it already matches against getOutermostShadowParent(target).

src/lib/shadow-patches.test.ts pins the behaviour. ⚠ The focusout half has no behavioural assertion: jsdom will not reproduce the event ordering its symptom needs, so a drift pin stands in.

Phases

  • Phase 1 — the spike and the mount: shadow root, the stylesheet's new home, the two focus reads, the reset retired, docs/embedding.md + CHANGELOG.md.
  • Phase 2 — the boundary audited against the map libraries and Radix, the focus contract pinned in specs, and three live defects that audit found fixed. The scoping pass stays re-aimed rather than retired (below).
  • Phase 3 — the focus decision implemented: both libraries patched, the contract rewritten, and the measured typeface figure corrected across all five of its citations.

Changes

  • src/Widget.tsx — r2wc(Widget, { shadow: 'open' }), and the root adopts the sheet before React mounts.
  • src/styles/sheet.ts (new) — the CSS sink and adoptStyles(root). vite.config.ts hands each chunk to it instead of appending a <style>.
  • patches/ (two new) — @radix-ui/react-focus-scope and aria-hidden, resolved through the boundary.
  • src/lib/active-element.ts (new) — deepActiveElement(), used by the report modal's and the compact card's return-focus captures.
  • src/views/DrawerStack/sheet-wake.ts (new) — the --sy-sheet-top wake filter, reading the composed path instead of a retargeted event.target.
  • src/components/organisms/Mapbox/aria-live.ts (new) — re-homes the geocoder's live region so its screen-reader announcements still reach a reader.
  • scripts/assert-css-scoped.mjs — re-aimed at the sink: there is no style tag left to scan for.

Preview

Both branch aliases are live and answer 200. They serve an earlier commit until Cloudflare rebuilds this push.

Contract impact

docs/embedding.md and CHANGELOG.md both change in this PR — the style-tag id is a published host contract, a host's own children of the element stop rendering, and the live region is a new node in the host's document.

  • sydevs/SahajAtlasWordpress owns the browser lane that is the acceptance evidence for this fix. It has been re-run against this branch and reports 0 failures on every cell, with the probe corrected in test(browser): read the widget through its shadow root, and judge a preview SahajAtlasWordpress#56.
  • The headline figure was wrong and is now corrected. The lane's old probe read Mapbox's own Helvetica Neue on the attribution link and zoom buttons as a theme leak. The real production loss is 24 of 72 page checks, all h2, on six themes — not 61 of 72. All five citations are fixed in 43e2580.
  • No in-tree consumer reads the style id: WeMeditateWeb/lib/atlas-embed.ts and the WordPress templates were not checked from this session — worth a grep before merge.

Test results

  • Lean gate: ✓ lint + typecheck + test:run (134 files, 1659 tests)
  • Targeted specs: 23 new assertions across active-element.test.ts, store.report-focus.test.ts, aria-live.test.ts, sheet-wake.test.ts, sheet.adopt.test.ts and sheet.test.ts, plus shadow-patches.test.ts for the two patches. Every one was confirmed RED against its own defect reintroduced at the real site, then restored — the deep walk collapsed to one hop and removed; store.ts reading document.activeElement again; the live-region read made once instead of observed, its teardown dropped, its closest walk unbounded; the sheet-wake filter back on event.target; the sink's listener dropped and its foreign-sheet filter removed; the chunk field renamed across the seam; and each patched site reverted in the bundle.
  • Build: ✓ including assert:css (1171 rules, 3 sheets) and assert:maps (23 files); pnpm size ✓ (standalone 302.1/308, loader 2.7/3.5, embed 303.9/308 KiB — unchanged)
  • comment-lint: clean, 17 files

Manual verification

Measured in real Chromium (Playwright, 1280×720) against the built embed on a host page carrying both the !important block and the non-!important block:

  1. Acceptance 1–3 pass. Host body h2 { font-family: serif; color: rgb(184,131,131) } lands on the host's own h2 while the widget's h2 computes Atlas Rethink Sans / rgb(32,32,32). letter-spacing: normal against 6px !important; box-sizing: border-box against content-box !important; the link neither red nor underlined; SVG filter: none. A Tailwind utility still wins.
  2. Dismissal passes. The settings dropdown opens with 3 nodes inside the shadow root and 0 in the host document. Escape closes it and returns focus to the Settings button; a click at (5, 5) on the host page dismisses it.
  3. The document.activeElement hazard is confirmed, not assumed: it reports sahaj-atlas for anything focused inside. Both return-focus captures now use deepActiveElement(), pinned by specs rather than by this observation.
  4. The plugin's browser lane passes against this branch: 0 failures, overlays, stacking, hit tests and the compact card all inside the shadow root. One finding is left, on Enigma at laptop size — the search input and one link use Mapbox Search JS's own system font stack, which is the library's font rather than a theme leak.

Still owed, and not doable from a sandbox — Chromium here cannot reach any external HTTPS host (the agent proxy's CA is not in its trust store, so every origin fails ERR_CERT_AUTHORITY_INVALID). These need an attended run or a deploy:

  1. Tab through and out of the report modal and the compact card's expanded dialog, to confirm the focus patch in a real browser rather than in jsdom. This is the one item the patches make load-bearing.
  2. The real Turnstile challenge rendering and solving inside the shadow root (acceptance 5). The earlier spike stubbed the script so the form would render; that says nothing about Cloudflare's own iframe.
  3. The report modal's focus return end to end (acceptance 4). Our half — which element is captured — is spec'd in store.report-focus.test.ts; Radix performs the focus.
  4. Mapbox end to end — tiles, pointer hit-testing, the geocoder's suggestions, and a bottom-sheet drag confirming the Register bar now follows the sheet.

Notes for reviewer

Why the two libraries are patched rather than mocked. Every site the focus-scope patch changes is module-internal — the package exports only FocusScope and Root, so focusFirst, focus and the three event handlers cannot be reached from our code. Two of the changes are new branches rather than substituted reads (the relatedTarget === host exemption, and aria-hidden's descent into the kept root), which no value-level shim can express at all. The only mock that reaches the reads is overriding Document.prototype.activeElement and Event.prototype.target — configurable getters, so it is possible, but they live in the host's realm and would change what every host script sees. A patch is also the loud option: a dependency bump fails the install with ERR_PNPM_PATCH_NOT_APPLIED, where a monkey-patch would drift in silence.

The review lenses ran, and they earned their keep — four real defects, three fixed. /security-review: no HIGH or MEDIUM findings, with reasoning rather than mere absence — the CSS sink is a mutable global any script in the host origin can pre-seed, but on main that same actor could already append a <style> to document.head and style every widget element, so the capability delta is zero; shadow: 'open' exposes nothing closed would withhold, since on main the whole tree sat in the host document; the hoisted live region cannot be made to move a host node, and the library writes it with textContent, not innerHTML. A correctness pass over the whole branch found the rest.

Fixed, each in its own commit:

  • The --sy-sheet-top wake loop was dead inside the embed. Both listeners sit on document and tested event.target, so after a bottom-sheet drag the sticky Register bar kept the offset from before the drag until something resized the window. Now reads composedPath().
  • sheet.test.ts did not pin the chunk field names. Renaming css to text in the sink left every spec and the CSS gate green while shipping the widget completely unstyled. Now pinned, and adoptStyles has behavioural coverage it had none of.
  • The live-region closest walk was unbounded, so a library version that stopped wrapping its description would have moved a chunk of the widget into the host's body and then deleted it.
  • Three stale or wrong statements: assert-css-scoped.mjs still opened "The widget has no shadow boundary"; the audit cited [email protected] when the installed and actually-read version is 1.6.0 (that is search-js-react's version — the claims all hold, the citation did not); and hoistGeocoderLiveRegion's docblock overstated its own teardown.

Not fixed, deliberately: the CSS sink is unversioned. Two different embed.js builds on one page would cross-feed chunks into one sink, and adoptStyles registers a listener with no unsubscribe, so a host SPA that re-creates <sahaj-atlas> N times keeps N detached roots alive. Both are bounded — the widget already refuses a second <sahaj-atlas> and a second script is a no-op — and both want the three-literal seam changed or a teardown threaded into disconnectedCallback. Worth a follow-up, not worth widening this PR unreviewed.

Also open: the geocoder's live region is hoisted rather than patched. Now that three patches ship, one patch of @mapbox/search-js-web would replace the 65-line hoist and cover the three activeElement comparisons docs/rules/mapbox.md records. The hoist is the shipped, spec'd half, so it stays here and the patch is the follow-up — the thread is left open for you.

The scoping pass stays rather than retiring, which is the ticket's "retire or re-aim" answered as re-aim. The embed's sheet is behind a boundary now, but the standalone build and Ladle still put it on <html class="sy-atlas">, so the pass is what keeps those two honest. Retiring the 1,146 lines is a separate, reviewable change, and it would reduce the benefit the ticket counted — worth disagreeing with if you do.

src/components/molecules/Fallbacks/Fallbacks.tsx deliberately does not resolve through the boundary. It reads node.ownerDocument.activeElement and asks the opposite question — "has the host page got focus somewhere?" — before moving focus to a boot failure. Checked in both directions: inside a root that read answers <sahaj-atlas> for our own elements, which is not body, so it does not steal focus from a visitor typing in our own search field; and a detached focused node still resets focus to body, so the steal still fires when it should.

Detail

What the library audit found, first-hand. The ticket listed two Mapbox risks as spike questions. Both were folklore older than the installed code.

  • mapbox-gl 3.30.0 needs no accommodation at all. elementFromPoint: zero occurrences across every dist bundle. document.body, ownerDocument, getRootNode, document.activeElement: zero. Pointer position is mousePos(el, e) → el.getBoundingClientRect() against a stored element reference, and the window-level drag listeners pass the event into it rather than reading e.target, so retargeting cannot reach them. Its only two document.fullscreenElement reads belong to FullscreenControl, which this app does not render.
  • @mapbox/[email protected] nests no shadow root. Eight customElements.define calls, zero attachShadow. So the ticket's "the geocoder is itself a shadow-DOM custom element, so it would nest" is false. It styles itself with <style> children of each element, and its only document.head injection is the autofill-detection sheet, reached from AddressAutofill and AddressMinimap — neither of which we render. The Geocoder mounts its suggestion listbox on its own parentElement, inside our root, so our adopted sheet reaches it and host CSS cannot.
  • One real defect there. createAriaLiveElement inserts the live region beside the Geocoder's <input> (inside our root) while setLiveRegionMessage reads it back with document.body.querySelector. The boundary puts those on opposite sides and the read is guarded, so every suggestion count, "no results", and selected-suggestion message stopped reaching a screen reader with nothing thrown and nothing logged.
  • One narrow consequence accepted. Three document.activeElement comparisons in the geocoder can never be true inside a root. The reachable one: a suggest response finds Geocoder.contains(document.activeElement) false and re-focuses the input, taking focus back from the suggestion list if a response lands while a keyboard user is already arrowing through it. Only fixable by patching the dependency; recorded in docs/rules/mapbox.md.

⚠ The fixture in aria-live.test.ts copies the library, so it was checked against the library. The id suffix, the [aria-live] wrapper, the insertion before the input, and the document.body.querySelector lookup it asserts against were all read off @mapbox/[email protected]'s dist/index-esm.js. The spec uses that file's lookup expression verbatim, so it fails if the fix stops satisfying the real reader rather than a paraphrase of it.

docs/embedding.md contradicted itself. "The stylesheet is injected into your document — there is no shadow DOM" sat twenty lines above the paragraph introducing the shadow root. Fixed, and the exception list grew the fifth entry it needed for the live region.

Why the stylesheet had to move at all. The boundary cuts both ways: a sheet in the host's <head> cannot reach into a shadow root either. So vite.config.ts's injectCodeFunction parks each chunk on globalThis and each entry adopts the sink into the root it owns — the shadow root for the embed, the document for the standalone shell. Ladle is untouched: .ladle/vite.config.ts already skips the injector and imports globals.css directly.

Three literals span a seam no import crosses. injectCodeFunction is stringified into the bundle, so it cannot import the key it writes to, and assert-css-scoped.mjs is a build script that cannot import the TS module either. src/styles/sheet.test.ts reads all three files and fails on drift — the src/loader/literals.ts pattern, for the same reason #153 needed it. It now pins the chunk field names too, which was the half whose drift was silent.

The gate counts injection sites by data-vite-dev-id, not by the sink key. The key appears in sheet.ts too, as the reader, so a chunk carrying that module counted one site more than it held. That was a real failure on the first build here: 4 sites against 3 stylesheets.

HMR would otherwise stack sheets. Vite re-sends a module's CSS on edit, so the sink keys a chunk on data-vite-dev-id and replaces in place. A build sends each chunk once and carries no id, where position is identity — sound because the sink only appends.

@font-face stays in document.head, and that is not a workaround. A face registered inside a shadow root is never applied. src/styles/fonts.ts already appended its own tag there and needed no change, which also keeps the 'Atlas Rethink Sans' family-name hack load-bearing for exactly the reason it was introduced.

⚠ jsdom 27 constructs a CSSStyleSheet and accepts an adoptedStyleSheets assignment but supplies no default empty list on a root, so sheet.adopt.test.ts seeds one and says why. adoptStyles reads the property unguarded, which is right — it is Baseline everywhere the widget ships.

Measured and unaffected (earlier session, real Chromium): display: contents on the theme root still computes contents; the fixed layer resolves against the viewport (a shadow root creates no containing block); document.fonts carries Atlas Rethink Sans and the widget resolves it; 838 rules adopted into the root; adoptedStyleSheets is empty on the document, so nothing is parsed twice.

Also observed, not explained (earlier session): 5 of the 8 <path> nodes present reported a non-zero getBBox(). The three that did not were not traced to a cause, and the reset's SVG exclusion is moot now that there is no reset — but it was not compared against a main build, so it is an observation rather than a clean bill.

One tool check did not run. comment-rule-sync.mjs expects the five repos as siblings and exits on canonical rule not found: ../claude-workflow/docs/code-comments.md, which this checkout's layout does not provide. No comment-rule file is in this diff, so nothing was owed to it.

Closes #236

🤖 Written by the sydevs autonomous loop — see what this is

🤖 Generated with Claude Code

https://claude.ai/code/session_01DZugACuG6BXhEzkWdpy5W8

claude added 2 commits October 1, 2026 21:31
A host's ordinary, non-`!important` CSS still restyled widget text. The
`all: revert` reset in `globals.css` was deliberately (0,0,0) so it would stay
under our own Tailwind utilities (0,1,0) — which bounded it above by our rules
while a host's selector was bounded by nothing. Measured across the WordPress
theme fleet, the widget's typeface was lost on 61 of 72 page checks, to rules as
ordinary as `body h2 { font-family }`.

`r2wc(Widget, { shadow: 'open' })` makes that unreachable rather than merely
harder: a host selector cannot match inside a shadow root at any specificity.
The reset retires with it, and so do its two measured costs — a style recalc at
about 2x over the scope, and `all: revert` rolling SVG 2 geometry to its initial
value.

The stylesheet has to move with the subtree it styles, because a document sheet
cannot reach into a shadow root either. `vite.config.ts` hands each CSS chunk to
a sink on `globalThis` instead of appending a `<style>`, and each entry adopts it
into the root it owns. `@font-face` stays in `document.head`, where a face has to
be to apply at all.

Both return-focus captures move to `deepActiveElement()`. Confirmed in Chromium:
`document.activeElement` reports `sahaj-atlas` for anything focused inside, so
closing the report modal would have dropped a keyboard user on the host element.
`Fallbacks.tsx` keeps reading `document.activeElement` — it asks the opposite
question, and the host element answering for our subtree is the answer it needs.

The published `sahaj-atlas-style` tag is gone with the head injection; no client
keys off it. `sahaj-atlas-fonts` is unchanged.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011KsjmeDNmd47t8j6843oUf
… gone

`docs/embedding.md` promised that only `!important` got through, and published
`sahaj-atlas-style` as stable "precisely because host sites key off them". The
shadow root makes the first claim stronger and the second false, so both are
rewritten rather than softened: what a host's CSS can and cannot reach, the two
things that still cross and why each is meant to, and the removal of the style
tag with a pointer at the open shadow root for anyone who was keying off it.

`sahaj-atlas-fonts` is documented as staying in the host's document, with the
reason — a face registered inside a shadow root is never applied.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011KsjmeDNmd47t8j6843oUf
@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: d458af9
Status: ✅  Deploy successful!
Preview URL: https://db6aa0b1.sahajatlas-design.pages.dev
Branch Preview URL: https://claude-fix-236-shadow-dom.sahajatlas-design.pages.dev

View logs

@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: d458af9
Status: ✅  Deploy successful!
Preview URL: https://fcb51e04.sahajatlas.pages.dev
Branch Preview URL: https://claude-fix-236-shadow-dom.sahajatlas.pages.dev

View logs

claude added 6 commits October 1, 2026 21:57
The two return-focus captures moved to `deepActiveElement()` on the strength of
one browser observation, and neither the walk nor the capture had a spec. An
observation does not survive the session that made it.

`active-element.test.ts` asserts the hazard beside the fix: inside an open root
`document.activeElement` names the host, so the first spec would pass against a
bare `document.activeElement` in an engine that did not retarget. It also covers
a nested root, which the geocoder would have been, and the case where the host
itself holds focus — a walk that skipped each root's own `activeElement` would
answer with the child instead.

`store.report-focus.test.ts` covers the capture that drops a keyboard user at the
top of the host page when it fails. The load-bearing line is `isConnected`: a
node inside a root reaches the document through it, so the boundary does not make
the opener look gone. Were that false, every close would return `null` and focus
would go nowhere, with nothing throwing.

Each spec was confirmed red against its own defect reintroduced at the real site
— the walk collapsed to one hop, the walk removed, and `store.ts` reading
`document.activeElement` again — then restored.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DouA7ayFHJuXWxpFbYNbqF
Auditing the two map libraries against the shadow root found one live defect.
`@mapbox/search-js-web` inserts its `aria-live` region beside its own input, so
inside our root, and then reads it back with `document.body.querySelector`. The
boundary puts those two on opposite sides, the read is guarded, and so every
suggestion count, "no results", and selected-suggestion message stops reaching a
screen reader with nothing thrown and nothing logged.

The region moves to where the library looks for it. A live region works anywhere
in the document and this one carries its own clipping styles, so it travels
intact; the alternative was patching a bundled dependency to change one lookup.
A MutationObserver rather than a read after mount, because the region appears
when the custom element connects, which is not ordered against this component's
effects. Each geocoder seeds its own id, so the region is removed on teardown
rather than orphaned in the host's body.

The rest of the audit is recorded in `docs/rules/mapbox.md` so nobody re-derives
it: mapbox-gl 3.30.0 needs no accommodation at all — no `elementFromPoint`
anywhere, pointer position computed against a stored element reference, and the
window-level drag listeners never reading `e.target`. The geocoder nests no
shadow root either, contrary to the premise in #236: eight custom elements, zero
`attachShadow`, styles as `<style>` children, and its suggestion listbox mounted
on its own `parentElement`. One narrow consequence is accepted and documented —
a suggest response re-focuses the input, which can take focus back from the
suggestion list mid-keyboard-navigation.

`docs/embedding.md` said "there is no shadow DOM" twenty lines above the
paragraph introducing the shadow root. That contradiction is fixed, and both it
and `CHANGELOG.md` now record the one hidden node the widget adds to a host's
body.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DouA7ayFHJuXWxpFbYNbqF
`closest('[aria-live]')` walks past the scope element to the shadow root, so a
library version that stopped wrapping its description would match one of our own
ancestors instead. Hoisting that would move a chunk of the widget into the host's
body, and teardown would then delete it.

The match now has to be a strict descendant of the scope. Confirmed red against
the unbounded walk.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DouA7ayFHJuXWxpFbYNbqF
…rget

The `--sy-sheet-top` loop parks after half a second of stillness and is woken
by `pointerdown` and `transitionrun` listeners on the host's document. Both
tested `event.target` against the sheet, and the shadow root retargets that to
`<sahaj-atlas>` — the sheet's own ancestor. So `sheet.contains(target)` was false
for the drag and `target !== sheet` true for the snap, and every wake path except
`resize` returned early.

The visible cost is a stale offset: `EventView`'s sticky Register bar reads
`--sy-sheet-top` live, so after a bottom-sheet drag it sat where the sheet used
to start until something resized the window. `FallbackRegion`'s max-height reads
it too.

The filter moves to `wakesSheetLoop`, a pure sibling like `strip-label`, so it can
be driven with real events in jsdom rather than by importing vaul and mapbox-gl
into the node lane. It reads `composedPath()`: a non-composed event never reaches
a document listener from inside a root at all, so the path can only do better than
the target, never worse. `resize` still falls through on its target's type.

Confirmed red against the two target reads — the drag and the snap both fail,
while the three cases that must stay ignored stay green.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DouA7ayFHJuXWxpFbYNbqF
`sheet.test.ts` pinned the sink key and its seed but not the per-chunk field
names, and that drift is the silent one. Renaming `css` to `text` in
`vite.config.ts` left every spec green and the CSS gate green — it reads the
template literal, never the object — while `replaceSync(undefined)` wrote the
string "undefined" into every constructed sheet and shipped the widget with no
styles at all. Now pinned on both sides, and confirmed red against that rename.

`adoptStyles` had no behavioural coverage, so the reason `listeners` exists could
not fail: a chunk arriving after a root has adopted is what `relativeCSSInjection`
produces on every lazy route. `sheet.adopt.test.ts` drives it in jsdom and covers
that, the preservation of a foreign sheet, and the document path the standalone
shell takes. Each was confirmed red against its own defect — the listener dropped,
and the foreign filter removed.

It is a separate file because its sibling reads itself off disk, which jsdom's
`import.meta.url` cannot do.

⚠ jsdom 27 constructs a `CSSStyleSheet` and accepts an `adoptedStyleSheets`
assignment but supplies no default empty list, so the fixture seeds one and says
why. `adoptStyles` reads the property unguarded, which is right — it is Baseline
everywhere the widget ships.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DouA7ayFHJuXWxpFbYNbqF
…ree corrections

The branch audited the two Mapbox libraries against the shadow root but not the
ones behind every drawer and dialog. `@radix-ui/react-focus-scope` listens for
`focusin`/`focusout` on `document` and asks `container.contains(event.target)`,
which inside a root is always false — the target is the container's own ancestor.
`lastFocusedElementRef` is therefore never set, the yank-back focuses nothing, and
the `Tab` handler's comparisons against `document.activeElement` can never match.
So a MODAL dialog no longer traps focus: tabbing past its last control leaves for
the host page. `aria-hidden`'s `hideOthers` degrades the same way, walking
`host.children`, which is empty.

That is this ticket's stated go/no-go, and it is only half passed. Recorded in
`src/components/AGENTS.md` beside the dialog's other keyboard reasoning, with what
still works so nobody re-derives it: the dismissable layer decides "inside" from a
React capture handler rather than `event.target`, `react-remove-scroll` resolves
shadow parents explicitly, and close-focus is ref-based. Only the trap and
`aria-hidden` are inert. No fix here — neither library is ours to patch, and the
choice between patching them and the ticket's fallback is the reviewer's.

Three corrections:

`assert-css-scoped.mjs`'s header still opened "The widget has no shadow boundary",
sixty-five lines above its own ⚠ saying there is no style tag to scan for any more.
It now says what the gate is actually for: the standalone shell and Ladle, which
have no boundary and put the same sheet on `<html class="sy-atlas">`.

The audit cited `@mapbox/[email protected]`. That is the version of
`search-js-react`, which declares `^1.0.0-beta.24` and resolves to **1.6.0** — the
file actually read. Every claim holds against it, but a doc whose authority is
"read off the installed version" has to name the right one.

`hoistGeocoderLiveRegion`'s docblock claimed a region is "removed rather than
orphaned". True of unmount, not of a geocoder remounting inside a living
`MapSearch`, which leaves its predecessor in the host's body until `MapSearch`
itself unmounts.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01DouA7ayFHJuXWxpFbYNbqF
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 2, 2026
@sydevs-bot

sydevs-bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running
CI fix 1

recent dispatches
  • 07:00Z resolve-conflicts · attempt 1 · session · done
  • 07:00Z resolve-conflicts · attempt 1 · session
  • 06:52Z address-review · attempt 1 · session · done
  • 06:52Z address-review · attempt 1 · session
  • 21:40Z address-review · attempt 1 · session · done

Written by the sydevs dispatcher. Sessions never edit this comment.

@Ardnived

Ardnived commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Decision: patch the libraries. Keep the shadow root. Fix the focus trap and screen-reader hiding with pnpm patch under pnpm.patchedDependencies, the same way [email protected] is patched. Don't accept the regression, and don't fall back to the per-element baseline.

  • @radix-ui/[email protected]: take the event target from event.composedPath()[0], not event.target. Read the active element through the shadow root instead of document.activeElement (src/lib/active-element.ts already does this). A focus that leaves a modal dialog must come back to it.
  • [email protected] (Radix calls hideOthers): hide the siblings inside the shadow root, so a screen reader sees only the modal dialog. Patch whichever is smaller: Radix's call site or the library's default parent.
  • While you're there, check [email protected]: it decides on event.target too. Wheel and touch scrolling inside a modal drawer must still work.
  • A regression test for each patch, and the patch's reason in src/components/AGENTS.md.

The WordPress plugin's browser lane reads the widget's DOM directly. I'm updating it to read through the shadow root, in a separate sydevs/SahajAtlasWordpress PR, and will post its results against this PR's preview here.

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧐 Adversarial review

The diff is the size of the problem. A one-line mount flip plus exactly the consequences it forces — the sheet's new home, two focus reads, the retired reset, two boundary defects found and fixed. Nothing is smuggled in, and every new module traces to the boundary. On scope this is disciplined work.

Two things stand between it and merge. The acceptance evidence cannot be produced as the ticket specifies it, because the lane that produces it cannot see inside a shadow root (blocker below). And the ticket named Phase 1 item 1 the go/no-go and wrote the fallback in advance; it half-failed, and the PR hands the decision up instead. That is a fair call — but the focus audit the decision rests on stops short, so the cost is still understated.

Contracts: the sahaj-atlas-style break is clean — an org-wide search finds the id in no consumer, only in this repo. The host-children contract is the one that went unrecorded.

Findings

  • blocker — sydevs/SahajAtlasWordpress tests/browser.mjs:338 does element.querySelector('.sy-atlas'), which does not pierce a root. So m.scope is false, the fit at :472 fails on all 18 cells × 4 viewports, and :474 returns before the typeface verdict — the lane reports "no .sy-atlas" 72 times, not 0/72. Worse if only scope is fixed: :512 counts font === null as a pass, so a lane that still cannot probe scores a vacuous 0/72. document.elementFromPoint also answers with the host, so inputHitInScope (:371) fails too. That lane needs updating before it can be acceptance evidence; filing it on the plugin repo is the cheap path.
  • should-fix — src/components/AGENTS.md:380: "only the trap and aria-hidden are inert" misses FocusScope's mount auto-focus, which breaks on the same retargeting. Thread names the mechanism and the one exposed surface (the report modal).
  • should-fix — docs/embedding.md:964: a host's own children of <sahaj-atlas> stop rendering at element upgrade, and WeMeditateWeb's whole /map route family is built on them being replaced. Unrecorded in both contract files.
  • should-fix — scripts/assert-css-scoped.mjs:10: the stated reason the scoping pass survives is the weak one; the load-bearing reason is unstated, and a reader who accepts the stated one can retire the pass and unstyle the embed.
  • consider — src/components/organisms/Mapbox/aria-live.ts:33: this repo already patches a dependency (patches/[email protected]), so the rejected alternative is house practice rather than a last resort.
  • consider — src/components/AGENTS.md:372: the aria-hidden mechanism named is not what the library does, though the conclusion holds.

What was checked

Ticket #236 against the full diff (origin/main...f9c8c35, 25 files). Read whole: styles/sheet.ts, Widget.tsx, main.tsx, vite.config.ts's styleSink, lib/active-element.ts, DrawerStack/sheet-wake.ts, Mapbox/aria-live.ts, styles/globals.css, scripts/assert-css-scoped.mjs, scripts/postcss-scope-widget.mjs, the five new spec files, and the three doc files.

Installed sources, since every claim in the PR body is about one: @radix-ui/[email protected] (focusFirst, handleFocusIn, getTabbableEdges, the mount effect), @radix-ui/[email protected] (confirmed — "inside" comes from a React onPointerDownCapture, not event.target, so the PR's claim holds), @radix-ui/react-dialog (onOpenAutoFocus not prevented; onCloseAutoFocus is ref-based, so close-focus does work), [email protected] (prevents it when autoFocus is false), [email protected], @r2wc/[email protected] (attachShadow in the constructor).

Consumer sides followed: sydevs/SahajAtlasWordpress — tests/browser.mjs measure() and its verdicts, assets/atlas-page.css (targets only the element's own box; unaffected), the printed element (empty, so no light-DOM concern there). sydevs/WeMeditateWeb — pages/map/+Page.tsx, types/sahaj-atlas.d.ts, lib/atlas-embed.ts. Org-wide code search for sahaj-atlas-style: 4 hits, all in this repo.

Not checked: the branch was not built or run, and no browser was used — every Manual-verification item the PR lists as owed is still owed. Reviewer profile read.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread src/components/AGENTS.md Resolved
Comment thread docs/embedding.md Resolved
Comment thread scripts/assert-css-scoped.mjs Resolved
Comment thread src/components/AGENTS.md Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 2, 2026
@Ardnived

Ardnived commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

The browser lane approves this preview (4336c065, every cell): 0 failures. Run it with SAHAJ_ATLAS_WIDGET_FROM from sydevs/SahajAtlasWordpress#56.

Widget Typeface leaks
Production 24 page checks, all h2, six themes
This PR 0

The overlays, stacking, hit tests and the compact card pass inside the shadow root. One finding is left, on Enigma at laptop size: the search input and one link use Mapbox Search JS's own system font stack. That's the library's font, not the theme's.

⚠ "61 of 72 page checks" is wrong, and this PR cites it five times: in CHANGELOG.md, docs/embedding.md, src/Widget.tsx, src/styles/globals.css and scripts/serve-embed-review.mjs. The lane's probe read Mapbox's own Helvetica Neue on its attribution link and zoom buttons as a theme leak. #56 corrects the probe. The real figure is 24 h2 checks on Enigma, Esotera, Fluida, Mesmerize, Seva Lite and Twenty Twenty-Four. Please correct all five.

claude added 5 commits October 2, 2026 02:03
The reviewer's decision on #236: keep the shadow root and patch the two
libraries that cannot see through it, rather than accept the regression or
fall back to a per-element baseline.

`@radix-ui/react-focus-scope` takes its focusin target from
`composedPath()[0]`, resolves every `activeElement` read through the
boundary, and exempts a `relatedTarget` that is the container's own shadow
host — a focusout between two of our own controls retargets too, and would
otherwise read as an escape and yank focus back. That also fixes the mount
auto-focus, which walked every tabbable because `focusFirst`'s early exit
compared the host with itself.

`aria-hidden` keeps the real target instead of rewriting it to the host,
crosses the boundary in `keep()` through `ShadowRoot.host`, and descends
into a kept shadow root in `deep()`. Descending puts the widget's own live
regions in the sweep's reach, so the library's issue-10 exemption is
collected from the target's root as well as from the document.

`[email protected]` needed nothing: it records
`getOutermostShadowParent(target)` and matches document-level events
against it, and `handleScroll` bubbles through hosts explicitly.

Both libraries become pinned devDependencies so the spec imports the same
patched instance Radix resolves. Each behavioural assertion was confirmed
RED against its own defect reintroduced in the installed bundle, then
restored. The focusout half has no behavioural spec and the file says why:
its symptom needs the browser's real ordering, which jsdom does not give,
and a vacuous pass is worse than none.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01H9G2b2rcv5SxpLtwpbVSdi
…anism

Two review threads. "Only the trap and `aria-hidden` are inert" missed
`FocusScope`'s mount auto-focus, which breaks on the same retargeting. And
the `aria-hidden` mechanism named was not what the library does: it does
not walk `host.children`, it stops because `elementsToStop` holds the
host. The conclusion held; the mechanism is what a later author reasons
from.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01H9G2b2rcv5SxpLtwpbVSdi
`@r2wc/core` attaches the shadow root in the constructor, so light-DOM
children are hidden at element upgrade, before `connectedCallback` can
decline. With no `<slot>` they never paint, and the duplicate-element
return leaves a blank box where a host's fallback used to stay visible.
Neither contract file recorded it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01H9G2b2rcv5SxpLtwpbVSdi
"Repaints the page around it" names no third party on the two builds we own
whole, so a reader who accepts it can retire the pass and unstyle the
embed. The real reason is the root-selector rewrite: there is no `html`
inside the shadow root to match.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01H9G2b2rcv5SxpLtwpbVSdi
The docblock rejected a dependency patch as a matter of principle while
this repo carries three. The hoist stays, with the reason stated and the
patch that would also cover the `activeElement` comparisons named as the
follow-up.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01H9G2b2rcv5SxpLtwpbVSdi
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Decision implemented — both libraries patched (4e47c39)

  • react-focus-scope — focusin target from composedPath()[0], activeElement read through the boundary, a relatedTarget equal to our own host exempted. Fixes the trap, the Tab edges and mount auto-focus.
  • aria-hidden — keeps the real target and descends into the kept root. Descending reaches our live regions, so the issue-10 exemption is collected there too.
  • [email protected] — no patch needed. It matches events against getOutermostShadowParent(target).

src/lib/shadow-patches.test.ts: each behavioural assertion confirmed RED against its defect reintroduced in the bundle. ⚠ The focusout half has none — jsdom will not reproduce the ordering its symptom needs, a drift pin stands in.

Also adopted: host children, the gate's reason. Open: the hoist, argued. The browser lane is yours.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Oct 2, 2026
@sydevs-bot
sydevs-bot marked this pull request as ready for review October 2, 2026 02:11
@sydevs-bot
sydevs-bot requested a review from Ardnived October 2, 2026 02:11
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Answered 1. No commit — the answer was already in the tree, so head stays at e3a0d53.

Two threads stay open and both are yours to settle: that one, and the shadow-DOM library.
🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. awaiting labels Oct 3, 2026
Ardnived asked to raise the browser baseline and delete whatever legacy code
that frees. Recording the answer at the loop, because the question has now
been asked twice and nothing in the tree answered it.

CSS anchor positioning is the only candidate for retiring the --sy-sheet-top
mirror, and no build.target raise reaches it. caniuse has Firefox at partial
support only, so a Firefox floor cannot buy it at any version. anchor() is
invalid in the max-h that Fallbacks reads. And it would cover one of the
three --sy-sheet-top consumers, leaving the loop running for the other two.

build.target is not set in vite.config.ts at all — it rides Vite 8's
baseline-widely-available default, verified as chrome111, edge111,
firefox114, safari16.4, ios16.4. Pinning a number to raise it would freeze
what currently moves forward on its own.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011qX6rH5eHD2Rz1o2dTtWTr
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Rebutted 1, asked 1. 2448e6a. Lean gate green: lint, typecheck, 1659 tests.

  • Open — raise the baseline. Not raised, and no number guessed:
    • Anchor positioning is the only thing a floor could buy here, and caniuse has Firefox at partial support only. No build.target reaches it.
    • chore(deps): upgrade tailwindcss 3 → 4, which is also the exit from the unpatched braces advisory #247 does not move build.target. Its 128 is Tailwind 4's declared stylesheet minimum, and its diff says the JavaScript target is unchanged. It edits the docs/embedding.md table this PR leaves alone.
    • Nothing waits to be deleted: zero @supports, zero vendor prefixes, no UA gating in src/. build.target is not set at all — it rides Vite 8's default, read off the installed Vite as chrome111, firefox114, safari16.4.

Which floor, and to buy what? If it is the published one, #247 owns that table.

Also open: the shadow-DOM library.
🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 3, 2026
Comment thread src/lib/active-element.ts Resolved
Comment thread src/views/DrawerStack/sheet-wake.ts Resolved
@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Oct 4, 2026
The recorded reason was wrong on its first clause. caniuse-lite 1.0.30001810,
the copy this repo pins, has css-anchor-positioning at FULL support in Chrome
and Edge 125+, Firefox 147+, Safari 27+, iOS Safari 26+ — no partial row for
any engine. So "Firefox ships only partial support" cannot carry the verdict.

The verdict still holds on the reason that does: anchor() is valid only in
inset properties, and Fallbacks' CENTERED_BODY reads --sy-sheet-top in
max-height. That consumer keeps the loop running at any build.target.

The count was wrong too. Two of the three readers are inset reads — the peek
strip's top and DrawerFooter's sticky bottom — so converting them trades one
mechanism for two and deletes nothing.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_018sN6LaUwMPVPooSDAMchDK
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Rebutted 2. 06a1205. Lean gate green: lint, typecheck, 1659 tests.

  • Open — raise the baseline. My "Firefox partial" was wrong: the pinned caniuse-lite has anchor positioning full in Chrome/Edge 125+, Firefox 147+, Safari 27+, iOS 26+. The verdict holds on the other reason — anchor() is valid only in inset properties, and Fallbacks.CENTERED_BODY reads --sy-sheet-top in max-height, so that reader keeps the loop at any build.target. Two of the three readers are inset reads, not one, so converting them trades one mechanism for two. 06a1205 corrects both errors at the loop.
  • Open — a shadow-DOM library. focus-trap stays unreachable: react-dialog hard-codes trapFocus: context.open on its FocusScope, which dialog, popover and select all mount. No next step.

Both threads are yours to settle.
🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 4, 2026
#247 moved the stylesheet to Tailwind 4 CSS-first config and split the
#156 defensive reset out into src/styles/host-reset.css. This branch
retires that reset, because the shadow root is the boundary now. Both
intents are kept: globals.css takes main's v4 part-imports, @source and
@theme wholesale, and #236's retirement lands in host-reset.css, where
the reset now lives — the `all: revert` rule is gone, the retirement note
and the inherited `.sy-atlas` baseline stay, still unlayered and still
ahead of preflight.

- package.json: both of this branch's pinned patch targets stay, main's
  @tailwindcss/postcss stays, and `autoprefixer` goes — v4 prefixes
  through lightningcss, and postcss.config.js no longer loads it.
- pnpm-lock.yaml: regenerated from main's lockfile by `pnpm install`.
- scripts/audit-baseline.json: main's side. This branch had booked the
  braces advisory against tailwindcss 3; #247's v4 upgrade took all six
  paths to it out of the graph, so the list is empty rather than waived.
- scripts/postcss-scope-widget.test.ts: this branch's assertions, aimed
  at host-reset.css, which is where the reset it pins against moved.
- CHANGELOG.md and docs/embedding.md: both sides' entries. The exception
  list is six now — the live region and the @Property registrations are
  separate facts a host can observe.

Gates: lean gate ✓ (135 files, 1665 tests), build ✓ with assert:css
(1176 rules, 3 sheets, 62 @Property allowlisted) and assert:maps ✓,
`pnpm size` ✓ (standalone 308.2/318, loader 2.7/3.5, embed 310.0/318
KiB), `pnpm audit:check` ✓ (0 new high or critical).

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0117YshqyPTLWEVcZ65d7DHa
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Merged main (#247, Tailwind 4) in. Two hunks were not mechanical.

The reset. #247 split the #156 reset into src/styles/host-reset.css; this branch retired it in globals.css. So globals.css takes main's v4 part-imports and @theme whole, and #236's retirement lands in host-reset.css: no all: revert, the note and the unlayered .sy-atlas baseline kept, still ahead of preflight. postcss-scope-widget.test.ts reads that file now.

The audit baseline. This branch waived the braces advisory against tailwindcss 3. v4 took all six paths to it out of the graph, so the list is empty rather than waived — main's side.

autoprefixer also goes: v4 prefixes through lightningcss. The host-observable exception list in docs/embedding.md is six now, counting both the live region and the --tw-… registrations.

Gates: lean ✓ (1665 tests), build ✓ (assert:css 1176 rules, 62 @property), size ✓, audit:check ✓.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot
sydevs-bot added this pull request to the merge queue Oct 4, 2026
Merged via the queue into main with commit 92e4e95 Oct 4, 2026
25 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-236-shadow-dom branch October 4, 2026 18:16
Ardnived added a commit that referenced this pull request Oct 10, 2026
…ile (#268)

The Dependency Audit job audited every production dependency in the
lockfile, so a new advisory against one already on main failed every
open PR. From 2026-09-30 to 10-03 it failed #233, #237, #243 and #248,
none of which touched a dependency, and fix-ci rewrote overrides and the
baseline on those unrelated PRs.

The shared Dependency Review job from sydevs/claude-workflow fails only
when a PR adds a high or critical runtime advisory. Advisories already
on main are the loop's daily Dependabot check's to fix. audit.yml, the
baseline and check-audit.mjs go with the old gate.

Co-authored-by: Claude Opus 5.5 <[email protected]>
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(ui): host CSS without !important still restyles widget text

3 participants