File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
Expand file tree Collapse file tree 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 {
126126}
127127
128128let isFirstUpdate = true
129+ const outdatedLinkTags = new WeakSet < HTMLLinkElement > ( )
129130
130131async function handleMessage ( payload : HMRPayload ) {
131132 switch ( payload . type ) {
@@ -166,7 +167,10 @@ async function handleMessage(payload: HMRPayload) {
166167 // URL for the include check.
167168 const el = Array . from (
168169 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+ )
170174 if ( el ) {
171175 const newPath = `${ base } ${ searchUrl . slice ( 1 ) } ${
172176 searchUrl . includes ( '?' ) ? '&' : '?'
@@ -182,6 +186,7 @@ async function handleMessage(payload: HMRPayload) {
182186 const removeOldEl = ( ) => el . remove ( )
183187 newLinkTag . addEventListener ( 'load' , removeOldEl )
184188 newLinkTag . addEventListener ( 'error' , removeOldEl )
189+ outdatedLinkTags . add ( el )
185190 el . after ( newLinkTag )
186191 }
187192 console . log ( `[vite] css hot updated: ${ searchUrl } ` )
You can’t perform that action at this time.
0 commit comments