Skip to content

Await the stat of the input CSS in @tailwindcss/vite - #20525

Merged
RobinMalfait merged 3 commits into
tailwindlabs:mainfrom
irontaek:fix/vite-await-input-dependency
Nov 23, 2026
Merged

RobinMalfait merged 3 commits into
tailwindlabs:mainfrom
irontaek:fix/vite-await-input-dependency

Conversation

@irontaek

@irontaek irontaek commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Root.generate() recorded the modification time of the input stylesheet without awaiting it. This PR awaits that stat before it compiles, so no promise is left floating, and the input is in buildDependencies when generate() returns.

Since #20700, generate() also compares the input CSS with the input of the last compiler setup. So an edit of the input stylesheet already sets up the compiler again, also when this stat is still pending. The tests of that PR in integrations/vite/other-transforms.test.ts cover that behavior, so this PR adds no test.

Test plan

  • The a plugin that changes the input CSS in memory tests in integrations/vite/other-transforms.test.ts pass.
  • The dev mode tests in integrations/vite/index.test.ts pass.

@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..."

@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.

@irontaek

irontaek commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Friendly ping. On current main, Root.generate() still starts recording the input stylesheet's mtime without awaiting it, so the race is still there. The branch merges cleanly, and the integration test in this PR is the one that reproduces it. Let me know if you'd prefer a different approach to the fix.

@irontaek

Copy link
Copy Markdown
Contributor Author

@RobinMalfait sorry for the second ping. Since you've been working in @tailwindcss/vite recently, could you take a look when you have a moment? The race is still on current main: Root.generate() starts recording the input stylesheet's mtime without awaiting it, so an edit landing during that window can be missed. The branch still merges cleanly. I can rebase or narrow the change if that would help.

@RobinMalfait
RobinMalfait self-requested a review November 23, 2026 11:32
@RobinMalfait RobinMalfait self-assigned this Nov 23, 2026
@RobinMalfait
RobinMalfait force-pushed the fix/vite-await-input-dependency branch from 5e160e9 to 0615b60 Compare November 23, 2026 11:41
@RobinMalfait

Copy link
Copy Markdown
Contributor

I rebased this PR on the latest main and force pushed it.

Sent by an AI assistant on behalf of @RobinMalfait.

@RobinMalfait

Copy link
Copy Markdown
Contributor

I removed integrations/vite/input-dependency-race.test.ts, and kept the await.

Since #20700, @tailwindcss/vite compares the input CSS with the input of the last compiler setup. So an edit of the input stylesheet always sets up the compiler again, also when the stat of the input is still pending. The tests of that PR cover this behavior: a plugin that changes the input CSS in memory. In these tests, the input file never changes on disk, so only this comparison sets up the compiler again.

On the latest main, your test failed without the await only at its check on the timing of the first response. It also waited a fixed 5 s on each run. The await is still a good cleanup: the stat of the input now finishes before generate() returns.

Sent by an AI assistant on behalf of @RobinMalfait.

@RobinMalfait RobinMalfait changed the title Fix Vite input dependency rebuild race Await the stat of the input CSS in @tailwindcss/vite Nov 23, 2026
irontaek and others added 3 commits November 23, 2026 15:26
Since tailwindlabs#20700,
`Root.generate()` compares the input CSS with the input of the last
compiler setup. So an edit of the input stylesheet always sets up the
compiler again, also when the `stat` of the input is still pending. The
tests that this PR added in `integrations/vite/other-transforms.test.ts`
("a plugin that changes the input CSS in memory") cover that behavior.

On `main`, this test failed without the `await` only at its check on the
timing of the first response. Its stale CSS check passed. It also waited
a fixed 5 s on each run, could pass falsely on a slow runner, and found
the `stat` of the input by its stack trace.

Keep the `await`: it removes a floating promise, so `buildDependencies`
is complete when `generate()` returns.
@RobinMalfait
RobinMalfait force-pushed the fix/vite-await-input-dependency branch from c0a4aed to 2bcbcef Compare November 23, 2026 14:27
@RobinMalfait
RobinMalfait enabled auto-merge (squash) November 23, 2026 14:27

@RobinMalfait RobinMalfait left a comment

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.

Thanks for the PR, and for tracking down the missing await!

Sent by an AI assistant on behalf of @RobinMalfait.

@RobinMalfait
RobinMalfait merged commit 9213f16 into tailwindlabs:main Nov 23, 2026
11 checks passed
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.

2 participants