Prevent @tailwindcss/vite crash under Vite's experimental bundledDev - #20379
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughThe Vite plugin now returns immediately when 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
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. Comment |
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (4): Last reviewed commit: "check all chunks" | Re-trigger Greptile |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f155b7b0-e0e7-4f94-b96b-240d78b5f3c0
📒 Files selected for processing (3)
integrations/vite/bundled-dev.test.tspackages/@tailwindcss-vite/src/index.test.tspackages/@tailwindcss-vite/src/index.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/@tailwindcss-vite/src/index.ts
- packages/@tailwindcss-vite/src/index.test.ts
| await retryAssertion(async () => { | ||
| // Updates are additive and cause new candidates to be added. | ||
| await fs.write( | ||
| 'project-a/index.html', | ||
| html` | ||
| <head> | ||
| <link rel="stylesheet" href="./src/index.css" /> | ||
| </head> | ||
| <body> | ||
| <div class="underline m-2">Hello, world!</div> | ||
| </body> | ||
| `, | ||
| ) | ||
|
|
||
| let styles = await fetchBundledStyles() | ||
| expect(styles).toContain(candidate`underline`) | ||
| expect(styles).toContain(candidate`flex`) | ||
| expect(styles).toContain(candidate`m-2`) | ||
| }) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Write each watched file before the retry loop.
retryAssertion reruns its callback after each failed assertion. Lines 109-119 and 129-134 therefore rewrite watched files on every retry. Each write can trigger another Vite rebuild. The test can keep observing a fallback or stale bundle and fail intermittently.
Move each fs.write call before its related retryAssertion call. The retry callback should only fetch and assert the rebuilt bundle.
Proposed change
- await retryAssertion(async () => {
- // Updates are additive and cause new candidates to be added.
- await fs.write(
+ // Updates are additive and cause new candidates to be added.
+ await fs.write(
'project-a/index.html',
html`
<head>
<link rel="stylesheet" href="./src/index.css" />
</head>
<body>
<div class="underline m-2">Hello, world!</div>
</body>
`,
- )
-
+ )
+ await retryAssertion(async () => {
let styles = await fetchBundledStyles()
expect(styles).toContain(candidate`m-2`)
})The retry behavior is defined in integrations/utils.ts:663-679.
Also applies to: 127-141
RobinMalfait
left a comment
There was a problem hiding this comment.
Thanks!
Made a few small changes to make TypeScript happy.
Also added an integration test to verify that this mode also works, and not just not crashes.
Rebase failed
Summary
Under Vite's experimental
bundledDevmode, thehotUpdatehook in@tailwindcss/vitegets called without aserver. Vite only passes{ type, file, modules }here, but the hook loops overObject.values(server.environments), so editing any file (JS, CSS, or HTML) throwsTypeError: Cannot read properties of undefined (reading 'environments')and the dev server build fails.The fix returns early when
serveris missing. Those environment loops only look at environments other than the current one, and the server-levelhot/wsreload channels don't exist in this mode, so bailing out leaves the classic (non-bundledDev) dev path untouched.Fixes #20378
Test plan
hotUpdatewithout aserverand checks it doesn't throw. It fails on the current code and passes with the guard.experimental.bundledDev: true: before the change, editing any JS/CSS/HTML file crashed the dev server; after it, edits work.pnpm run testand the@tailwindcss/viteintegration suite both pass.[ci-all]