fix: refit figures after layout settles

This commit is contained in:
lda
2026-07-08 17:13:09 +07:00 Verified
parent bacc67c3fb
commit d2ce2b068d
2 changed files with 21 additions and 0 deletions
@@ -210,4 +210,21 @@ describe("InteractiveFigure", () => {
expect(secondFigureId).not.toBe(firstFigureId);
expect(figureNode("providers")).toBeInTheDocument();
});
it("schedules a settled fitView pass for stage figures", () => {
const requestAnimationFrameSpy = vi
.spyOn(window, "requestAnimationFrame")
.mockImplementation((callback: FrameRequestCallback) => {
callback(0);
return 1;
});
const cancelAnimationFrameSpy = vi.spyOn(window, "cancelAnimationFrame").mockImplementation(() => {});
renderFigure({ focusPath: [], size: "stage" });
expect(requestAnimationFrameSpy).toHaveBeenCalled();
requestAnimationFrameSpy.mockRestore();
cancelAnimationFrameSpy.mockRestore();
});
});
@@ -83,6 +83,10 @@ const FitViewOnLayoutChange = ({ layoutKey }: { layoutKey: string }) => {
const { fitView } = useReactFlow();
useEffect(() => {
void fitView({ padding: 0.15, duration: 0 });
const frame = window.requestAnimationFrame(() => {
void fitView({ padding: 0.15, duration: 0 });
});
return () => window.cancelAnimationFrame(frame);
}, [fitView, layoutKey]);
return null;
};