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

Memoize ThemeContext.Provider value #135

Merged
merged 1 commit into from
Sep 8, 2022

Commits on Sep 8, 2022

  1. Memoize ThemeContext.Provider value

    Every time <Theme /> renders a new object is constructed and passed to ThemeContext.Provider. This guarantees that regardless of what inputs changed the Context will be propagated. This is particularly harmful when React is doing hydration because if an unhydrated Suspense boudnary exists in the sub-tree of the Provider it will fall back to client rendering regardless of whether the context is an actual dependency for that Suspense boundary.
    
    This commit adds memoization so the value only changes if one of it's inputs change
    To make this memoization effective the default argument for `themes` needed to be statically extracted (it constructs a new array on each function invocation otherwise)
    gnoff committed Sep 8, 2022
    Configuration menu
    Copy the full SHA
    88fd415 View commit details
    Browse the repository at this point in the history