Skip to content

Commit 500372e

Browse files
Enable Vite's waitForRequestsIdle() for client requests only (#13394)
* Enable `waitForRequestsIdle` but only when not doing SSR * Cleanup comment * Update changelog
1 parent 855cd94 commit 500372e

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Enable Vite's `waitForRequestsIdle()` for client requests only ([#13394](https://github.com/tailwindlabs/tailwindcss/pull/13394))
1113

1214
## [4.0.0-alpha.11] - 2024-03-27
1315

packages/@tailwindcss-vite/src/index.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,18 @@ export default function tailwindcss(): Plugin[] {
159159
name: '@tailwindcss/vite:generate:serve',
160160
apply: 'serve',
161161

162-
async transform(src, id) {
162+
async transform(src, id, options) {
163163
if (!isTailwindCssFile(id, src)) return
164164

165165
// In serve mode, we treat cssModules as a set, ignoring the value.
166166
cssModules[id] = ''
167167

168-
// TODO: Re-enable waitForRequestsIdle once issues with it hanging are
169-
// fixed. Until then, this transformation may run multiple times in
170-
// serve mode, possibly giving a FOUC.
171-
//
172-
// Wait until all other files have been processed, so we can extract all
173-
// candidates before generating CSS.
174-
// await server?.waitForRequestsIdle?.(id)
168+
if (!options?.ssr) {
169+
// Wait until all other files have been processed, so we can extract
170+
// all candidates before generating CSS. This must not be called
171+
// during SSR or it will block the server.
172+
await server?.waitForRequestsIdle?.(id)
173+
}
175174

176175
let code = await transformWithPlugins(this, id, generateCss(src))
177176
return { code }

0 commit comments

Comments
 (0)