Skip to content

Commit be89835

Browse files
author
佛肚
committed
replace dom node in the right place
1 parent bc017ee commit be89835

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/hotModuleReplacement.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@ function updateCss(el, url) {
5151

5252
el.visited = true;
5353
const newEl = el.cloneNode();
54+
const oldEl = el.cloneNode();
5455

5556
newEl.isLoaded = false;
5657

5758
newEl.addEventListener('load', function () {
5859
newEl.isLoaded = true;
59-
el.parentNode.removeChild(el);
6060
});
6161

6262
newEl.addEventListener('error', function () {
6363
newEl.isLoaded = true;
64-
el.parentNode.removeChild(el);
64+
el.parentNode.replaceChild(oldEl, el);
6565
});
6666

6767
newEl.href = url + '?' + Date.now();
68-
el.parentNode.appendChild(newEl);
68+
el.parentNode.replaceChild(newEl, el);
6969
}
7070

7171
function getReloadUrl(href, src) {

0 commit comments

Comments
 (0)