Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: fallback to module level registry in browser #768

Merged
merged 4 commits into from
Dec 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/style.js
Original file line number Diff line number Diff line change
@@ -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