Skip to content

Stop builds from hanging on mutually interpolated class names - #102

Merged
nstepien merged 2 commits into
mainfrom
fix-cyclic-interpolation-hang
Oct 16, 2026
Merged

nstepien merged 2 commits into
mainfrom
fix-cyclic-interpolation-hang

Conversation

@nstepien

@nstepien nstepien commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

To resolve a class name imported from another module, a module's transform waits for this.load() of that module, which runs that module's transform. When two modules interpolate each other's class names, each transform waited for the other to finish, and the build never completed.

Changes

  • Track which module each running transform is waiting for (pendingLoads), and skip loading a module whose transform is already waiting for the current one, directly or through other transforms (isWaitingFor). That module's transform parsed it before resolving anything, so its exported values come from the cache.
  • Only loads that would close a cycle are skipped. Transforms that run concurrently without waiting for each other still wait for the loads they need, so they register their stylesheets as before.
  • Within a cycle, the module whose load was skipped has not registered its stylesheet yet, so its importer cannot import that stylesheet ahead of its own. Every rule is still emitted, in the order the other module imports them. Import stylesheet dependencies in the Vite dev server #100, stacked on top, extracts the skipped module's stylesheet on demand.

Tests

  • New fixtures cycle-a.ts and cycle-b.ts, whose CSS interpolates each other's class names. A Vite build of them timed out before this change and now completes with both rules.
  • A three-module cycle (A → B → C → A) also builds, with all three rules when the package is not sideEffects: false.
  • All existing snapshots pass, including the cross-module interpolations.

Test plan

  • node --run format:check, lint, typecheck, build
  • node --run test: 16/16 against the source and against the built dist (CI=true)
  • The new test times out without the fix

🤖 Generated with Claude Code

@nstepien
nstepien added this pull request to stack #103 October 15, 2026 17:15
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7a5355f4-ac4d-4e72-97b5-cc99e2c9ae94
  • 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

Comment @coderabbitai help to get the list of available commands.

Base automatically changed from plugin-audit-follow-ups to main October 15, 2026 17:39
To resolve a class name imported from another module, a module's transform
waits for `this.load()` of that module, which runs its transform. When two
modules interpolate each other's class names, each transform waited for the
other to finish, and the build never completed.

Track which module each running transform is waiting for, and skip loading
a module whose transform is already waiting for the current one, directly or
through other transforms. Its transform has parsed it before resolving
anything, so its exported values are read from the cache. Only loads that
would close a cycle are skipped, so concurrent transforms still wait for each
other and register their stylesheets as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nstepien
nstepien force-pushed the fix-cyclic-interpolation-hang branch from f4740c2 to 3cdc545 Compare October 15, 2026 17:40
- Use descendant selectors in the cycle fixtures. TypeScript still needs the
  `: string` annotations, as each class name's type depends on the other's.
- Walk the pending loads recursively, which needs no type annotation.
- Note why buildEnd leaves pendingLoads alone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nstepien
nstepien merged commit ba43976 into main Oct 16, 2026
9 checks passed
@nstepien
nstepien deleted the fix-cyclic-interpolation-hang branch October 16, 2026 01:21
nstepien added a commit that referenced this pull request Oct 16, 2026
#102 changed the CSS of the cycle fixtures, and with it their stylesheet IDs. Merging its branch into this one updated this snapshot, but GitHub restacked this branch onto the squash-merged #102 by replaying only its own commit, which dropped that merge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nstepien added a commit that referenced this pull request Oct 17, 2026
main took in the first slice of this PR (#79) and solved several of its
other problems differently since August, so the merge ports the rest of
this branch onto main's design instead of keeping both:

- Values, class names included, come from the parse of each module, and
  const initializers resolve lazily (#79). Re-exports, `export *`,
  default and namespace imports, and `export default` resolve through the
  same evaluator, with ESM precedence and ambiguity.
- Cycles are handled by main's pendingLoads and isWaitingFor (#102), so
  the wait graph, the deferred same-file passes, and the import-last
  ordering are gone, along with the guard against inlining the class
  names of skipped templates, which needed the imported modules'
  transforms.
- Class names are IIFEs (#87, #98), so `moduleSideEffects: true` is gone.
- Vite's dev server keeps main's behavior (#104) and does not transform
  imported modules through transformRequest. There, the code of modules
  that no file holds comes from their `load` hooks.
- UNREADABLE_MODULE and UNPARSEABLE_MODULE are gone: a module whose code
  cannot be read exports nothing, and modules are parsed as the language
  Rolldown assigned them.
- Kept: raw TypeScript bindings, `meta.moduleType` parsing,
  prologue-safe imports, query-variant module identity, skipping
  external modules, and resolving each import once per transform.

Tests: main's suite, plus this branch's tests of the kept features, with
new cases for the paths that no fixture reached. The tests of the removed
behavior, and the cycle test that main already has, are dropped.
basic.input.ts is restored for main's inlineConst tests, and this
branch's barrel.ts is now barrel-index.ts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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