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

A lot of React Warnings Warning: An update to ... inside a test was not wrapped in act(...). appeared since 3.0.0-beta.2 (fixed in 3.0.2) #7283

Closed
6 tasks done
ceisele-r opened this issue Jan 17, 2025 · 1 comment

Comments

@ceisele-r
Copy link

Describe the bug

Note: This seems to be already fixed with the just released v3.0.2 and can immediately be closed if you also consider this to be intentionally fixed with v3.0.2.
However I still thought reporting this as a reference might be worth as others might also face this issue after updating to v3 and search for a solution. Besides that, I think it might be worth mentioning that this appeared after the v3 update as I am not sure by the changelog for v3.0.2 what exactly fixed it. I guess #7281 fixed it.

Bug description:
Since updating to vite v3 (tested v3.0.1), a lot of the following react warning appeared in quite some existing tests that would not emit that warning with vitest <= 3.0.0-beta.1.
I traced it down that these warnings started to be emitted with vitest 3.0.0-beta.2.

Again, after updating to v3.0.2, the issue was gone in my existing tests.

Reproduction

This is kind of a reproduction that creates such a warning.
It is based on the reproduction in #7196 and causes an update to the Button react component after 400ms.

https://stackblitz.com/edit/vitest-fake-timers-act-warnings-trw1va8q?file=src%2FButton.test.tsx

Such a promise at the end of a test is not used in my regular tests, however, that was how I could trigger this warning in the repro.
However, I am unsure whether this is really a good repro of the issue as it kind of intentionally makes the react component to update after the test completed. Still, I thought testing-library/react would call cleanup in a global afterEach after each test which should prevent this.

System Info

System:
    OS: Windows 11 10.0.22631
  Binaries:
    Node: 22.13.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (131.0.2903.146)
  npmPackages:
    @vitejs/plugin-react: ^4.3.4 => 4.3.4
    @vitejs/plugin-react-swc: ^3.7.2 => 3.7.2
    @vitest/coverage-v8: ^3.0.2 => 3.0.2
    @vitest/ui: ^3.0.2 => 3.0.2
    vite: ^5.4.11 => 5.4.11
    vitest: ^3.0.1 => 3.0.1

Used Package Manager

npm

Validations

@ceisele-r ceisele-r changed the title A lot of React Warnings Warning: An update to ... inside a test was not wrapped in act(...). appeared since 3.0.0-beta.2 A lot of React Warnings Warning: An update to ... inside a test was not wrapped in act(...). appeared since 3.0.0-beta.2 (fixed in 3.0.2) Jan 17, 2025
@hi-ogawa
Copy link
Contributor

The reproduction you attached still shows a act warning but the rational is as described in #7196 and it's out of scope for Vitest with my current understanding.
Let me close this as your main issue seems fixed.

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

No branches or pull requests

2 participants