File tree 1 file changed +6
-1
lines changed
1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,7 @@ function cleanUrl(pathname: string): string {
126
126
}
127
127
128
128
let isFirstUpdate = true
129
+ const outdatedLinkTags = new WeakSet < HTMLLinkElement > ( )
129
130
130
131
async function handleMessage ( payload : HMRPayload ) {
131
132
switch ( payload . type ) {
@@ -166,7 +167,10 @@ async function handleMessage(payload: HMRPayload) {
166
167
// URL for the include check.
167
168
const el = Array . from (
168
169
document . querySelectorAll < HTMLLinkElement > ( 'link' )
169
- ) . find ( ( e ) => cleanUrl ( e . href ) . includes ( searchUrl ) )
170
+ ) . find (
171
+ ( e ) =>
172
+ ! outdatedLinkTags . has ( e ) && cleanUrl ( e . href ) . includes ( searchUrl )
173
+ )
170
174
if ( el ) {
171
175
const newPath = `${ base } ${ searchUrl . slice ( 1 ) } ${
172
176
searchUrl . includes ( '?' ) ? '&' : '?'
@@ -182,6 +186,7 @@ async function handleMessage(payload: HMRPayload) {
182
186
const removeOldEl = ( ) => el . remove ( )
183
187
newLinkTag . addEventListener ( 'load' , removeOldEl )
184
188
newLinkTag . addEventListener ( 'error' , removeOldEl )
189
+ outdatedLinkTags . add ( el )
185
190
el . after ( newLinkTag )
186
191
}
187
192
console . log ( `[vite] css hot updated: ${ searchUrl } ` )
You can’t perform that action at this time.
0 commit comments