1
+ var currentlyProcessing = { } ;
1
2
module . exports = function ( publicPath , outputFilename ) {
2
3
if ( document ) {
3
4
var newHref = publicPath . match ( / h t t p s ? : / g) ? new URL ( outputFilename , publicPath ) : new URL ( publicPath + outputFilename , window . location ) ;
4
5
var links = document . getElementsByTagName ( 'link' ) ;
5
6
6
- //update the stylesheet corresponding to `outputFilename`
7
+ //update the stylesheet corresponding to `outputFilename`
7
8
for ( var i = 0 ; i < links . length ; i ++ ) {
8
9
if ( links [ i ] . href ) {
9
10
var oldChunk = new URL ( links [ i ] . href ) ;
@@ -19,15 +20,24 @@ module.exports = function(publicPath, outputFilename) {
19
20
link . charset = 'utf-8'
20
21
link . type = 'text/css'
21
22
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
+ }
23
30
head . insertBefore ( link , oldSheet . nextSibling )
24
31
25
32
// remove the old sheet only after the old one loads so it's seamless
26
33
// we gotta do it this way since link.onload basically doesn't work
27
34
var img = document . createElement ( 'img' )
28
35
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
+ }
31
41
}
32
42
img . src = url
33
43
break ;
0 commit comments