@@ -42,7 +42,6 @@ import {
4242import { buildPropsFromAttrs } from './buildPropsFromAttrs'
4343import { substitute , runtime , mixin } from './parsers'
4444import { createTheme } from './theme'
45- import { splitAttrs } from './splitAttrs'
4645import { buildDynamicStyles } from './buildDynamicStyles'
4746import { isFunction , isStyledComponent } from './utils'
4847
@@ -66,47 +65,37 @@ export function createStyled<Theme extends AnyTheme>() {
6665 attrs = isStyledComponent ( Component ) ? [ ...Component . attrs , ...attrs ] : attrs
6766 const hasDynamicStyles = Object . keys ( initialStyles ) . some ( ( key ) => isFunction ( initialStyles [ key ] ) )
6867 const fixedStyle = hasDynamicStyles ? undefined : initialStyles
69- const { fixedProps, dynamicAttrs } = splitAttrs ( attrs )
7068 const origin = isStyledComponent ( Component ) ? Component . origin : Component
71- const isDynamic = dynamicAttrs . length > 0 || hasDynamicStyles
7269
7370 // Component
7471 type ThemedProps = Themed < UnknownProps , Theme >
7572 const StyledComponent = React . forwardRef ( ( props : PropsWithChildren < ThemedProps & AnyStyleProps & AsComponentProps > , ref ) => {
7673 const theme = useContext ( ThemeContext )
7774 const CastedComponent = ( props . as ?? origin ) as AnyComponent
78- const styleFromProps = props . style
79- const hasCustomStyle = fixedStyle !== styleFromProps
80- // We add fixed props and styles to defaultProps. Thanks to this, we don't need to copy the props object.
81- // We copy the props object in the following cases:
82- // 1. ref is not null, meaning the parent has set a ref for the component.
83- // 2. There are dynamic props that depend on the component's props.
84- // 3. There are dynamic attributes that depend on the component's props.
85- const shouldCopyProps = isDynamic || ref || hasCustomStyle
86- let propsForElement = shouldCopyProps ? Object . assign ( { } , props , { theme, ref } ) : props
75+ let propsForElement : ThemedProps = Object . assign ( { } , props , { theme, ref } )
8776 let style : StyleProp < UnknownStyles > = fixedStyle
8877
89- if ( dynamicAttrs . length > 0 ) {
90- propsForElement = buildPropsFromAttrs ( propsForElement , dynamicAttrs )
78+ if ( attrs . length > 0 ) {
79+ propsForElement = buildPropsFromAttrs ( propsForElement , attrs )
9180 }
9281 if ( hasDynamicStyles ) {
9382 style = buildDynamicStyles ( propsForElement , initialStyles )
9483 }
95- if ( hasCustomStyle ) {
84+
85+ const styleFromProps = props . style
86+ if ( styleFromProps ) {
9687 style = ( [ style ] as Array < StyleProp < UnknownStyles > > ) . concat ( styleFromProps )
9788 }
9889 propsForElement . style = style
99- if ( shouldCopyProps ) {
100- propsForElement . theme = props . theme
101- }
90+ propsForElement . theme = props . theme
91+
10292 return createElement ( CastedComponent , propsForElement )
10393 } ) as StyledComponent
10494
10595 StyledComponent . displayName = 'StyledComponent'
10696 StyledComponent . isStyled = true
10797 StyledComponent . styles = initialStyles
10898 StyledComponent . attrs = attrs
109- StyledComponent . defaultProps = Object . assign ( { style : fixedStyle } , fixedProps )
11099 StyledComponent . origin = origin
111100 return StyledComponent
112101 }
0 commit comments