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) {
637637        'rgb(255, 0, 0)' , 
638638      ) 
639639    } ) 
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+     } ) 
640658  } ) 
641659
642660  test ( 'temporary references @js' ,  async  ( {  page } )  =>  { 
Original file line number Diff line number Diff line change @@ -142,6 +142,9 @@ export function useFixture(options: {
142142      reset ( ) : void   { 
143143        fs . writeFileSync ( filepath ,  originalFiles [ filepath ] ! ) 
144144      } , 
145+       resave ( ) : void   { 
146+         fs . writeFileSync ( filepath ,  current ) 
147+       } , 
145148    } 
146149  } 
147150
Original file line number Diff line number Diff line change @@ -70,7 +70,8 @@ async function main() {
7070
7171  // implement server HMR by trigering re-fetch/render of RSC upon server code change 
7272  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 ) 
7475      fetchRscPayload ( ) 
7576    } ) 
7677  } 
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' ;
22
33button  {
44  @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 @@ -436,6 +436,18 @@ export default function vitePluginRsc(
436436
437437        if  ( ! isInsideClientBoundary ( ctx . modules ) )  { 
438438          if  ( this . environment . name  ===  'rsc' )  { 
439+             // detect if this module is only created as css deps (e.g. tailwind) 
440+             // (NOTE: this is not necessary since Vite 7.1.0-beta.0 https://github.com/vitejs/vite/pull/20391 ) 
441+             if  ( ctx . modules . length  ===  1 )  { 
442+               const  importers  =  [ ...ctx . modules [ 0 ] ! . importers ] 
443+               if  ( 
444+                 importers . length  >  0  && 
445+                 importers . every ( ( m )  =>  m . id  &&  isCSSRequest ( m . id ) ) 
446+               )  { 
447+                 return  [ ] 
448+               } 
449+             } 
450+ 
439451            // transform js to surface syntax errors 
440452            for  ( const  mod  of  ctx . modules )  { 
441453              if  ( mod . type  ===  'js' )  { 
@@ -464,6 +476,7 @@ export default function vitePluginRsc(
464476            // Server files can be included in client module graph, for example, 
465477            // when `addWatchFile` is used to track js files as style dependency (e.g. tailwind) 
466478            // In this case, reload all importers (for css hmr), and return empty modules to avoid full-reload. 
479+             // (NOTE: this is not necessary since Vite 7.1.0-beta.0 https://github.com/vitejs/vite/pull/20391 ) 
467480            const  env  =  ctx . server . environments . rsc ! 
468481            const  mod  =  env . moduleGraph . getModuleById ( ctx . file ) 
469482            if  ( mod )  { 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments