diff --git a/packages/@lwc/engine-dom/src/styles.ts b/packages/@lwc/engine-dom/src/styles.ts index 991e91c76e..229c14bc2a 100644 --- a/packages/@lwc/engine-dom/src/styles.ts +++ b/packages/@lwc/engine-dom/src/styles.ts @@ -30,15 +30,30 @@ const isIE11 = !isUndefined((document as any).documentMode); // Style sheet cache // -// Global cache of style elements used for fast cloning -let styleElements: Map = new Map(); -// Global cache of CSSStyleSheets because these need to be unique based on content so the browser -// can optimize repeated usages across multiple shadow roots -let stylesheets: Map = new Map(); -// Bookkeeping of targets to CSS that has already been injected into them, so we don't duplicate -let shadowRootsToInsertedStylesheets: WeakMap> = new WeakMap(); -// Same as above, but for the global document to avoid an extra WeakMap lookup for this common case -let globalInsertedStylesheets: Set = new Set(); +interface CacheData { + // Global cache of style elements is used for fast cloning. + // Global cache of CSSStyleSheets is used because these need to be unique based on content, so the browser + // can optimize repeated usages across multiple shadow roots. + stylesheet: CSSStyleSheet | HTMLStyleElement; + // Bookkeeping of shadow roots that have already had this CSS injected into them, so we don't duplicate stylesheets. + // Note this will never be used by IE11 (because it only uses global styles), so WeakSet support is not important. + roots: WeakSet | undefined; + // Same as above, but for the global document to avoid an extra WeakMap lookup for this common case. + global: boolean; + // Keep track of whether the