Skip to content

Commit 5c5c5d5

Browse files
committed
fix($hmr): Target correct link tags when hot reloading.
Update the logic for comparing link tags' URLs so that the correct pathname is matched against. faceyspacey#23
1 parent 9e8fd10 commit 5c5c5d5

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

hotModuleReplacement.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ module.exports = function(publicPath, outputFilename) {
22
if (document) {
33
var origin = document.location.protocol + '//' + document.location.hostname + (document.location.port ? ':' + document.location.port: '');
44
var newHref = origin + publicPath + outputFilename
5-
var styleSheets = document.getElementsByTagName('link');
5+
var links = document.getElementsByTagName('link');
66

77
//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];
8+
for (var i = 0; i < links.length; i++) {
9+
if (links[i].href) {
10+
var oldChunk = new URL(links[i].href);
11+
var newChunk = new URL(newHref);
1212

13-
if (oldChunk === newChunk) {
14-
var oldSheet = styleSheets[i]
13+
if (oldChunk.pathname === newChunk.pathname) {
14+
var oldSheet = links[i]
1515
var url = newHref + '?' + (+new Date)
1616
var head = document.getElementsByTagName('head')[0]
1717
var link = document.createElement('link')
@@ -38,4 +38,3 @@ module.exports = function(publicPath, outputFilename) {
3838
}
3939
}
4040
}
41-

0 commit comments

Comments
 (0)