-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Optimize ThemeProvider custom properties output #3550
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
Conversation
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.
Love it 🥇
Makes things much less confusing for consumers
|
Tangental: In #3527 I identified that we're recreating the object we store in the ThemeContext on every rerender, and found a smallish fix for it (with a further suggesting that we should replace those multiple useMemo calls with a single useMemo call). Is it worth working at caching this response here or should we deal with that in a separate PR? |
Good call @BPScott. I want to do a bit of perf testing with this change so it would make sense to try to get that fixed in here as well so we can test it all together. |
|
Alrighty, this should be ready for a real review now. Following a similar approach to what @BPScott did in #3527 I was able to get this memoizing properly. One thing I noticed was that the parent context from the I tested in that app with something like this: The 3 theme providers have their values memoized on first render and when clicking the toggle button, only the most nested provider reruns the memoization. The custom properties also only output when the |
|
One other thing I noticed in that example. If you declare |
885a053 to
96785f4
Compare
|
This fixes #3448 |
96785f4 to
6fadd22
Compare
* Optimize ThemeProvider custom properties output * Updating memoization * Feedback based on review * Adding to unreleased * Updating UNRELEASED
This is an alternative approach to #3546.
WHY are these changes introduced?
Currently we output the custom properties on each level of
ThemeProvidereven if they are identical to the parent.WHAT is this pull request doing?
This changes the ThemeProvider to compare the generated custom properties with the parent context and only output them if they differ.
How to 🎩
🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines
I committed a change to the Details Page example to try this out. If you change to the new design language light mode, you should see only one top level output of the custom properties since the AppProvider's ThemeProvider and the ThemeProvider wrapping the Details Page frame match. If you switch to dark mode you should see it output on both and that the page stays in light mode because of the nested ThemeProvider's custom properties.
🎩 checklist
README.mdwith documentation changes