Skip to content

Commit

Permalink
perf: fallback to module level registry in browser (#768)
Browse files Browse the repository at this point in the history
* perf: fallback to module level registry in browser

* preeval registry at top level

* use typeof for conditions
  • Loading branch information
huozhi committed Dec 22, 2021
1 parent 2190f82 commit 3366cfd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions 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) {
Expand Down

0 comments on commit 3366cfd

Please sign in to comment.