Skip to content

Commit

Permalink
Merge pull request #24 from phyllisstein/master
Browse files Browse the repository at this point in the history
fix($hmr): Target correct link tags when hot reloading.
  • Loading branch information
faceyspacey committed Jul 17, 2017
2 parents eb3b7cf + 2509c13 commit 36d0462
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions hotModuleReplacement.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,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 newHref = publicPath.match(/https?:/g) ? new URL(outputFilename, publicPath) : new URL(publicPath + outputFilename, window.location);
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);

if (oldChunk === newChunk) {
var oldSheet = styleSheets[i]
var url = newHref + '?' + (+new Date)
if (oldChunk.pathname === newHref.pathname) {
var oldSheet = links[i]
var url = newHref.href + '?' + (+new Date)
var head = document.getElementsByTagName('head')[0]
var link = document.createElement('link')

Expand All @@ -38,4 +36,3 @@ module.exports = function(publicPath, outputFilename) {
}
}
}

0 comments on commit 36d0462

Please sign in to comment.