Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix($hmr): Target correct link tags when hot reloading. #24

Merged
merged 3 commits into from
Jul 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
}
}
}