Repository navigation
Conversation
…ebuggable calls
In `debug` mode (the default outside production), @vanilla-extract/integration's
`transform`/`transformSync` ran every `*.css.ts` module through Babel so that
@vanilla-extract/babel-plugin-debug-ids could attach debug IDs to calls like
`style()`, `createVar()`, and `createTheme()`. But the plugin only ever mutates the
functions in its `debuggableFunctionConfig`. A module that uses only non-debuggable
APIs — `globalStyle`, `globalKeyframes`, `globalFontFace`, `createThemeContract`,
`fallbackVar`, … — was parsed and fully regenerated to produce byte-identical output.
For large generated stylesheets this no-op pass is expensive and also trips Babel's
code-generator deopt ("… has deoptimised the styling of … as it exceeds the max of
500KB").
Introduce `mightHaveDebuggableCalls(source)` in babel-plugin-debug-ids: a cheap,
word-bounded regex compiled once from the keys of `debuggableFunctionConfig` — the
single source of truth for which calls receive debug IDs. integration's
`transform`/`transformSync` now gate the Babel call on it:
`identOption === 'debug' && mightHaveDebuggableCalls(source)`.
Safe against false negatives: a call the plugin acts on must reference a debuggable
name literally — a named import (`import { style }` / `import { style as s }`) or a
namespace member access (`ns.style(...)`) — so the name always appears verbatim in the
source text. The word boundaries keep it from matching the intentionally-excluded
`global*` siblings (`globalStyle` contains `Style`, not a `\bstyle\b`). False positives
(running Babel when nothing changes) simply fall back to today's behavior.
Emitted CSS and debug class/var identifiers are unchanged. Adds a focused unit test
for the helper.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 9b1a958 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
debugmode (the default outside production), @vanilla-extract/integration'stransform/transformSyncran every*.css.tsmodule through Babel so that @vanilla-extract/babel-plugin-debug-ids could attach debug IDs to calls likestyle(),createVar(), andcreateTheme().But the plugin only ever mutates the functions in its
debuggableFunctionConfig. A module that uses only non-debuggable APIs —globalStyle,globalKeyframes,globalFontFace,createThemeContract,fallbackVar, … — was parsed and fully regenerated to produce byte-identical output. For large generated stylesheets this no-op pass is expensive and also trips Babel's code-generator deopt:This shows up when vanilla-extract is generated programmatically from another source
rather than hand-authored — e.g. converting an existing CSS framework to vanilla-extract —
where the emitted per-theme stylesheets can be large and built almost entirely from
globalStyle.Real-world case
The repo where I ran into this:
https://github.com/arijs/bootswatch-solid/tree/ve-literal-converter
(arijs/bootswatch-solid@8cc4201)
Run
Without this optimization, the build is slower than it could optimally be.
Change
@vanilla-extract/babel-plugin-debug-idsexports a new helpermightHaveDebuggableCalls(source: string): boolean— a cheap, word-bounded regex builtfrom the keys of
debuggableFunctionConfig(the single source of truth for which calls getdebug IDs).
@vanilla-extract/integration'stransform/transformSyncgate the Babel call on it:if (identOption === 'debug' && mightHaveDebuggableCalls(source)).Why it's safe (no false negatives)
For the plugin to add a debug ID, the call must reference a debuggable name literally in
the source: either as a named import (
import { style }orimport { style as s }) or anamespace member access (
ns.style(...)). In every case the debuggable name appears verbatimin the source text, so the pre-check sees it. The regex is word-bounded specifically so it
does not match the intentionally-excluded
global*siblings (globalStylecontainsStyle, not a\bstyle\b;styleVariantsmatches its own alternative, notstyle).False positives (running Babel when nothing changes) are harmless — they just fall back to
today's behavior.
Verification
Applied to the built packages and run against a real 27-theme project (~925
*.css.ts,several literal stylesheets >500KB, overwhelmingly
globalStyle):rule normalized and sorted, plus the full set of VE debug class/var identifiers — is
byte-identical with and without the change:
ruleSetSigandidentSetSigidentical across runs.(
ruleSetSig=f2f7b46a…,identSetSig=6592fb7f…) before and after.[BABEL] … deoptimised …notes: 15 → 0 on the full build.~2× on the files that previously hit the >500KB deopt (each such file went from a
multi-second cold Babel compile to being skipped). The win scales with how much of a
codebase is generated
globalStyle.A focused unit test for the helper is included
(
packages/babel-plugin-debug-ids/src/mightHaveDebuggableCalls.test.ts).Test suite status
New helper test —
mightHaveDebuggableCalls.test.ts(12 cases, all pass). Covers thesix ways a debuggable name can appear (named import, aliased import, namespace member call,
the
styleVariants/createVar/layeralternatives) and the six that must not match(
globalStyle,globalKeyframes,globalFontFace,createThemeContract,fallbackVar,and a file with no vanilla-extract at all). The
createThemeContractcase pins theword-boundary guarantee —
\bcreateTheme\bdeliberately does not match across theContractsuffix.(
import { describe, expect, it } from 'vitest'); vitest is configured withoutglobals: true, so a bare-globals test wouldReferenceErrorat runtime.Full unit run (
pnpm test:unit): 436 passed, 1 skipped. The change introduces noregressions across the suite.
Pre-existing, unrelated flakes — not introduced by this PR. Two cases in
packages/turbopack-plugin/src/index.test.ts(a self-described race-condition stresstest, added in turbopack support #1639 / migrated in Migrate all tests to vitest, increase
vite-nodedep range #1694 — untouched by this branch) fail only inside thefull 26-file run and pass in isolation (
pnpm vitest run packages/turbopack-plugin→ 2/2). One is a tight timeout (
10 × 250ms) that the compiler-warmup iteration blowsunder full-suite CPU contention; the other is the shared-compiler staleness race the test
exists to catch. Both are orthogonal to the debug-ids Babel path and out of scope here —
recommend running the turbopack stress test in isolation in CI rather than masking it.
Notes
identOption === 'debug'.short(production) already skips Babel.vanillaExtractTransformPlugin) goes through the sametransform, so it benefits automatically.Local-setup-only changes — NOT included in the PR
To get
pnpm installto complete on my machine (pnpm 11.8), some edits topnpm-workspace.yamlwere required. These are unrelated to the change itself and areleft out of the PR:
trustPolicyExcludeadditions. The repo setstrustPolicy: no-downgrade, which pnpmenforces against every transitive dependency. Several old packages that predate npm
provenance tripped
ERR_PNPM_TRUST_DOWNGRADE(a package whose earlier version had a trustedpublisher but the pinned version has no trust evidence). To install, each flagged name was
added to
trustPolicyExclude:rollup,algoliasearchand the@algolia/*family(
@algolia/recommend,@algolia/client-common,@algolia/client-search,@algolia/logger-console,@algolia/client-analytics,@algolia/requester-node-http,@algolia/requester-browser-xhr,@algolia/client-personalization), andcss-declaration-sorter. These are all pinned by upstream and mostly pulled in by thedocs
site/.allowBuilds: '@parcel/watcher': false. After deps resolved, pnpm'sERR_PNPM_IGNORED_BUILDSdemanded an explicit build-script decision for@parcel/watcher.Set to
falseto match every other native dep in that map (esbuild, sharp, lmdb, … allfalse); the prebuilt binary is used, no local compile.pnpm-lock.yamlchurn /pnpm-lock-git.yaml. Any local lockfile drift is likewise asetup artifact and should not be part of the PR.
None of the above touches the debug-ids Babel path; they only reflect this environment's
supply-chain policy gates.