From c864baf1c64908f47f2701e41726769ef0bbf3a9 Mon Sep 17 00:00:00 2001 From: Kirill Romanov Date: Thu, 4 Jun 2020 15:05:14 +0300 Subject: [PATCH] fix: Lazily define if current browser is old IE --- src/inject-style/browser.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/inject-style/browser.ts b/src/inject-style/browser.ts index f61f903..ed7b6a3 100644 --- a/src/inject-style/browser.ts +++ b/src/inject-style/browser.ts @@ -7,9 +7,7 @@ export interface StyleSource { } -const isOldIE = - typeof navigator !== 'undefined' && - /msie [6-9]\\b/.test(navigator.userAgent.toLowerCase()) +let isOldIE: boolean | undefined export default function createInjector(context: any) { return (id: string, style: StyleSource) => addStyle(id, style) @@ -24,6 +22,12 @@ export interface StyleElementContent { let HEAD: HTMLElement | undefined const styles: { [key: string]: StyleElementContent } = {} function addStyle(id: string, css: StyleSource) { + if (isOldIE === undefined) { + isOldIE = + typeof navigator !== 'undefined' && + /msie [6-9]\\b/.test(navigator.userAgent.toLowerCase()) + } + const group = isOldIE ? css.media || 'default' : id const style = styles[group] || (styles[group] = { ids: new Set(), styles: [] })