File tree Expand file tree Collapse file tree 6 files changed +38
-2
lines changed Expand file tree Collapse file tree 6 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -637,6 +637,24 @@ function defineTest(f: Fixture) {
637
637
'rgb(255, 0, 0)' ,
638
638
)
639
639
} )
640
+
641
+ test ( 'tailwind no redundant server hmr' , async ( { page } ) => {
642
+ await page . goto ( f . url ( ) )
643
+ await waitForHydration ( page )
644
+ const logs : string [ ] = [ ]
645
+ page . on ( 'console' , ( msg ) => {
646
+ if ( msg . type ( ) === 'log' ) {
647
+ logs . push ( msg . text ( ) )
648
+ }
649
+ } )
650
+ f . createEditor ( 'src/routes/tailwind/unused.tsx' ) . resave ( )
651
+ await page . waitForTimeout ( 200 )
652
+ f . createEditor ( 'src/routes/tailwind/server.tsx' ) . resave ( )
653
+ await page . waitForTimeout ( 200 )
654
+ expect ( logs ) . toEqual ( [
655
+ expect . stringMatching ( / \[ v i t e - r s c : u p d a t e \] .* \/ t a i l w i n d \/ s e r v e r .t s x / ) ,
656
+ ] )
657
+ } )
640
658
} )
641
659
642
660
test ( 'temporary references @js' , async ( { page } ) => {
Original file line number Diff line number Diff line change @@ -142,6 +142,9 @@ export function useFixture(options: {
142
142
reset ( ) : void {
143
143
fs . writeFileSync ( filepath , originalFiles [ filepath ] ! )
144
144
} ,
145
+ resave ( ) : void {
146
+ fs . writeFileSync ( filepath , current )
147
+ } ,
145
148
}
146
149
}
147
150
Original file line number Diff line number Diff line change @@ -70,7 +70,8 @@ async function main() {
70
70
71
71
// implement server HMR by trigering re-fetch/render of RSC upon server code change
72
72
if ( import . meta. hot ) {
73
- import . meta. hot . on ( 'rsc:update' , ( ) => {
73
+ import . meta. hot . on ( 'rsc:update' , ( e ) => {
74
+ console . log ( '[vite-rsc:update]' , e . file )
74
75
fetchRscPayload ( )
75
76
} )
76
77
}
Original file line number Diff line number Diff line change
1
+ console . log ( < div className = "unused" > unused</ div > )
Original file line number Diff line number Diff line change 1
- @import 'tailwindcss' source('. / ') ;
1
+ @import 'tailwindcss' ;
2
2
3
3
button {
4
4
@apply bg-gray-100 mx-1 px-2 border hover:bg-gray-200 active:bg-gray-300;
Original file line number Diff line number Diff line change @@ -398,6 +398,18 @@ export default function vitePluginRsc(
398
398
399
399
if ( ! isInsideClientBoundary ( ctx . modules ) ) {
400
400
if ( this . environment . name === 'rsc' ) {
401
+ // detect if this module is only created as css deps (e.g. tailwind)
402
+ // (NOTE: this is not necessary since Vite 7.1.0-beta.0 https://github.com/vitejs/vite/pull/20391 )
403
+ if ( ctx . modules . length === 1 ) {
404
+ const importers = [ ...ctx . modules [ 0 ] ! . importers ]
405
+ if (
406
+ importers . length > 0 &&
407
+ importers . every ( ( m ) => m . id && isCSSRequest ( m . id ) )
408
+ ) {
409
+ return [ ]
410
+ }
411
+ }
412
+
401
413
// transform js to surface syntax errors
402
414
for ( const mod of ctx . modules ) {
403
415
if ( mod . type === 'js' ) {
@@ -426,6 +438,7 @@ export default function vitePluginRsc(
426
438
// Server files can be included in client module graph, for example,
427
439
// when `addWatchFile` is used to track js files as style dependency (e.g. tailwind)
428
440
// In this case, reload all importers (for css hmr), and return empty modules to avoid full-reload.
441
+ // (NOTE: this is not necessary since Vite 7.1.0-beta.0 https://github.com/vitejs/vite/pull/20391 )
429
442
const env = ctx . server . environments . rsc !
430
443
const mod = env . moduleGraph . getModuleById ( ctx . file )
431
444
if ( mod ) {
You can’t perform that action at this time.
0 commit comments