@@ -2,8 +2,8 @@ import path from 'node:path'
22import type { RolldownBuild , RolldownOptions } from 'rolldown'
33import type { Update } from 'types/hmrPayload'
44import colors from 'picocolors'
5- import type { ChunkMetadata } from 'types/metadata'
65import {
6+ ChunkMetadataMap ,
77 clearLine ,
88 enhanceRollupError ,
99 resolveRolldownOptions ,
@@ -18,7 +18,7 @@ import { prepareError } from '../middlewares/error'
1818const debug = createDebugger ( 'vite:full-bundle-mode' )
1919
2020type HmrOutput = Exclude <
21- Awaited < ReturnType < RolldownBuild [ 'generateHmrPatch ' ] > > ,
21+ Awaited < ReturnType < RolldownBuild [ 'hmrInvalidate ' ] > > ,
2222 undefined
2323>
2424
@@ -106,7 +106,7 @@ export class FullBundleDevEnvironment extends DevEnvironment {
106106 patched : this . state . patched ,
107107 }
108108
109- let hmrOutput : HmrOutput | undefined
109+ let hmrOutput : HmrOutput [ ]
110110 try {
111111 // NOTE: only single outputOptions is supported here
112112 hmrOutput = await this . state . bundle . generateHmrPatch ( [ file ] )
@@ -123,12 +123,14 @@ export class FullBundleDevEnvironment extends DevEnvironment {
123123 return
124124 }
125125
126- if ( ! hmrOutput ) {
126+ if ( hmrOutput . every ( ( output ) => output . type === 'Noop' ) ) {
127127 debug ?.( `ignored file change for ${ file } ` )
128128 return
129129 }
130130
131- this . handleHmrOutput ( file , hmrOutput , this . state )
131+ for ( const output of hmrOutput ) {
132+ this . handleHmrOutput ( file , output , this . state )
133+ }
132134 return
133135 }
134136 this . state satisfies never // exhaustive check
@@ -188,7 +190,7 @@ export class FullBundleDevEnvironment extends DevEnvironment {
188190 return
189191 }
190192
191- if ( hmrOutput . isSelfAccepting ) {
193+ if ( hmrOutput . type === 'Patch' ) {
192194 this . logger . info (
193195 colors . yellow ( `hmr invalidate ` ) +
194196 colors . dim ( m . path ) +
@@ -198,7 +200,7 @@ export class FullBundleDevEnvironment extends DevEnvironment {
198200 }
199201
200202 // TODO: need to check if this is enough
201- this . handleHmrOutput ( m . path , hmrOutput , this . state )
203+ this . handleHmrOutput ( m . path , hmrOutput , this . state , m . firstInvalidatedBy )
202204 } ) ( )
203205 }
204206
@@ -238,7 +240,7 @@ export class FullBundleDevEnvironment extends DevEnvironment {
238240 }
239241
240242 private async getRolldownOptions ( ) {
241- const chunkMetadataMap = new Map < string , ChunkMetadata > ( )
243+ const chunkMetadataMap = new ChunkMetadataMap ( )
242244 const rolldownOptions = resolveRolldownOptions ( this , chunkMetadataMap )
243245 rolldownOptions . experimental ??= { }
244246 rolldownOptions . experimental . hmr = {
@@ -355,19 +357,19 @@ export class FullBundleDevEnvironment extends DevEnvironment {
355357 file : string ,
356358 hmrOutput : HmrOutput ,
357359 { options, bundle } : BundleStateCommonProperties ,
360+ firstInvalidatedBy ?: string ,
358361 ) {
359- if ( hmrOutput . fullReload ) {
362+ if ( hmrOutput . type === 'Noop' ) return
363+
364+ if ( hmrOutput . type === 'FullReload' ) {
360365 this . triggerGenerateBundle ( { options, bundle } )
361366
362- const reason = hmrOutput . fullReloadReason
363- ? colors . dim ( ` (${ hmrOutput . fullReloadReason } )` )
367+ const reason = hmrOutput . reason
368+ ? colors . dim ( ` (${ hmrOutput . reason } )` )
364369 : ''
365370 this . logger . info (
366371 colors . green ( `trigger page reload ` ) + colors . dim ( file ) + reason ,
367- {
368- // clear: !hmrOutput.firstInvalidatedBy,
369- timestamp : true ,
370- } ,
372+ { clear : ! firstInvalidatedBy , timestamp : true } ,
371373 )
372374 return
373375 }
@@ -387,7 +389,7 @@ export class FullBundleDevEnvironment extends DevEnvironment {
387389 url : hmrOutput . filename ,
388390 path : boundary . boundary ,
389391 acceptedPath : boundary . acceptedVia ,
390- firstInvalidatedBy : hmrOutput . firstInvalidatedBy ,
392+ firstInvalidatedBy,
391393 timestamp : 0 ,
392394 }
393395 } )
@@ -398,7 +400,7 @@ export class FullBundleDevEnvironment extends DevEnvironment {
398400 this . logger . info (
399401 colors . green ( `hmr update ` ) +
400402 colors . dim ( [ ...new Set ( updates . map ( ( u ) => u . path ) ) ] . join ( ', ' ) ) ,
401- { clear : ! hmrOutput . firstInvalidatedBy , timestamp : true } ,
403+ { clear : ! firstInvalidatedBy , timestamp : true } ,
402404 )
403405
404406 this . state = {
0 commit comments