testing-library / testing-library/react-testing-library
@testing-library/react behaves differently when dealing with Suspense in React 18 and React 19
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 19.7k
- Forks
- 1.2k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 1
Description
@testing-library/reactversion: 16.1.0- Testing Framework and version: jest 29.7.0
- DOM Environment: jsdom 29.7.0
Relevant code or config:
render(
<Suspense fallback="fallback">
<TestComponent />
</Suspense>
);
expect(screen.getByText("fallback")).toBeInTheDocument();
expect(await screen.findByText("resolved")).toBeInTheDocument();
What you did:
We're upgrading our codebase from React 18.3.1 to React 19.0.0.
What happened:
Over 300 tests started to fail because of suspended components kept rendering their fallbacks and never their children.
Reproduction:
In this repo we created a minimal reproduction for the issue we're facing.
It contains a folder react-18 and a folder react-19 that contains the same dependencies, configuration and code, except for the React version.
In both code bases there's the same test. It passes on the React 18 project, but fails in 2 different ways in the React 19 one.
Run npm test in each folder to see the output.
Problem description:
By default, a test that uses Suspense gets stuck rendering the fallback on React 19.
RTL emits a warning to wrap the render method in an awaited act. Following the suggestion leads the component to un-suspend, but make it impossible to assert against its fallback.
Suggested solution:
We don't have a solution for this problem, but we think RTL should behave the same with React 18 and React 19.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproduction, comparing the identical tests and configurations in its react-18 and react-19 folders. Run npm test in each folder and inspect the render, Suspense, fallback, and resolved-content behavior described in the issue. Done means the relevant tests no longer remain stuck on the fallback and behavior is consistent across React 18 and React 19.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100