A local-first personal finance app
Memoizing useRechartsAnimation() (#8150)
Kennedy242abb1e4fbd740
diff --git a/packages/desktop-client/src/components/reports/chart-theme.ts b/packages/desktop-client/src/components/reports/chart-theme.tsindex 23c35f4e26..a8e59d2879 100644--- a/packages/desktop-client/src/components/reports/chart-theme.ts+++ b/packages/desktop-client/src/components/reports/chart-theme.ts@@ -1,3 +1,5 @@+import { useMemo } from 'react';+import { useReducedMotion } from '#hooks/useReducedMotion';export function getColorScale(name: string): string[] {@@ -23,15 +25,17 @@ export function useRechartsAnimation(defaults?: {}) {const reducedMotion = useReducedMotion();- if (reducedMotion) {- return {- isAnimationActive: false,- animationDuration: 0,- };- }+ const isAnimationActive = reducedMotion+ ? false+ : (defaults?.isAnimationActive ?? true);+ const animationDuration = reducedMotion ? 0 : defaults?.animationDuration;- return {- isAnimationActive: defaults?.isAnimationActive ?? true,- animationDuration: defaults?.animationDuration,- };+ // The returned object must be referentially stable: recharts re-runs chart+ // animations (hiding labels while animating) whenever element identity+ // changes, and this file is outside the React Compiler's *.tsx include, so+ // it isn't auto-memoized.+ return useMemo(+ () => ({ isAnimationActive, animationDuration }),+ [isAnimationActive, animationDuration],+ );}diff --git a/upcoming-release-notes/8150.md b/upcoming-release-notes/8150.mdnew file mode 100644index 0000000000..d485d2065c--- /dev/null+++ b/upcoming-release-notes/8150.md@@ -0,0 +1,6 @@+---+category: Enhancements+authors: [Kennedy242, MatissJanis]+---++Fix Cash Flow Report card text flashing by memoizing recharts animations