Skip to content

Dynamic imports in useEffect cause act() warning in React 18 #1150

@kenny-grubb

Description

@kenny-grubb
  • @testing-library/react version: 13.4.0
  • Testing Framework and version:
    Jest 29
  • DOM Environment: jsdom default version

Relevant code or config:

Codesandbox repro https://codesandbox.io/s/peaceful-violet-2bstp7

Working in React 17 codesandbox
https://codesandbox.io/s/affectionate-torvalds-vov885

What you did:

In a useEffect, dynamically import code, run it, then set state on the component. In React 17, we were able to test the results of the setState without an act warning. After upgrading to React 18, the act warning appears.

What happened:

image

Reproduction:

Codesandbox repro https://codesandbox.io/s/peaceful-violet-2bstp7

Working in React 17 codesandbox
https://codesandbox.io/s/affectionate-torvalds-vov885

Problem description:

Using findBy to wait for the resulting state (in the codesandbox, it's just some text to appear) should not be showing an act warning.

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