Skip to content
This repository has been archived by the owner on Apr 16, 2019. It is now read-only.

memory leak fix, only reload css files #22

Merged
merged 2 commits into from
Oct 7, 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
14 changes: 10 additions & 4 deletions hotModuleReplacement.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,28 @@ var getCurrentScriptUrl = function(moduleId) {
}

function updateCss(el, url) {
var newEl = el.cloneNode();
if (!url) {
url = el.href.split('?')[0];
}

if (!url || !url.endsWith('.css')) return;

var newEl = el.cloneNode();
newEl.addEventListener('load', function () {
el.remove();
});
newEl.addEventListener('error', function () {
el.remove();
});
newEl.href = url + '?' + Date.now();
el.parentNode.insertBefore(newEl, el.nextSibling);
}

function reloadStyle(src) {
var elements = document.querySelectorAll('link');
var loaded = false;
for (var i = 0, el = null; el = elements[i]; i++) {
var url = getReloadUrl(el.href, src);
for (let i = 0, el = null; el = elements[i]; i++) {
let url = getReloadUrl(el.href, src);
if (url) {
updateCss(el, url);
loaded = true;
Expand All @@ -64,7 +70,7 @@ function getReloadUrl(href, src) {

function reloadAll() {
var elements = document.querySelectorAll('link');
for (var i = 0, el = null; el = elements[i]; i++) {
for (let i = 0, el = null; el = elements[i]; i++) {
updateCss(el);
}
}
Expand Down