Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mori-hisayuki opened this issue Jan 23, 2025 · 0 comments

Comments

@mori-hisayuki
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant