Skip to content

Commit 1d583e1

Browse files
committed
Skip soft reload if not needed.
1 parent 93bca61 commit 1d583e1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/content/syncFetchPolicy.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// Mozilla has already parsed the <head> element, we must take extra steps...
2020

2121
let softReloading = true;
22+
let suppressedScripts = 0;
2223
debug("Early parsing: preemptively suppressing events and script execution.");
2324

2425
try {
@@ -57,7 +58,7 @@
5758
}
5859

5960
let {readyState} = document;
60-
debug("Readystate: %s, canScript: ", readyState, ns.canScript);
61+
debug("Readystate: %s, %suppressedScripts %s, canScript = %s", readyState, suppressedScripts, ns.canScript);
6162
if (!ns.canScript) {
6263
for (let node of document.querySelectorAll("*")) {
6364
let evAttrs = [...node.attributes].filter(a => a.name.toLowerCase().startsWith("on"));
@@ -71,6 +72,13 @@
7172
return;
7273
}
7374

75+
if (suppressedScripts === 0 && readyState === "loading") {
76+
// we don't care reloading, if no script has been suppressed
77+
// and no readyState change has been fired yet
78+
softReloading = false;
79+
return;
80+
}
81+
7482
let softReload = ev => {
7583
let html = document.documentElement.outerHTML;
7684
try {
@@ -143,7 +151,8 @@
143151
debug(e.type, e.target, softReloading); // DEV_ONLY
144152
if (softReloading) {
145153
e.preventDefault();
146-
debug("Blocked early script", e.target);
154+
++suppressedScripts;
155+
debug(`Suppressed early script #${suppressedScripts}`, e.target);
147156
} else {
148157
removeEventListener(e.type, scriptSuppressor);
149158
}

0 commit comments

Comments
 (0)