fix: refit figures after layout settles
This commit is contained in:
@@ -210,4 +210,21 @@ describe("InteractiveFigure", () => {
|
|||||||
expect(secondFigureId).not.toBe(firstFigureId);
|
expect(secondFigureId).not.toBe(firstFigureId);
|
||||||
expect(figureNode("providers")).toBeInTheDocument();
|
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();
|
const { fitView } = useReactFlow();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
void fitView({ padding: 0.15, duration: 0 });
|
void fitView({ padding: 0.15, duration: 0 });
|
||||||
|
const frame = window.requestAnimationFrame(() => {
|
||||||
|
void fitView({ padding: 0.15, duration: 0 });
|
||||||
|
});
|
||||||
|
return () => window.cancelAnimationFrame(frame);
|
||||||
}, [fitView, layoutKey]);
|
}, [fitView, layoutKey]);
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user