@@ -2,8 +2,8 @@ import path from 'node:path'
2
2
import type { RolldownBuild , RolldownOptions } from 'rolldown'
3
3
import type { Update } from 'types/hmrPayload'
4
4
import colors from 'picocolors'
5
- import type { ChunkMetadata } from 'types/metadata'
6
5
import {
6
+ ChunkMetadataMap ,
7
7
clearLine ,
8
8
enhanceRollupError ,
9
9
resolveRolldownOptions ,
@@ -18,7 +18,7 @@ import { prepareError } from '../middlewares/error'
18
18
const debug = createDebugger ( 'vite:full-bundle-mode' )
19
19
20
20
type HmrOutput = Exclude <
21
- Awaited < ReturnType < RolldownBuild [ 'generateHmrPatch ' ] > > ,
21
+ Awaited < ReturnType < RolldownBuild [ 'hmrInvalidate ' ] > > ,
22
22
undefined
23
23
>
24
24
@@ -106,7 +106,7 @@ export class FullBundleDevEnvironment extends DevEnvironment {
106
106
patched : this . state . patched ,
107
107
}
108
108
109
- let hmrOutput : HmrOutput | undefined
109
+ let hmrOutput : HmrOutput [ ]
110
110
try {
111
111
// NOTE: only single outputOptions is supported here
112
112
hmrOutput = await this . state . bundle . generateHmrPatch ( [ file ] )
@@ -123,12 +123,14 @@ export class FullBundleDevEnvironment extends DevEnvironment {
123
123
return
124
124
}
125
125
126
- if ( ! hmrOutput ) {
126
+ if ( hmrOutput . every ( ( output ) => output . type === 'Noop' ) ) {
127
127
debug ?.( `ignored file change for ${ file } ` )
128
128
return
129
129
}
130
130
131
- this . handleHmrOutput ( file , hmrOutput , this . state )
131
+ for ( const output of hmrOutput ) {
132
+ this . handleHmrOutput ( file , output , this . state )
133
+ }
132
134
return
133
135
}
134
136
this . state satisfies never // exhaustive check
@@ -188,7 +190,7 @@ export class FullBundleDevEnvironment extends DevEnvironment {
188
190
return
189
191
}
190
192
191
- if ( hmrOutput . isSelfAccepting ) {
193
+ if ( hmrOutput . type === 'Patch' ) {
192
194
this . logger . info (
193
195
colors . yellow ( `hmr invalidate ` ) +
194
196
colors . dim ( m . path ) +
@@ -198,7 +200,7 @@ export class FullBundleDevEnvironment extends DevEnvironment {
198
200
}
199
201
200
202
// 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 )
202
204
} ) ( )
203
205
}
204
206
@@ -238,7 +240,7 @@ export class FullBundleDevEnvironment extends DevEnvironment {
238
240
}
239
241
240
242
private async getRolldownOptions ( ) {
241
- const chunkMetadataMap = new Map < string , ChunkMetadata > ( )
243
+ const chunkMetadataMap = new ChunkMetadataMap ( )
242
244
const rolldownOptions = resolveRolldownOptions ( this , chunkMetadataMap )
243
245
rolldownOptions . experimental ??= { }
244
246
rolldownOptions . experimental . hmr = {
@@ -355,19 +357,19 @@ export class FullBundleDevEnvironment extends DevEnvironment {
355
357
file : string ,
356
358
hmrOutput : HmrOutput ,
357
359
{ options, bundle } : BundleStateCommonProperties ,
360
+ firstInvalidatedBy ?: string ,
358
361
) {
359
- if ( hmrOutput . fullReload ) {
362
+ if ( hmrOutput . type === 'Noop' ) return
363
+
364
+ if ( hmrOutput . type === 'FullReload' ) {
360
365
this . triggerGenerateBundle ( { options, bundle } )
361
366
362
- const reason = hmrOutput . fullReloadReason
363
- ? colors . dim ( ` (${ hmrOutput . fullReloadReason } )` )
367
+ const reason = hmrOutput . reason
368
+ ? colors . dim ( ` (${ hmrOutput . reason } )` )
364
369
: ''
365
370
this . logger . info (
366
371
colors . green ( `trigger page reload ` ) + colors . dim ( file ) + reason ,
367
- {
368
- // clear: !hmrOutput.firstInvalidatedBy,
369
- timestamp : true ,
370
- } ,
372
+ { clear : ! firstInvalidatedBy , timestamp : true } ,
371
373
)
372
374
return
373
375
}
@@ -387,7 +389,7 @@ export class FullBundleDevEnvironment extends DevEnvironment {
387
389
url : hmrOutput . filename ,
388
390
path : boundary . boundary ,
389
391
acceptedPath : boundary . acceptedVia ,
390
- firstInvalidatedBy : hmrOutput . firstInvalidatedBy ,
392
+ firstInvalidatedBy,
391
393
timestamp : 0 ,
392
394
}
393
395
} )
@@ -398,7 +400,7 @@ export class FullBundleDevEnvironment extends DevEnvironment {
398
400
this . logger . info (
399
401
colors . green ( `hmr update ` ) +
400
402
colors . dim ( [ ...new Set ( updates . map ( ( u ) => u . path ) ) ] . join ( ', ' ) ) ,
401
- { clear : ! hmrOutput . firstInvalidatedBy , timestamp : true } ,
403
+ { clear : ! firstInvalidatedBy , timestamp : true } ,
402
404
)
403
405
404
406
this . state = {
0 commit comments