Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
benchristel committed Jun 13, 2024
1 parent 8348640 commit 97b19a7
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <MafsGraph {...props} state={state} dispatch={dispatch} />;
Expand Down

0 comments on commit 97b19a7

Please sign in to comment.