Repository navigation
Conversation
useThemeColors rebuilt its return object and all five nested sections on every call, so any consumer placing a section in a useMemo/useCallback dependency array was invalidated every render. Hoist the light and dark values into two module-level tables and return a single useMemo keyed on the resolved mode and the MUI theme. Section references are now stable while the mode is unchanged, and a light -> dark -> light round trip restores the original references. Color values are unchanged; all 20 leaves per mode were mechanically compared against the previous ternaries. ThemeColors leaf types widen from palette literal unions to string. Tests: four identity-stability cases added (same-mode rerender for light and dark, top-level object identity, and the mode-flip round trip). Each was watched failing on Object.is before the change. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Jared Scott <jared.scott@datarecce.io>
…turn-value-with-usememo-module
…turn-value-with-usememo-module
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR checklist
What type of PR is this?
refactor
What this PR does / why we need it:
useThemeColors()rebuilt its return object and all five nested sections (background,text,border,status,interactive) on every call. Any consumer that placed a section in auseMemo/useCallbackdependency array would have been invalidated on every render.This hoists the light and dark values into two module-level tables and returns a single
useMemokeyed on the resolved mode and the MUI theme. Section references are now stable for as long as the mode is unchanged, and flipping light → dark → light returns the original references.Color values are unchanged. All 20 leaves in each mode were mechanically compared against the previous ternaries.
Which issue(s) this PR fixes:
Closes DRC-3328
Special notes for your reviewer:
ThemeColorsleaves were previously literal unions inferred from theas constpalette (for example"#171717" | "#FFFFFF"). They are nowstring. This is a widening, so assignments intosx,color, or anystringslot are unaffected. Workspace type-check (root, ui, storybook) passes.isDarkis alwaysfalseon first render (themountedguard), so the memo keys on the resolved mode rather than the raw inputs. The tests assert identity only within a mode.vi.hoistedso the top-level memo is observable. Production MUI already memoizes the theme object.Verification:
Does this PR introduce a user-facing change?:
🤖 Generated with Claude Code