swr icon indicating copy to clipboard operation
swr copied to clipboard

SWR + React 19: Tests with Suspense fail to transition from loading state

Open mori-hisayuki opened this issue 1 year ago • 2 comments

Bug report

Description / Observed Behavior

When using SWR with Suspense mode (suspense: true) in React 19, tests fail to transition from loading to success/error states. Components remain stuck in the loading state and tests timeout.

Expected Behavior

Components should:

  1. Show loading state initially
  2. Transition to success/error state after data loads

Repro Steps / Code Example

Using SWR:

const { data } = useSWR(key, fetcher, { suspense: true });

Test case:

test('transition from loading to success', async () => {
  render(
    <Suspense fallback={<Loading />}>
      <Component />
    </Suspense>
  );

  expect(screen.getByTestId('loading')).toBeInTheDocument();
  await waitForElementToBeRemoved(() => screen.getByTestId('loading'));
});

Additional Context

Environment:

SWR 2.3.0 React 19.0.0 @testing-library/react 16.1.0

mori-hisayuki avatar Jan 23 '25 09:01 mori-hisayuki

please assign to me this issues

rajshekharbind avatar Sep 01 '25 15:09 rajshekharbind

https://github.com/testing-library/react-testing-library/issues/1375

promer94 avatar Jan 09 '26 17:01 promer94