diff --git a/.changeset/twelve-gifts-do.md b/.changeset/twelve-gifts-do.md new file mode 100644 index 000000000..df5e40c78 --- /dev/null +++ b/.changeset/twelve-gifts-do.md @@ -0,0 +1,7 @@ +--- +'@emotion/primitives-core': major +'@emotion/styled': major +'@emotion/react': major +--- + +Refs are no longer internally forwarded using `React.forwardRef`. diff --git a/packages/primitives-core/src/styled.ts b/packages/primitives-core/src/styled.ts index 45ba0fd9a..4f929cd88 100644 --- a/packages/primitives-core/src/styled.ts +++ b/packages/primitives-core/src/styled.ts @@ -50,7 +50,7 @@ export function createStyled( } // do we really want to use the same infra as the web since it only really uses theming? - let Styled = React.forwardRef((props, ref) => { + let Styled: React.FC = props => { const finalTag = (shouldUseAs && (props.as as React.ElementType)) || component @@ -78,12 +78,9 @@ export function createStyled( } } newProps.style = [css.apply(mergedProps, styles), props.style] - if (ref) { - newProps.ref = ref - } return React.createElement(finalTag, newProps) - }) + } Styled.displayName = `emotion(${getDisplayName(component)})` diff --git a/packages/react/src/context.tsx b/packages/react/src/context.tsx index 22df8f655..c526f9d70 100644 --- a/packages/react/src/context.tsx +++ b/packages/react/src/context.tsx @@ -1,5 +1,5 @@ import * as React from 'react' -import { useContext, forwardRef } from 'react' +import { useContext } from 'react' import createCache, { EmotionCache } from '@emotion/cache' import isDevelopment from '#is-development' import isBrowser from '#is-browser' @@ -27,23 +27,14 @@ export let __unsafe_useEmotionCache = function useEmotionCache() { return useContext(EmotionCacheContext) } -let withEmotionCache = function withEmotionCache( - func: ( - props: React.PropsWithoutRef, - context: EmotionCache, - ref?: React.ForwardedRef - ) => React.ReactNode -): - | React.FC & React.RefAttributes> - | React.ForwardRefExoticComponent< - React.PropsWithoutRef & React.RefAttributes - > { - return forwardRef((props, ref) => { +let withEmotionCache = function withEmotionCache( + func: (props: Props, context: EmotionCache) => React.ReactNode +): React.FC { + return props => { // the cache will never be null in the browser let cache = useContext(EmotionCacheContext)! - - return func(props, cache, ref) - }) + return func(props, cache) + } } if (!isBrowser) { diff --git a/packages/react/src/theming.tsx b/packages/react/src/theming.tsx index 6d84bf36b..5db91af36 100644 --- a/packages/react/src/theming.tsx +++ b/packages/react/src/theming.tsx @@ -85,19 +85,16 @@ export function withTheme< C extends React.ComponentType> >( Component: C -): React.ForwardRefExoticComponent< +): React.FC< DistributiveOmit, 'theme'> & { theme?: Theme } -> -export function withTheme( - Component: React.ComponentType -): React.ForwardRefExoticComponent { +> { const componentName = Component.displayName || Component.name || 'Component' - let WithTheme = React.forwardRef(function render(props, ref) { + let WithTheme: React.FC = function render(props) { let theme = React.useContext(ThemeContext) - return - }) + return + } WithTheme.displayName = `WithTheme(${componentName})`