Skip to content

Commit 36d0462

Browse files
authored
Merge pull request #24 from phyllisstein/master
fix($hmr): Target correct link tags when hot reloading.
2 parents eb3b7cf + 2509c13 commit 36d0462

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

hotModuleReplacement.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
module.exports = function(publicPath, outputFilename) {
22
if (document) {
3-
var origin = document.location.protocol + '//' + document.location.hostname + (document.location.port ? ':' + document.location.port: '');
4-
var newHref = origin + publicPath + outputFilename
5-
var styleSheets = document.getElementsByTagName('link');
3+
var newHref = publicPath.match(/https?:/g) ? new URL(outputFilename, publicPath) : new URL(publicPath + outputFilename, window.location);
4+
var links = document.getElementsByTagName('link');
65

76
//update the stylesheet corresponding to `outputFilename`
8-
for (var i = 0; i < styleSheets.length; i++) {
9-
if (styleSheets[i].href) {
10-
var oldChunk = styleSheets[i].href.split('.')[0];
11-
var newChunk = newHref.split('.')[0];
7+
for (var i = 0; i < links.length; i++) {
8+
if (links[i].href) {
9+
var oldChunk = new URL(links[i].href);
1210

13-
if (oldChunk === newChunk) {
14-
var oldSheet = styleSheets[i]
15-
var url = newHref + '?' + (+new Date)
11+
if (oldChunk.pathname === newHref.pathname) {
12+
var oldSheet = links[i]
13+
var url = newHref.href + '?' + (+new Date)
1614
var head = document.getElementsByTagName('head')[0]
1715
var link = document.createElement('link')
1816

@@ -38,4 +36,3 @@ module.exports = function(publicPath, outputFilename) {
3836
}
3937
}
4038
}
41-

0 commit comments

Comments
 (0)