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 @@ -398,6 +398,18 @@ export default function vitePluginRsc(
398398
399399 if ( ! isInsideClientBoundary ( ctx . modules ) ) {
400400 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+
401413 // transform js to surface syntax errors
402414 for ( const mod of ctx . modules ) {
403415 if ( mod . type === 'js' ) {
@@ -426,6 +438,7 @@ export default function vitePluginRsc(
426438 // Server files can be included in client module graph, for example,
427439 // when `addWatchFile` is used to track js files as style dependency (e.g. tailwind)
428440 // 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 )
429442 const env = ctx . server . environments . rsc !
430443 const mod = env . moduleGraph . getModuleById ( ctx . file )
431444 if ( mod ) {
You can’t perform that action at this time.
0 commit comments