Skip to content

chore(ui): evaluate shadow DOM now that the CSS reset has a measured gap #157

Closed as not planned

Description

@Ardnived

Summary

Evaluate moving the widget into a shadow root, and decide it with evidence rather than
instinct. #156 shipped a defensive CSS reset that blocks host styles reaching into the widget —
but it has one measured, irreducible gap, and shadow DOM is the only thing that closes it.

The gap the reset cannot close

:where(.sy-atlas) :where(*) { all: revert } blocks non-!important host CSS completely.
Verified in a browser against a deliberately hostile stylesheet: a global button { … },
a { color }, letter-spacing, line-height and font-family are all stopped.

A host rule carrying !important still wins, because an important author declaration beats a
non-important one whatever its specificity. The only way to outrank it from a stylesheet would be
all: revert !important, which would equally beat every rule of ours and render the widget
unstyled — strictly worse than the problem.

Inside a shadow root the question does not arise: host selectors do not match shadow descendants at
all, !important or not. Only inherited properties cross, and those are already handled by the
baseline the reset ships.

What the evaluation must cover

Each of these is a known obstacle, not a hypothetical — they are why the widget is shadow-free
today, and each needs an answer before adopting:

  • @font-face cannot be registered inside a shadow root in current engines. The widget declares three (src/styles/fonts.ts). Verify current Chrome/Safari behaviour rather than trusting the folklore, and decide where they live if the rest moves.
  • Every portal target changes. overlayContainer() (src/lib/overlay.ts) can point at a shadow root, but Radix's dismissible-layer and focus machinery use document-level listeners and document.activeElement, which returns the host element across a shadow boundary. Focus trapping, click-outside and Esc all route through that.
  • vite-plugin-css-injected-by-js appends to document.head, not a shadow root. Changing that has its own gate implications: pnpm assert:css reads the CSS back out of the emitted bundle, and postcss-scope-widget.mjs rewrites every selector to :where(.sy-atlas) — which becomes unnecessary inside a shadow root, so the pass and its gate are in scope too.
  • Mapbox GL has known shadow-root issues with document.elementFromPoint; the geocoder is itself a shadow-DOM custom element.
  • ⚠ It does NOT fix vaul's window-height arithmetic, which is the thing map mode actually needs. Adopting shadow DOM would not make map mode containable — that is a separate problem and should not be used to justify this one.

What would justify it

Not "isolation is nicer". One of:

  1. A host we actually need to support ships !important global CSS that breaks the widget, and cannot or will not change it.
  2. The reset's measured cost becomes a problem. Today a forced style recalc over 3,200 nodes inside the scope costs ~2× one outside it (41ms vs 20ms across five recalcs, Chrome 151) — accepted because full recalcs are rare and the results list is bounded by MAX_REVEAL. If that ceiling rises, re-measure.

Absent either, the reset is the right trade and this ticket stays open as the recorded alternative.

Acceptance criteria

  • A written decision, with the @font-face and Radix-focus questions answered from observed behaviour in current engines rather than from documentation or memory.
  • If adopted: the scoping pass and assert:css are reconciled (either retired or re-aimed), and focus/dismiss/Esc are verified in a browser across the boundary.
  • If declined: docs/embedding.md's note about !important stays accurate, and this ticket records what would reopen it.

References

Activity

  1. added theissue type on Aug 28, 2026
  2. Ardnived commented on Aug 29, 2026

    @Ardnived
    ContributorAuthor

    @sydevs-bot Investigate this issue, analyze actual performance and maintainability and provide a reasoned verdict on whether we should go ahead with a shadow DOM or close this ticket.

  3. sydevs-bot commented on Aug 29, 2026

    @sydevs-bot
    Contributor

    I haven't started this — the ticket carries no approved label, and that gate covers investigations too. An "evaluate and decide" ticket ends in a written verdict rather than a PR, but it is still work with a real cost, so it queues like anything else. I'm not going to read the request as the gate, and I won't apply the label myself.

    Flagging that explicitly rather than quietly doing it, because a comment asking for work reads a lot like permission to start, and it isn't. Add approved and the next run picks this up.

    What it would cost, so the label is an informed decision rather than a blank cheque:

    This is a browser-verification ticket, not a reading ticket. Your own acceptance criteria are what make it expensive — they require the @font-face and Radix-focus answers to come from observed behaviour in current engines rather than from documentation, and that judgement is right: both are areas where the folklore is stale and confidently wrong, and this repo has been bitten by exactly that twice (container-type not establishing a containing block; mapbox-gl's .d.ts contradicting its own source on followUserLocation). So the work is a Playwright session against a real shadow-root prototype, not a survey.

    Concretely, four things get measured:

    1. @font-face inside a shadow root — whether current Chrome/Safari still refuse it, and if so whether the three faces in src/styles/fonts.ts can stay in the host document while everything else moves.
    2. Radix across the boundary — document.activeElement returns the host element from outside a shadow root, and dismissible-layer, focus-trap and Esc all route through document-level listeners. This is the one most likely to sink it, and it cannot be answered by reading Radix's source alone.
    3. Mapbox GL's document.elementFromPoint, plus the geocoder, which is itself a shadow-DOM custom element being nested inside another.
    4. The gate reconciliation — postcss-scope-widget.mjs and assert:css exist to prove every rule is confined to .sy-atlas. Inside a shadow root that is structural, so the pass and its gate are either retired or re-aimed. That is a real chunk of the work and it lands whichever way the verdict goes.

    One question that might settle this far more cheaply, and it's yours to answer rather than mine to measure. The ticket already sets the bar in "What would justify it", and condition (1) is the live one: a host we actually need to support ships !important global CSS that breaks the widget, and cannot or will not change it.

    Do we have one? If yes, that is the decision — the reset provably cannot beat an important author declaration without all: revert !important, which would flatten our own styles too, so shadow DOM is the only remaining answer and the evaluation becomes an implementation plan. If no, condition (2) is the fallback, and it currently reads as "not yet": the measured cost is ~2× a recalc outside the scope (41ms vs 20ms over 3,200 nodes, Chrome 151), accepted because full recalcs are rare and the list is bounded by MAX_REVEAL — and that ceiling has not moved.

    With no host in category (1) and MAX_REVEAL unchanged, the honest verdict is likely "declined, reset stands, ticket stays open as the recorded alternative" — which is the outcome your own acceptance criteria already anticipate. Worth knowing that before spending a browser session to reach it.

    I have left the body alone: it is already precise about scope, obstacles and what would justify adoption, and there is nothing in your comment that changes it. It needs the label, not a rewrite.

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


    Generated by Claude Code

  4. Ardnived commented on Aug 29, 2026

    @Ardnived
    ContributorAuthor

    We do not have any known clients that ship !important, but I don't want to keep this ticket open. We can close it if we don't want to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    Priority

    Low

    Hold Until

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions