diff --git a/components/spin/__tests__/delay.test.tsx b/components/spin/__tests__/delay.test.tsx
index eb67695c4f..154ce8c28c 100644
--- a/components/spin/__tests__/delay.test.tsx
+++ b/components/spin/__tests__/delay.test.tsx
@@ -42,4 +42,15 @@ describe('delay spinning', () => {
unmount();
expect(cancel).toHaveBeenCalled();
});
+
+ it('should close immediately', async () => {
+ jest.useFakeTimers();
+ const { container, rerender } = render();
+
+ await waitFakeTimer();
+ expect(container.querySelector('.ant-spin-spinning')).toBeTruthy();
+
+ rerender();
+ expect(container.querySelector('.ant-spin-spinning')).toBeFalsy();
+ });
});
diff --git a/components/spin/index.tsx b/components/spin/index.tsx
index 6ad1fbc4be..8527a9a9b9 100644
--- a/components/spin/index.tsx
+++ b/components/spin/index.tsx
@@ -93,13 +93,17 @@ const Spin: React.FC = (props) => {
);
React.useEffect(() => {
- const updateSpinning = debounce(delay, () => {
- setSpinning(customSpinning);
- });
- updateSpinning();
- return () => {
- updateSpinning?.cancel?.();
- };
+ if (customSpinning) {
+ const showSpinning = debounce(delay, () => {
+ setSpinning(true);
+ });
+ showSpinning();
+ return () => {
+ showSpinning?.cancel?.();
+ };
+ }
+
+ setSpinning(false);
}, [delay, customSpinning]);
const isNestedPattern = React.useMemo(() => typeof children !== 'undefined', [children]);