Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Memoize ThemeContext.Provider value (pacocoursey#135)
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)
- Loading branch information