Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 825179c

Browse files
authored
feat(useStyles): avoid creating new instances of mergedStyles if there are no inline overrides (#2226)
* -wip * -changed styles prop * -fixed factories * -reverted some changes -no caching added if some of the prop of the hash obj is function * -updates * -solved merge conflicts
1 parent 5618a4f commit 825179c

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

packages/react-bindings/src/styles/getStyles.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,20 @@ const getStyles = (options: GetStylesOptions): GetStylesResult => {
6969
: resolvedComponentVariables[displayName]
7070

7171
// Resolve styles using resolved variables, merge results, allow props.styles to override
72-
const mergedStyles: ComponentSlotStylesPrepared = mergeComponentStyles(
73-
theme.componentStyles[displayName],
74-
props.design && withDebugId({ root: props.design }, 'props.design'),
75-
props.styles && withDebugId({ root: props.styles } as ComponentSlotStylesInput, 'props.styles'),
76-
)
72+
let mergedStyles: ComponentSlotStylesPrepared = theme.componentStyles[displayName] || {
73+
root: () => ({}),
74+
}
75+
76+
const hasInlineOverrides = !_.isNil(props.design) || !_.isNil(props.styles)
77+
78+
if (hasInlineOverrides) {
79+
mergedStyles = mergeComponentStyles(
80+
mergedStyles,
81+
props.design && withDebugId({ root: props.design }, 'props.design'),
82+
props.styles &&
83+
withDebugId({ root: props.styles } as ComponentSlotStylesInput, 'props.styles'),
84+
)
85+
}
7786

7887
const styleParam: ComponentStyleFunctionParam = {
7988
displayName,

0 commit comments

Comments
 (0)