Skip to content

@vitest/pretty-format is not compatible with React 19 snapshots #6908

@hi-ogawa

Description

@hi-ogawa

Describe the bug

Since v2.0.2 and this PR #6077, Vitest uses @vitest/pretty-format which bundles react-is from React 18, but this doesn't support formatting React 19's element.

Previously it was possible to overrides react-is to pin React 19 version like other React deps react, react-dom, and react-server-dom-webpack and it's common to do so.

Not sure what would be the solution. We can try bundling react-is both from 18 and 19 and switch during runtime?

Reproduction

I found the issue on my repo hi-ogawa/vite-plugins#660, which is using pnpm override like this https://github.com/hi-ogawa/vite-plugins/blob/ca3f97ec09c2549d98779acbf9a24e97706c125d/package.json#L43-L46

Stackblitz repro

On latest Vitest https://stackblitz.com/edit/vitest-dev-vitest-a6zqtz?file=test%2Frepro.test.tsx

// repro.test.tsx
import { expect, test } from 'vitest';

test('repro', () => {
  expect(<div>hello</div>).toMatchInlineSnapshot(`
    {
      "$$typeof": Symbol(react.transitional.element),
      "_owner": null,
      "_store": {},
      "key": null,
      "props": {
        "children": "hello",
      },
      "type": "div",
    }
  `);
});

On Vitest v2.0.1 https://stackblitz.com/edit/vitest-dev-vitest-rrglpy?file=test%2Frepro.test.tsx

test('repro', () => {
  expect(<div>hello</div>).toMatchInlineSnapshot(`
    <div>
      hello
    </div>
  `);
});

System Info

(stackblitz)

  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vitest: 2.1.5 => 2.1.5

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions