Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 3884 text styles not applied correctly #5253

Conversation

primos63
Copy link
Contributor

Closes #3884

📝 Description

Process text and layer styles correctly

⛳️ Current behavior (updates)

If a component already has a property for which a textStyle property would overwrite, the update is skipped.

🚀 New behavior

Each style property is processed in precedence order. For each style the CSS for the style is generated, the CSS is then merged with an accumulator for the final computed CSS. This ensures that properties, including responsive ones, have the correct values.

💣 Is this a breaking change (Yes/No):

📝 Additional Information

@changeset-bot
Copy link

changeset-bot bot commented Dec 16, 2021

🦋 Changeset detected

Latest commit: f0884f1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@chakra-ui/styled-system Patch
@chakra-ui/system Patch
@chakra-ui/props-docs Patch
@chakra-ui/provider Patch
@chakra-ui/react Patch
@chakra-ui/skeleton Patch
@chakra-ui/test-utils Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Dec 16, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/chakra-ui/chakra-ui-storybook/2uWuqes2Vj6JHMTQ44anKn8GZCHN
✅ Preview: https://chakra-ui-storybook-git-fork-primos63-fix-3884-c02bf6-chakra-ui.vercel.app

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit f0884f1:

Sandbox Source
create-react-app-ts Configuration
textStyle problems Issue #3884
textStyle problems Issue #3884

Copy link
Contributor

@TimKolberger TimKolberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @primos63 for this PR ✨

I really like the improvements you did to the code structure and readability.

Kindly see my comments in the code to see the performance impact.
I think we may need a re-architecture of the styled-system that's focused heavily on performance. When we do that, we will include the idea behind your solution.

We are not able to move forward with this PR. Feel free to reach out to me to discuss this more!

Thanks for understanding

Comment on lines +75 to +77
const computedCSS = stylePrecedence.reduce((accStyle: any, style: any) => {
return mergeWith(accStyle, css(style)(theme))
}, {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mergeWith function causes to increase the runtime complexity to increase from O(n) to O(n^2). Sadly this is in the styled-system algorithm hot path, which will be called by every chakra component on every render.

A very simple loop test gave us the following average time in ms for a run with 10000 iterations:

PR solution: 0.045435ms
Current main branch: 0.02831ms

The large chunk of the performance regression is caused by running mergeWith and css function in a loop, compared to the current approach that uses Object.assign and runs the css function once.

@primos63 primos63 deleted the fix-3884-textStyles-not-applied-correctly branch February 1, 2022 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

textStyles defined inside extendTheme aren’t applied correctly
4 participants