Skip to content

Commit 3f1a9b8

Browse files
authored
ensure styletags aren't injected more than once on SPAs (#1952)
1 parent df3f2d8 commit 3f1a9b8

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

injected/src/features/element-hiding.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ let hiddenElements = new WeakMap();
77
let modifiedElements = new WeakMap();
88
let appliedRules = new Set();
99
let shouldInjectStyleTag = false;
10+
let styleTagInjected = false;
1011
let mediaAndFormSelectors = 'video,canvas,embed,object,audio,map,form,input,textarea,select,option,button';
1112
let hideTimeouts = [0, 100, 300, 500, 1000, 2000, 3000];
1213
let unhideTimeouts = [1250, 2250, 3000];
@@ -242,6 +243,10 @@ function extractTimeoutRules(rules) {
242243
* @param {string} rules[].type
243244
*/
244245
function injectStyleTag(rules) {
246+
// if style tag already injected on SPA url change, don't inject again
247+
if (styleTagInjected) {
248+
return;
249+
}
245250
// wrap selector list in :is(...) to make it a forgiving selector list. this enables
246251
// us to use selectors not supported in all browsers, eg :has in Firefox
247252
let selector = '';
@@ -257,6 +262,7 @@ function injectStyleTag(rules) {
257262
const styleTagContents = `${forgivingSelector(selector)} {${styleTagProperties}}`;
258263

259264
injectGlobalStyles(styleTagContents);
265+
styleTagInjected = true;
260266
}
261267

262268
/**

0 commit comments

Comments
 (0)