This repository was archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
feat(useStyles): avoid creating new instances of mergedStyles if there are no inline overrides #2226
Merged
+14
−5
Merged
feat(useStyles): avoid creating new instances of mergedStyles if there are no inline overrides #2226
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
21cc7b8
-wip
mnajdova d65c978
-changed styles prop
mnajdova 1aa9d40
-fixed factories
mnajdova 19c1caf
-reverted some changes
mnajdova 0bc55ab
-updates
mnajdova bc16bab
Merge branch 'master' into chore/add-cache-on-merge-component-styles
mnajdova 1f0e473
-solved merge conflicts
mnajdova 7dfa6d0
Merge branch 'master' into chore/add-cache-on-merge-component-styles
mnajdova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,11 +69,20 @@ const getStyles = (options: GetStylesOptions): GetStylesResult => { | |
: resolvedComponentVariables[displayName] | ||
|
||
// Resolve styles using resolved variables, merge results, allow props.styles to override | ||
const mergedStyles: ComponentSlotStylesPrepared = mergeComponentStyles( | ||
theme.componentStyles[displayName], | ||
props.design && withDebugId({ root: props.design }, 'props.design'), | ||
props.styles && withDebugId({ root: props.styles } as ComponentSlotStylesInput, 'props.styles'), | ||
) | ||
let mergedStyles: ComponentSlotStylesPrepared = theme.componentStyles[displayName] || { | ||
root: () => ({}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is necessary for the components that don't have any styles in the theme. It is always a new object, but it should be ok as we don't have anything to cache anyway |
||
} | ||
|
||
const hasInlineOverrides = !_.isNil(props.design) || !_.isNil(props.styles) | ||
|
||
if (hasInlineOverrides) { | ||
mergedStyles = mergeComponentStyles( | ||
mergedStyles, | ||
props.design && withDebugId({ root: props.design }, 'props.design'), | ||
props.styles && | ||
withDebugId({ root: props.styles } as ComponentSlotStylesInput, 'props.styles'), | ||
) | ||
} | ||
|
||
const styleParam: ComponentStyleFunctionParam = { | ||
displayName, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the theme is immutable, the mergedStyles by default will always reference to the same object.