1+ var currentlyProcessing = { } ;
12module . exports = function ( publicPath , outputFilename ) {
23 if ( document ) {
34 var newHref = publicPath . match ( / h t t p s ? : / g) ? new URL ( outputFilename , publicPath ) : new URL ( publicPath + outputFilename , window . location ) ;
45 var links = document . getElementsByTagName ( 'link' ) ;
56
6- //update the stylesheet corresponding to `outputFilename`
7+ //update the stylesheet corresponding to `outputFilename`
78 for ( var i = 0 ; i < links . length ; i ++ ) {
89 if ( links [ i ] . href ) {
910 var oldChunk = new URL ( links [ i ] . href ) ;
@@ -19,15 +20,24 @@ module.exports = function(publicPath, outputFilename) {
1920 link . charset = 'utf-8'
2021 link . type = 'text/css'
2122 link . rel = 'stylesheet'
22-
23+
24+ // TODO: Look into using __webpack_hash__
25+ if ( ! currentlyProcessing [ oldChunk . pathname ] ) {
26+ currentlyProcessing [ oldChunk . pathname ] = [ oldSheet ] ;
27+ } else {
28+ currentlyProcessing [ oldChunk . pathname ] . push ( link ) ;
29+ }
2330 head . insertBefore ( link , oldSheet . nextSibling )
2431
2532 // remove the old sheet only after the old one loads so it's seamless
2633 // we gotta do it this way since link.onload basically doesn't work
2734 var img = document . createElement ( 'img' )
2835 img . onerror = function ( ) {
29- oldSheet . remove ( )
30- console . log ( '[HMR]' , 'Reload css: ' , url ) ;
36+ if ( currentlyProcessing [ oldChunk . pathname ] ) {
37+ currentlyProcessing [ oldChunk . pathname ] . forEach ( old => old . remove ( ) ) ;
38+ currentlyProcessing [ oldChunk . pathname ] = null ;
39+ console . log ( '[HMR]' , 'Reload css: ' , url ) ;
40+ }
3141 }
3242 img . src = url
3343 break ;
0 commit comments