Skip to content

fix(styles): scope bk-utilities layer to .bk-root / .bk-portal-content#139

Merged
StephenTangCook merged 3 commits into
mainfrom
claude/adoring-galileo-7c17d7
Jul 2, 2026
Merged

fix(styles): scope bk-utilities layer to .bk-root / .bk-portal-content#139
StephenTangCook merged 3 commits into
mainfrom
claude/adoring-galileo-7c17d7

Conversation

@StephenTangCook

Copy link
Copy Markdown
Contributor

Summary

Scope the compiled bk-utilities cascade layer to the package's own roots so its ~1485 generic Tailwind utilities apply only under .bk-root / .bk-portal-content (and their descendants), instead of leaking into the whole host document.

Why

styles.css imports the full Tailwind utility set into a global bk-utilities layer. Consumers (e.g. Studio) import '@tightknitai/block-kitchen/styles.css' into the host document, so those generic utilities (hidden, table-cell, …) apply document-wide. Studio ranks bk-utilities last to make the Builder render, which lets bk's .hidden override host styles app-wide, breaking every non-md hidden → show reveal. See ENG-5125 / ENG-5124.

What changed

  • scripts/scope-utilities.mjs (new) — postcss post-build step. Parses the compiled stylesheet, finds the single @layer bk-utilities { … } block, and wraps its rules in @scope (.bk-root, .bk-portal-content) { … }. Parses structure (not regex) so the minified input stays safe; postcss preserves each rule's minified raws, so no re-minify step is needed. Throws unless it finds exactly one utilities-layer body (guards against future Tailwind emission changes).
  • package.jsonbuild:css now runs the script after tailwindcss --minify; added postcss as an explicit devDependency (was a non-hoisted pnpm transitive, unresolvable at the top level under strict node_modules).

Bare @scope selectors match the scope root itself, so .bk-root's own utilities (flex h-full …) still resolve — a plain descendant-combinator wrap would miss the roots. bk-theme (CSS custom properties) and Tailwind's internal properties layer stay global; vars don't collide.

Test plan

  • pnpm typecheck
  • pnpm lint
  • pnpm test
  • Ran the full build:css pipeline against the real compiled stylesheet: exactly one @scope inserted, output re-parses with postcss, braces balanced. Verified a bare <span class="hidden sm:table-cell"> outside .bk-root is no longer clobbered.
  • Spot-check Builder renders identically (utilities still win inside .bk-root; dialogs/popovers under .bk-portal-content still styled, incl. dark mode).

Notes for reviewer

  • dev:css (watch) intentionally does not run the scope step — local dev renders under .bk-root so unscoped output is fine there.
  • Follow-up (separate, after release): in web-studio-start, revert the @layer order stopgap and remove the !important workarounds.

🤖 Generated with Claude Code

The compiled stylesheet imports the full Tailwind utility set into a
global `bk-utilities` layer. Because consumers import styles.css into the
host document, those ~1485 generic utilities (`hidden`, `table-cell`, …)
apply document-wide and override host styles, breaking Studio reveals.

Add a postcss post-build step that wraps the `bk-utilities` layer's rules
in `@scope (.bk-root, .bk-portal-content) { … }`, so utilities apply only
under the package's own roots (and their subtree) and nowhere else. Bare
`@scope` selectors match the scope root itself, so `.bk-root`'s own
utilities still resolve. `bk-theme` vars stay global (no collisions).

Closes ENG-5125.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
block-kitchen 8e10dae Commit Preview URL

Branch Preview URL
Jul 02 2026, 03:28 AM

StephenTangCook and others added 2 commits July 1, 2026 20:22
Add the postcss direct-dependency specifier so `pnpm install
--frozen-lockfile` passes in CI. Resolves to 8.5.15, already present
transitively.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Extract the layer-wrapping logic into an exported pure `scopeUtilities`
function and add a unit test: verifies utilities get wrapped in @scope,
the ordering statement and bk-theme layer stay global, and the
one-body-expected guard throws. Also drop the stray ticket ref from the
file header comment.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@StephenTangCook StephenTangCook merged commit c12ee96 into main Jul 2, 2026
13 checks passed
@StephenTangCook StephenTangCook deleted the claude/adoring-galileo-7c17d7 branch July 2, 2026 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant