You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a component which suspends on render until a certain promise is fulfilled (I'm using the new React 19 use, but I believe this behavior is consistent without React 19, for example using the older suspend-react library).
When I render this component in a test (wrapping it with a Suspense boundary), it never updates. I can see that the promise is resolved via the test log, but the rendered output remains in the suspended state.
If I run a normal Vite app with the same component, I can see that after the appropriate time, the suspense is resolved and the component contents are displayed.
Additional logs from the test are probably relevant:
A component suspended inside an `act` scope, but the `act` call was not awaited. When testing React components that depend on asynchronous data, you must await the result:
await act(() => ...)
I manually patched the vitest-browser-react module to await act on initial render and it appears to have resolved the problem. However, this changes the API, requiring render to be an async function and awaited by the user.
It's reasonable to me, we have an effort for that in RTL: testing-library/react-testing-library#1214 but it's been open for a while now. I believe that the main concern is that since we're not wrapping interactions here with act, what will it mean if a click triggers a transition for example?
Vitest triggers a native click, so it should work the same way it works in production. To catch the changes in DOM, users should call page.getBy* locators that will wait for the presence of the element
Reproduction repo here: https://github.com/a-type/vitest-browser-react-suspense-repro
I have a component which suspends on render until a certain promise is fulfilled (I'm using the new React 19
use
, but I believe this behavior is consistent without React 19, for example using the oldersuspend-react
library).When I render this component in a test (wrapping it with a Suspense boundary), it never updates. I can see that the promise is resolved via the test log, but the rendered output remains in the suspended state.
If I run a normal Vite app with the same component, I can see that after the appropriate time, the suspense is resolved and the component contents are displayed.
Additional logs from the test are probably relevant:
I manually patched the vitest-browser-react module to await
act
on initial render and it appears to have resolved the problem. However, this changes the API, requiringrender
to be an async function and awaited by the user.The text was updated successfully, but these errors were encountered: