Skip to content

fix(shared): load css-tree from its self-contained bundle - #9992

Merged
saddlepaddle merged 1 commit into
mainfrom
fix/main-ci-cli-build
Nov 19, 2026
Merged

saddlepaddle merged 1 commit into
mainfrom
fix/main-ci-cli-build

Conversation

@saddlepaddle

@saddlepaddle saddlepaddle commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

What and why

Main's Build CLI / Build linux-x64 smoke step has failed since #9970:

error: Cannot find module '../data/patch.json' from '/$bunfs/root/superset'

Cause. #9970 added css-tree@3 to @superset/shared for sanitizeThemeCss. The CLI imports @superset/shared/themes, so the parser loads when the CLI starts. css-tree's ESM entry reads its syntax data at run time with createRequire(import.meta.url) (../data/patch.json, mdn-data/css/*.json). bun build --compile does not embed files loaded that way, so the compiled binary throws on start, also for --version. Browser bundles (the desktop renderer) were not affected: css-tree's browser map sends lib/data.js to dist/data.js, which has the data inlined. Bun with target: "bun" does not use that map. #9970 is a fork PR and had no CI run of its own, so main was the first Build CLI run with it.

Fix. Import from css-tree/dist/csstree.esm. This is css-tree's own self-contained ESM bundle (public ./dist/* export), with the data inlined. A 3-line ambient declaration re-exports the @types/css-tree types for that subpath. Same version, same API, no behaviour change. No revert of #9970.

Regression test. sanitizeThemeCss.test.ts bundles the sanitizer with Bun.build({ target: "bun" }) and runs the output (~20 ms). It fails with the same patch.json error on the old import.

What breaks

Nothing. Released CLIs were not built from this main commit.

Not in this PR

The cli-framework table hyperlink test failures in recent PR runs have a different cause: they fail when the runner sets TERM=dumb (the tests force isTTY but inherit TERM). #9664 fixes that. It applies cleanly to main and passes under TERM=dumb, so this PR does not duplicate it.

How I verified

  • Built the CLI as CI does (bun run build:dist --target=linux-x64, Bun 1.4.3) and ran packages/cli/scripts/smoke-test.sh. On main it fails with the error above. On this branch it prints [smoke] all checks passed.
  • packages/shared: bun test passes (1762 pass, 0 fail). tsc --noEmit is clean for shared, cli and desktop. biome is clean.
  • The new test fails with the fix reverted and passes with it.

Evidence: https://app.superset.sh/page/mainfix-fix-compiled-cli-crash-on-css-tree-data-fi-2pnpef
Design: https://app.superset.sh/page/admin-cloud-workspace-cost-and-health-design-8z3d4d


Summary by cubic

Fixes the compiled CLI crashing on startup because css-tree's ESM entry reads its syntax data at runtime, which bun build --compile does not embed.

  • sanitizeThemeCss now imports css-tree/dist/csstree.esm, a self-contained bundle with the data inlined; no API or behavior change.
  • Adds a regression test that bundles sanitizeThemeCss with Bun.build so the failure surfaces in bun test.

Written for commit 8b37428. Summary will update on new commits.

View guided diff Turn on auto-fix

Summary by CodeRabbit

  • Chores
    • Improved theme CSS build compatibility in Bun-based environments. No changes were made to how CSS is sanitized or displayed.

css-tree's ESM entry reads its syntax data with createRequire at run
time (../data/patch.json, mdn-data). bun build --compile does not embed
those files, so the compiled CLI failed at start with "Cannot find
module '../data/patch.json'". Browser bundlers use the package's browser
map and were not affected.

Import dist/csstree.esm, which has the data inlined, and add a Bun
bundle test so the bundling break shows in bun test.
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The sanitizer now imports CSS-tree from its ESM entry point, supported by a local TypeScript declaration. A new test checks that Bun can bundle the sanitizer and that the bundled code produces the expected sanitized CSS.

Changes: CSS-tree ESM import

Layer / File(s) Summary
Declare and use the ESM entry point
packages/shared/src/themes/sanitizeThemeCss/css-tree-esm.d.ts, packages/shared/src/themes/sanitizeThemeCss/sanitizeThemeCss.ts
A local ambient declaration re-exports CSS-tree declarations for the ESM entry point. The sanitizer imports CSS-tree from that entry point.
Test Bun bundling and sanitizer output
packages/shared/src/themes/sanitizeThemeCss/sanitizeThemeCss.test.ts
A new test builds the sanitizer with Bun, checks the build result and bundled output, and removes the temporary directory in a finally block.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Possibly related PRs

  • ParadevAI/Paradev#9970: Adds custom theme CSS support and the css-tree@3 dependency that this change continues to use.

Suggested reviewers: atharvamhaske

Merge Risk: Minimal · up to 8b374

This change loads css-tree from its bundled ESM build so the compiled CLI no longer fails to find runtime data files at startup. It also adds a regression test for that case. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(shared): load css-tree from its self-contained bundle" follows conventional commit format and names the main change: switching the css-tree import to its self-contained ESM bundle to fi…
Description check Passed The description follows the template's main sections. The 'What & why' section explains the cause (css-tree runtime data not embedded by bun build --compile), the fix, and the regression test, and it …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(shared): load css-tree from its self-contained bundle" follows conventional commit format and names the main change: switching the css-tree import to its self-contained ESM bundle to fix the compiled CLI startup crash. The changeset matches this: the import moves to css-tree/dist/csstree.esm, a type declaration is added, and a regression test is included.

Full details: Description check

Explanation

The description follows the template's main sections. The 'What & why' section explains the cause (css-tree runtime data not embedded by bun build --compile), the fix, and the regression test, and it describes what breaks. The 'How I tested it' section lists the commands run, the smoke test result, test counts, and the regression test verification. The checklist from the template is not present; the description omits the lint/typecheck, maintainer-edit, and CLA checklist items. It also includes a related-issue reference only indirectly (#9970) and no explicit 'fixes #' link. These are minor gaps and the description is mostly complete.

Resolution

Optionally add the template's Checklist section (PR title convention, lint/typecheck status, fork maintainer-edit setting, CLA signature) and an explicit issue link if one exists.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6de76bfb-5c59-4dd7-ae5f-ffd2361d683c
Commits

Reviewing files that changed from the base of the PR and between d11c453 and 8b37428.

Files selected for processing: 3

  • packages/shared/src/themes/sanitizeThemeCss/css-tree-esm.d.ts
  • packages/shared/src/themes/sanitizeThemeCss/sanitizeThemeCss.test.ts
  • packages/shared/src/themes/sanitizeThemeCss/sanitizeThemeCss.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Preview Deployment

🔗 Preview Links

Service Status Link
Neon Database (Neon) ✅ View Branch
Vercel API (Vercel) ✅ Open Preview
Vercel Web (Vercel) ✅ Open Preview
Vercel Agents Web (Vercel) ➖ Not set up
Vercel Marketing (Vercel) ✅ Open Preview
Vercel Docs (Vercel) ✅ Open Preview

Preview updates automatically with new commits

@expo

expo Bot commented Nov 19, 2026

Copy link
Copy Markdown

Preview update published for development build 0dd268df (fingerprint 08a5e03ce5fb). Open the build on your phone and scan:

Update group 0f08dd56

@saddlepaddle
saddlepaddle merged commit 50851e3 into main Nov 19, 2026
21 checks passed
saddlepaddle added a commit that referenced this pull request Nov 19, 2026
… it (#9995)

* refactor(desktop): sanitize theme CSS only where the renderer applies it

The theme CSS sanitizer is a browser concern: it decides what may go
into the renderer's <style> element. It lived in packages/shared and
also ran at import, so the CLI loaded css-tree through
parseThemeConfigFile. css-tree's Node entry reads JSON with
createRequire, which bun build --compile does not embed, and the
compiled CLI crashed at start. #9992 worked around the bundling.

Import-time sanitizing protects nothing: app-state.json can be edited
by hand or written by any client (CLI, ui-state router), and the
renderer sanitizes on every apply. So:

- Move sanitizeThemeCss next to applyThemeCss in the desktop renderer,
  and css-tree with it. Import plain css-tree again; the renderer
  bundler resolves its browser build.
- parseThemeConfigFile keeps the length check and stores CSS as given.
  MAX_THEME_CSS_LENGTH stays in shared as a plain constant.
- Remove the #9992 shim (css-tree-esm.d.ts and its triple-slash
  reference) and the Bun.build test in shared.
- Add one CLI test that bundles every command and fails if css-tree
  or mdn-data is in the inputs.

* refactor(cli-framework): share the build options with the CSS guard test

Export buildOptions (entry and plugins) from cli-framework and use it in
both runBuild and the CLI bundle test, so the test bundles exactly what
the compiled CLI bundles. Name the test for what it keeps out.

This branch had an error being deployed

1 failed deployment
preview — 8b374285 Deployed Nov 19, 2026 by saddlepaddle via Cleanup Preview Resources #5803
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