Repository navigation
Description
Summary
The widget injects its stylesheet into the host document (light DOM, vite-plugin-css-injected-by-js — no shadow boundary), and that stylesheet currently carries a full unscoped CSS reset, globally-named utility classes, :root-level custom properties, whole third-party library stylesheets, and a runtime Google Fonts @import. Appended after the host's own stylesheets, it wins ties and visibly restyles the embedding page — a WordPress theme's links, headings, lists and forms change the moment the widget script loads. This violates the repo's own rule (.claude/rules/components.md: the injected stylesheet "lands in the HOST document, so every selector in it must be scoped to our own DOM") — the previously hand-removed main {}/a {} leaks were cosmetic; the real leak is upstream in Preflight and the config. Ship-blocker #1 of the release-readiness review.
Bundled into this ticket: self-host the Raleway font. src/styles/globals.css:1 runtime-@imports Google Fonts from inside the injected style — a GDPR exposure for EU hosts (German court precedent on Google Fonts disclosing visitor IPs, LG München I 3 O 17493/20) and it forces every host CSP to allow fonts.googleapis.com + fonts.gstatic.com. Bundling the font files removes both problems at once.
Evidence (verified against the working tree, 2026-08-06)
- Tailwind Preflight ships unscoped:
@tailwind baseatsrc/styles/globals.css:19;tailwind.config.jshas nocorePlugins.preflightdisable and noprefix/importantscoping strategy. The built bundle contains the full reset —a{color:inherit;text-decoration:inherit}, zeroedh1–h6/list/blockquotemargins,border:0on the universal selector, form-control resets — applied to every element of the host page. - Generated utilities land globally, including
.container(a guaranteed Bootstrap/theme collision),.hidden,.sr-only, etc. - Hand-written unscoped selectors in
src/styles/globals.css::root-level palette custom properties::root, .light, .light-theme+.dark, .dark-themeblocks (lines 30–117), plus the Radix Colors imports (lines 14–17), whose own files scope to:root, .light/.dark..dark/.dark-theme— extremely common host theme classes; a host using.darkfor its own dark mode receives our palette variables..flex-center/.flex-center-x/.flex-center-yutilities (lines 198–208)..colored-linkswith!important(lines 215–221).- Top-level
[data-vaul-drawer]media-query rule (lines 124–128). - Top-level
@importofmapbox-gl/dist/mapbox-gl.css, threeswiper/css*sheets, and the vendored./vaul.css(lines 1–7) — these restyle a host page running its own Swiper or Mapbox GL instance.
- Runtime Google Fonts
@importatsrc/styles/globals.css:1(verified in the shipped bundle).
Proposed changes
Implementation options — pick per sub-problem; don't feel bound to a single mechanism:
- Preflight:
corePlugins: { preflight: false }plus a minimal hand-rolled reset scoped under a widget-owned class (the theme-root wrapperdivinsrc/Widget.tsx:83–88already wraps the whole tree, and portals are retargeted to it, so a scope class there covers everything) — and/or keep Preflight but scope all Tailwind output with theimportant: '<scope-selector>'strategy and/or aprefix. Whatever the mechanism, the invariant is: no Tailwind-emitted rule can select a host element. - Utilities: the same scoping strategy must cover generated utilities (
.containeret al.) and the hand-written@layer utilities/@layer componentsentries. - Palette variables: rescope from
:root/bare.darkto the widget theme root (the wrapper div already carries the light/dark class); the Radix Colors imports need the same treatment (vendor, or rescope via a PostCSS pass — e.g.postcss-prefix-selector). - Third-party sheets: scope the mapbox-gl / swiper / vaul imports under widget-owned wrappers (the map container,
.sy-carousel, the drawer scope) — a PostCSS prefix pass over the imports, or vendoring, both work. - Font: self-host Raleway (e.g.
@fontsource/ralewayor checked-in woff2 subsets +@font-face), drop the Google Fonts@import. - Build assertion: a small script (e.g.
scripts/assert-css-scoped.mjs) that parses the emitted CSS afterpnpm buildand fails when any top-level selector falls outside the allowlisted widget-owned scopes — wired so CI catches a re-leak.
Acceptance criteria
- After
pnpm build, the emitted CSS contains no top-level selectors outside widget-owned scopes, asserted by a script/unit check runnable in CI (allowlist of widget-owned scope prefixes; the check fails when an unscoped selector reappears). - Host elements outside the widget render identically with and without the widget script on a test page with representative host markup (links, headings, lists, blockquote, form controls, a
.containerelement, a host.darkclass, a host Swiper instance) — no Preflight reset, no utility collision, no palette-variable injection, no third-party-sheet bleed. - The widget still themes correctly from its own theme root: brand palette override, light/dark toggle, and the Radix gray/red ramps all resolve inside the widget.
- Raleway is self-hosted: the widget makes no request to
fonts.googleapis.com/fonts.gstatic.com, and text renders in Raleway. - Visual verification (Ladle + demo.html, Playwright MCP acceptable): drawers + peek strips, calendar view, image carousel (pagination bullets), event-pin popover, and
.colored-linksprose all render correctly after rescoping. - The CSP table in the integrator docs (README) is updated:
fonts.googleapis.com(style-src) andfonts.gstatic.com(font-src) removed as required origins. -
pnpm lint+pnpm typecheck+pnpm test:run+pnpm buildpass. - Write an implementation report to
.claude/reports/91-scope-widget-css.md— in the MAIN checkout at /Users/devindra/Documents/Projects/SahajAtlasWeb even when implementing from a worktree (the folder is gitignored) — covering what changed, what was deliberately NOT changed, and which readiness-report findings are resolved.
Files affected
Owned by this ticket:
tailwind.config.jssrc/styles/globals.csssrc/styles/vaul.css- Font assets (new — e.g.
@fontsource/ralewaydependency or checked-in woff2 +@font-face) - A small build-assertion script (new, e.g.
scripts/assert-css-scoped.mjs) + itspackage.json/CI wiring
Parallel implementation: this ticket OWNS the files listed above; sibling release-hardening tickets are implemented concurrently, so changes outside the owned files must be avoided or kept strictly additive. In particular src/Widget.tsx is owned by the mount-path hardening ticket — if a scope class must be added to its theme-root wrapper, keep that change strictly additive (add a class, touch nothing else).
References
.claude/reports/RELEASE_READINESS.md§3.1, §3.5, Appendix B (local, gitignored — for repo-local implementers; all load-bearing evidence is inlined above).claude/rules/components.md— the scoping rule this violates, and the record of the two prior leaks (main {}/a {},.swiperbullets →.sy-carousel)src/styles/globals.css:176–181— comment documenting the earlier hand-removed leaks- LG München I, 3 O 17493/20 (2022) — Google Fonts / visitor-IP disclosure ruling
- Sibling ticket (same batch):
fix(widget): survive foreign hashes and harden the mount path
Metadata
Metadata
Assignees
Labels
Type
Fields
Hold Until
Activity
fix(ui): keep the page frozen behind the open lightbox
feat(seo): prevent direct indexing of the standalone build (#124)
chore(claude): widen the security-review trigger paths (#139)
chore(build): move the Ladle playground to Cloudflare Workers (#294)