From 97b19a78591634af4aa55fa9466f9af2caad4f0e Mon Sep 17 00:00:00 2001 From: Ben Christel Date: Thu, 13 Jun 2024 16:12:17 -0700 Subject: [PATCH] Fix test --- .../src/widgets/interactive-graphs/mafs-graph.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/perseus/src/widgets/interactive-graphs/mafs-graph.tsx b/packages/perseus/src/widgets/interactive-graphs/mafs-graph.tsx index 6792b30d03..6458714a83 100644 --- a/packages/perseus/src/widgets/interactive-graphs/mafs-graph.tsx +++ b/packages/perseus/src/widgets/interactive-graphs/mafs-graph.tsx @@ -152,9 +152,16 @@ export const StatefulMafsGraph = React.forwardRef< }, [dispatch, xMinRange, xMaxRange, yMinRange, yMaxRange]); const numSegments = graph.type === "segment" ? graph.numSegments : null; + const originalPropsRef = useRef(props); const latestPropsRef = useLatestRef(props); useEffect(() => { - dispatch(reinitialize(latestPropsRef.current)); + // This conditional prevents the state from being "reinitialized" right + // after the first render. This is an optimization, but also prevents + // a bug where the graph would be marked "incorrect" during grading + // even if the user never interacted with it. + if (latestPropsRef.current !== originalPropsRef.current) { + dispatch(reinitialize(latestPropsRef.current)); + } }, [graph.type, numSegments, latestPropsRef]); return ;