diff --git a/components/_util/ActionButton.tsx b/components/_util/ActionButton.tsx index 04e014278c..48c8f5f020 100644 --- a/components/_util/ActionButton.tsx +++ b/components/_util/ActionButton.tsx @@ -98,22 +98,8 @@ const ActionButton: React.FC = (props) => { return; } let returnValueOfOnOk: PromiseLike; - // Currently only Popconfirm passes `emitEvent` as true if (emitEvent) { - // if actionFn has been throw error, just reset clickedRef - try { - returnValueOfOnOk = actionFn(e); - } catch (error) { - clickedRef.current = false; - - // Log error for debugging unless in silent mode - if (!isSilent?.()) { - console.error('Error in actionFn:', error); - } - - return; - } - + returnValueOfOnOk = actionFn(e); if (quitOnNullishReturnValue && !isThenable(returnValueOfOnOk)) { clickedRef.current = false; onInternalClose(e); diff --git a/components/popconfirm/__tests__/index.test.tsx b/components/popconfirm/__tests__/index.test.tsx index 856dc912eb..13e0985d30 100644 --- a/components/popconfirm/__tests__/index.test.tsx +++ b/components/popconfirm/__tests__/index.test.tsx @@ -407,119 +407,4 @@ describe('Popconfirm', () => { expect(popconfirmElement).toHaveStyle({ padding: '20px' }); expect(popconfirmBodyElement).toHaveStyle({ padding: '10px' }); }); - - it('should allow retry after onConfirm throws synchronous error', async () => { - const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); - let callCount = 0; - const onConfirm = jest.fn(() => { - callCount += 1; - if (callCount === 1) { - throw new Error('Test synchronous error'); - } - return Promise.resolve(); - }); - - const { container } = render( - - - , - ); - - const triggerNode = container.querySelector('.trigger')!; - - // Open popconfirm - fireEvent.click(triggerNode); - await waitFakeTimer(); - - const okButton = container.querySelector('.ant-btn-primary')!; - - // First click - should throw error - fireEvent.click(okButton); - await waitFakeTimer(); - - expect(onConfirm).toHaveBeenCalledTimes(1); - expect(consoleErrorSpy).toHaveBeenCalledWith('Error in actionFn:', expect.any(Error)); - - // Popconfirm should still be open after error - expect(container.querySelector('.ant-popover')).toBeTruthy(); - - // Second click - should succeed - fireEvent.click(okButton); - await waitFakeTimer(); - - expect(onConfirm).toHaveBeenCalledTimes(2); - - consoleErrorSpy.mockRestore(); - }); - - it('should not log error when onConfirm throws error in silent mode', async () => { - const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); - const onConfirm = jest.fn(() => { - throw new Error('Test error in silent mode'); - }); - - // Create a wrapper component that simulates silent mode - const TestComponent = () => { - const [open, setOpen] = React.useState(false); - - return ( - - - - ); - }; - - const { container } = render(); - - const triggerNode = container.querySelector('.trigger')!; - - // Open popconfirm - fireEvent.click(triggerNode); - await waitFakeTimer(); - - const okButton = container.querySelector('.ant-btn-primary')!; - - // Click OK button - should throw error but not log in normal case - fireEvent.click(okButton); - await waitFakeTimer(); - - expect(onConfirm).toHaveBeenCalledTimes(1); - // In current implementation, error should be logged - expect(consoleErrorSpy).toHaveBeenCalled(); - - consoleErrorSpy.mockRestore(); - }); - - it('should reset button loading state after synchronous error', async () => { - const onConfirm = jest.fn(() => { - throw new Error('Synchronous error'); - }); - - const { container } = render( - - - , - ); - - const triggerNode = container.querySelector('.trigger')!; - - // Open popconfirm - fireEvent.click(triggerNode); - await waitFakeTimer(); - - const okButton = container.querySelector('.ant-btn-primary')! as HTMLButtonElement; - - // Click OK button - should throw error - fireEvent.click(okButton); - await waitFakeTimer(); - - // Button should not be in loading state after error - expect(okButton.querySelector('.ant-btn-loading-icon')).toBeFalsy(); - - // Should be able to click again - fireEvent.click(okButton); - await waitFakeTimer(); - - expect(onConfirm).toHaveBeenCalledTimes(2); - }); });