Skip to content

Commit

Permalink
fix($hmr): Target correct link tags when hot reloading.
Browse files Browse the repository at this point in the history
Update the logic for comparing link tags' URLs so that the correct pathname is matched against.

#23
  • Loading branch information
phyllisstein committed Jul 16, 2017
1 parent 9e8fd10 commit 5c5c5d5
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions hotModuleReplacement.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ module.exports = function(publicPath, outputFilename) {
if (document) {
var origin = document.location.protocol + '//' + document.location.hostname + (document.location.port ? ':' + document.location.port: '');
var newHref = origin + publicPath + outputFilename
var styleSheets = document.getElementsByTagName('link');
var links = document.getElementsByTagName('link');

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

if (oldChunk === newChunk) {
var oldSheet = styleSheets[i]
if (oldChunk.pathname === newChunk.pathname) {
var oldSheet = links[i]
var url = newHref + '?' + (+new Date)
var head = document.getElementsByTagName('head')[0]
var link = document.createElement('link')
Expand All @@ -38,4 +38,3 @@ module.exports = function(publicPath, outputFilename) {
}
}
}

0 comments on commit 5c5c5d5

Please sign in to comment.