import * as React from 'react' import isDevelopment from '#is-development' import { withEmotionCache } from './context' import { Theme, ThemeContext } from './theming' import { insertStyles } from '@emotion/utils' import { Options as SheetOptions, StyleSheet } from '@emotion/sheet' import isBrowser from '#is-browser' import { useInsertionEffectWithLayoutFallback } from '@emotion/use-insertion-effect-with-fallbacks' import { Interpolation, serializeStyles } from '@emotion/serialize' export interface GlobalProps { styles: Interpolation } let warnedAboutCssPropForGlobal = false // maintain place over rerenders. // initial render from browser, insertBefore context.sheet.tags[0] or if a style hasn't been inserted there yet, appendChild // initial client-side render from SSR, use place of hydrating tag export let Global = /* #__PURE__ */ withEmotionCache( (props, cache) => { if ( isDevelopment && !warnedAboutCssPropForGlobal && // check for className as well since the user is // probably using the custom createElement which // means it will be turned into a className prop // I don't really want to add it to the type since it shouldn't be used (('className' in props && props.className) || ('css' in props && props.css)) ) { console.error( "It looks like you're using the css prop on Global, did you mean to use the styles prop instead?" ) warnedAboutCssPropForGlobal = true } let styles = props.styles let serialized = serializeStyles( [styles], undefined, React.useContext(ThemeContext) ) if (!isBrowser) { let serializedNames = serialized.name let serializedStyles = serialized.styles let next = serialized.next while (next !== undefined) { serializedNames += ' ' + next.name serializedStyles += next.styles next = next.next } let shouldCache = cache.compat === true let rules = cache.insert( ``, { name: serializedNames, styles: serializedStyles }, cache.sheet, shouldCache ) if (shouldCache) { return null } return (