Skip to content

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

@mori-hisayuki

Description

@mori-hisayuki

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions