Skip to content

Fix Vite input dependency rebuild race - #20525

Open
irontaek wants to merge 2 commits into
tailwindlabs:mainfrom
irontaek:fix/vite-await-input-dependency
Open

irontaek wants to merge 2 commits into
tailwindlabs:mainfrom
irontaek:fix/vite-await-input-dependency

Conversation

@irontaek

@irontaek irontaek commented Sep 27, 2026 •

Copy link
Copy Markdown

Summary

Root.generate() started recording the input stylesheet's modification time without awaiting it. When that stat was slower than compilation, the first transform returned with no input entry in buildDependencies; a subsequent transform could reuse the old compiler after the stylesheet changed.

Await that dependency record before compiling. The integration test holds just this stat pending until it checks the first response, then edits the root stylesheet and checks that the Vite dev server serves the new theme value. The held-stat test failed before the fix and passes afterward.

Test plan

  • pnpm build — passed.
  • pnpm test:integrations run vite/input-dependency-race.test.ts — failed before the fix (first response returned while the input stat was pending), passed after.
  • pnpm test:integrations run vite/input-dependency-race.test.ts vite/config.test.ts -t 'rebuilds when the input stylesheet changes before its dependency stat finishes|Config files \(CJS, dev mode\)' — 2 passed.
  • pnpm exec prettier --check integrations/vite/input-dependency-race.test.ts packages/@tailwindcss-vite/src/index.ts — passed.

pnpm lint did not complete locally: its repository-wide Prettier pass inspected generated WASM build files, and a separate package TypeScript pass reported errors outside the changed files.

@irontaek
irontaek requested a review from a team as a code owner September 27, 2026 10:48
@greptile-apps

greptile-apps Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Fixes a race condition in the Vite plugin rebuild logic.

The PR appears safe to merge, though the regression test can still miss the race when the first stylesheet response takes more than five seconds.

Reviews (2) · Last reviewed commit: "test: hold Vite input stat through regre..."

) {
delayed = true
await fs.writeFile('input-stat-delayed', 'yes')
await new Promise((resolve) => setTimeout(resolve, 1500))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Fixed delay weakens race test

The test holds the input file’s stat for only 1.5 seconds. If the first stylesheet response takes longer than that, the stat can finish before the test edits the CSS, so the test may pass even without the fix. Keep the stat pending until the edit to make the regression test reliable.

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: f068906b-48e8-4c59-a9fe-26612fba9443

📥 Commits

Reviewing files that changed from the base of the PR and between 4187908 and 5e160e9.

📒 Files selected for processing (1)
  • integrations/vite/input-dependency-race.test.ts

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


Walkthrough

Root.generate now waits for input CSS build dependency registration to complete. A Vite integration test delays the stylesheet stat during startup, checks the initial red theme, changes the theme to blue, and verifies the rebuilt styles include the text-brand candidate and blue theme value.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 5e160

The change makes stylesheet generation wait for dependency registration, and the integration test covers the delayed-stat rebuild. No material merge risk is evident.

Architecture Summary

Architecture risk: 🔵 Low · up to 5e160

The change affects 2 systems.

Changed systems: integrations, packages/@tailwindcss-vite

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — integrations (service) was modified; 1 changed file maps to changed impact.
  • observed — packages/@tailwindcss-vite (library) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in packages/@tailwindcss-vite/src/index.ts: Root.generate now awaits registration of the input file as a build dependency instead of calling the asynchronous method without waiting.
  • observed — Modified behavior in integrations/vite/input-dependency-race.test.ts: Adds the Vite test fixture, including a fs.stat wrapper that pauses the first matching index.css stat from addBuildDependency after the stat completes. It records the pending stat and waits for the release file instead of using a fixed 1.5-second delay.
  • observed — Modified behavior in integrations/vite/input-dependency-race.test.ts: The test starts the initial stylesheet fetch while the stat is pending, checks that it does not complete within five seconds, releases the stat, and verifies the initial response contains the red theme. It then changes the theme to blue and retries until the styles contain the text-brand candidate and blue theme value.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely identifies the main change: fixing a Vite input dependency rebuild race.
Description check ✅ Passed The description directly explains the race condition, the await-based fix, the integration test, and the reported validation results.

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.

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