Skip to content

NextJS 10 breaks tests by throwing warnings for components using next/link #20048

@thanos-diacakis-grandrounds

Description

Bug report

Describe the bug

Minimal code to replicate: https://github.com/thanos-diacakis-grandrounds/nextjs-10-link-test-errors

We have a simple component includes a next/link. We have tests that will render the component, and assert various things (assertions omitted in the sample code). This works fine in NextJS 9.5.6. When upgrading to NextJS 10, these tests start throwing the following two warnings:

  1. Warning: An update to Link inside a test was not wrapped in act(...). [etc.]
  2. Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.

To Reproduce

  1. Check out this repo: https://github.com/thanos-diacakis-grandrounds/nextjs-10-link-test-errors
  2. Run "npm run test"
  3. Observer the warnings

Expected behavior

We expected to see the same behavior as NextJS 9.x - no warnings.

Screenshots

dev_test-zsh_

System information

  • OS: macOS 10.15.7
  • Version of Next.js: 10.0.3
  • Version of Node.js: 14.6.0
  • Deployment: local dev with "npm run test"

Additional context

If there is a single test, it seems to pass with no warnings. Once you add more tests, it seems to fail, even if the additional tests do nothing at all.

Removing the resolves the issue.

Tried turning off prefetching, making the act() function async/await, assuming some kind of state change is happening behind the scenes with no luck.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions