From b7832e90974f0b0b762bdf147b65304ad0c7a8ad Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Wed, 22 Dec 2021 13:58:13 +0100 Subject: [PATCH] perf: fallback to module level registry in browser (#768) * perf: fallback to module level registry in browser * preeval registry at top level * use typeof for conditions --- src/style.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/style.js b/src/style.js index db78742f..13eb139f 100644 --- a/src/style.js +++ b/src/style.js @@ -1,12 +1,15 @@ import React from 'react' -import { useStyleRegistry } from './stylesheet-registry' +import { useStyleRegistry, createStyleRegistry } from './stylesheet-registry' import { computeId } from './lib/hash' // Opt-into the new `useInsertionEffect` API in React 18, fallback to `useLayoutEffect`. // https://github.com/reactwg/react-18/discussions/110 const useInsertionEffect = React.useInsertionEffect || React.useLayoutEffect + +const defaultRegistry = + typeof window !== 'undefined' ? createStyleRegistry() : undefined export default function JSXStyle(props) { - const registry = useStyleRegistry() + const registry = defaultRegistry ? defaultRegistry : useStyleRegistry() // If `registry` does not exist, we do nothing here. if (!registry) {