refactor(theme): memoize rendering#698
Merged
mikewheeleer merged 2 commits intoJul 25, 2026
Merged
Conversation
Memoize derived theme data and row rendering to avoid re-renders on unrelated state changes. - Wrap formatAmount in useCallback keyed on amountFormat primitive - Wrap updatePreference in useCallback for stable reference - Wrap PreferencesContext value in useMemo to avoid new objects - Extract module-level fallback constants for usePreferences() outside provider - Wrap SettingsPanel in React.memo with useCallback'd onClose - Move SettingsPanel option arrays to module-level constants - Add memoization reference-stability tests - Move localStorage.clear() beforeEach to top-level scope Closes Talenttrust#564
- Integrate safeCurrencyFormat, sanitizePreferences, safeStorage, useMediaQuery, ToastDuration, idleDisconnectMs from upstream - Preserve useCallback/useMemo memoization and module-level fallbacks - Preserve React.memo on SettingsPanel and useCallback on handleClose - Merge all upstream tests (sanitizePreferences, invalid currency, theme application) with memoization reference-stability tests - Fix regex escaping in compact format tests
AnnieIj
force-pushed
the
refactor/theme-01-memoize
branch
from
July 25, 2026 05:47
598014b to
38fe48f
Compare
|
@AnnieIj Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
well done @AnnieIj, this reads well. merging in 🌟 |
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.
Summary
Memoize derived theme data and row rendering to avoid re-renders on unrelated state changes, improving responsiveness on larger data sets.
Changes
src/lib/preferences.tsxformatAmountinuseCallbackkeyed on theamountFormatprimitive, not the entire preferences object — avoids recreating the function when unrelated fields (theme, toastDensity, quietMode) changeupdatePreferenceinuseCallbackwith zero dependencies for a stable referencePreferencesContext.Providervalue inuseMemoso consumers only re-render when the actual dependencies changeFALLBACK_UPDATEandFALLBACK_FORMATconstants sousePreferences()outside a provider returns stable referencessrc/components/settings/SettingsPanel.tsxReact.memoto prevent re-renders from unrelated parent statesrc/components/settings/SettingsTrigger.tsxhandleCloseinuseCallbacksoReact.memoonSettingsPanelis effectivesrc/lib/__tests__/preferences.test.tsxlocalStorage.clear()to top-levelbeforeEachto prevent cross-test state leakageupdatePreference, stableformatAmountwhen non-amountFormat prefs change,formatAmountreference changes whenamountFormatchanges, filter/state changes propagate correctlyTest Results
Behaviour
No behavioural changes — all existing tests pass without modification. The memoization only affects internal reference stability, not output.
Closes #564