Skip to content

fix: compatibility with react 19 in snapshots #15729

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Filipoliko
Copy link

@Filipoliko Filipoliko commented Jul 8, 2025

Summary

Remove react-is dependency in favor of custom implementation, which is compatible with both React 18 and React 19.

Resolves #15402

Test plan

Copy link

linux-foundation-easycla bot commented Jul 8, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: Filipoliko / name: Filipoliko (26a3968)

Copy link

netlify bot commented Jul 8, 2025

Deploy Preview for jestjs ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 26a3968
🔍 Latest deploy log https://app.netlify.com/projects/jestjs/deploys/686d75ad5c9dad00084d1df4
😎 Deploy Preview https://deploy-preview-15729--jestjs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

pkg-pr-new bot commented Jul 8, 2025

Open in StackBlitz

babel-jest

npm i https://pkg.pr.new/babel-jest@15729

babel-plugin-jest-hoist

npm i https://pkg.pr.new/babel-plugin-jest-hoist@15729

babel-preset-jest

npm i https://pkg.pr.new/babel-preset-jest@15729

create-jest

npm i https://pkg.pr.new/create-jest@15729

@jest/diff-sequences

npm i https://pkg.pr.new/@jest/diff-sequences@15729

expect

npm i https://pkg.pr.new/expect@15729

@jest/expect-utils

npm i https://pkg.pr.new/@jest/expect-utils@15729

jest

npm i https://pkg.pr.new/jest@15729

jest-changed-files

npm i https://pkg.pr.new/jest-changed-files@15729

jest-circus

npm i https://pkg.pr.new/jest-circus@15729

jest-cli

npm i https://pkg.pr.new/jest-cli@15729

jest-config

npm i https://pkg.pr.new/jest-config@15729

@jest/console

npm i https://pkg.pr.new/@jest/console@15729

@jest/core

npm i https://pkg.pr.new/@jest/core@15729

@jest/create-cache-key-function

npm i https://pkg.pr.new/@jest/create-cache-key-function@15729

jest-diff

npm i https://pkg.pr.new/jest-diff@15729

jest-docblock

npm i https://pkg.pr.new/jest-docblock@15729

jest-each

npm i https://pkg.pr.new/jest-each@15729

@jest/environment

npm i https://pkg.pr.new/@jest/environment@15729

jest-environment-jsdom

npm i https://pkg.pr.new/jest-environment-jsdom@15729

@jest/environment-jsdom-abstract

npm i https://pkg.pr.new/@jest/environment-jsdom-abstract@15729

jest-environment-node

npm i https://pkg.pr.new/jest-environment-node@15729

@jest/expect

npm i https://pkg.pr.new/@jest/expect@15729

@jest/fake-timers

npm i https://pkg.pr.new/@jest/fake-timers@15729

@jest/get-type

npm i https://pkg.pr.new/@jest/get-type@15729

@jest/globals

npm i https://pkg.pr.new/@jest/globals@15729

jest-haste-map

npm i https://pkg.pr.new/jest-haste-map@15729

jest-jasmine2

npm i https://pkg.pr.new/jest-jasmine2@15729

jest-leak-detector

npm i https://pkg.pr.new/jest-leak-detector@15729

jest-matcher-utils

npm i https://pkg.pr.new/jest-matcher-utils@15729

jest-message-util

npm i https://pkg.pr.new/jest-message-util@15729

jest-mock

npm i https://pkg.pr.new/jest-mock@15729

@jest/pattern

npm i https://pkg.pr.new/@jest/pattern@15729

jest-phabricator

npm i https://pkg.pr.new/jest-phabricator@15729

jest-regex-util

npm i https://pkg.pr.new/jest-regex-util@15729

@jest/reporters

npm i https://pkg.pr.new/@jest/reporters@15729

jest-resolve

npm i https://pkg.pr.new/jest-resolve@15729

jest-resolve-dependencies

npm i https://pkg.pr.new/jest-resolve-dependencies@15729

jest-runner

npm i https://pkg.pr.new/jest-runner@15729

jest-runtime

npm i https://pkg.pr.new/jest-runtime@15729

@jest/schemas

npm i https://pkg.pr.new/@jest/schemas@15729

jest-snapshot

npm i https://pkg.pr.new/jest-snapshot@15729

@jest/snapshot-utils

npm i https://pkg.pr.new/@jest/snapshot-utils@15729

@jest/source-map

npm i https://pkg.pr.new/@jest/source-map@15729

@jest/test-result

npm i https://pkg.pr.new/@jest/test-result@15729

@jest/test-sequencer

npm i https://pkg.pr.new/@jest/test-sequencer@15729

@jest/transform

npm i https://pkg.pr.new/@jest/transform@15729

@jest/types

npm i https://pkg.pr.new/@jest/types@15729

jest-util

npm i https://pkg.pr.new/jest-util@15729

jest-validate

npm i https://pkg.pr.new/jest-validate@15729

jest-watcher

npm i https://pkg.pr.new/jest-watcher@15729

jest-worker

npm i https://pkg.pr.new/jest-worker@15729

pretty-format

npm i https://pkg.pr.new/pretty-format@15729

commit: 26a3968

@Filipoliko Filipoliko force-pushed the react-19-compatibility branch from d0d571d to 793988e Compare July 8, 2025 19:07
@Filipoliko Filipoliko force-pushed the react-19-compatibility branch from 793988e to 26a3968 Compare July 8, 2025 19:46
@Filipoliko
Copy link
Author

I tried to create react-is fork inside pretty-print library to add compatibility layer between all react versions, but it is not possible due to Symbol.for('react.context') being treated as Context.Provider in React 19, but in React < 19 it is Context.Consumer. See this commit in react repository, which implements the change.

This change would make this PR breaking and it would also have incomplete support for older React versions.

I am leaving this PR open if somebody can give some hint about how to approach this problem, but right now, I am not sure how to accomplish full support for both React 18 and 19 at the same time.

Btw. Amazing testing coverage, the problem got discovered right away.

@cpojer
Copy link
Member

cpojer commented Jul 9, 2025

I'd really prefer us not to take on the responsibility of maintaining this code. It will get out of sync more often than we think, and then we have to figure out the compatibility story each time.

Is there no way we can use react-is 19, and add a bunch of things around it so it correctly identifies pre react 19 elements?

@Filipoliko
Copy link
Author

I don't really see a way to do this without having a custom implementation. Actually, I don't even see a way how to do this with a custom implementation, that will stay compatible with multiple major React versions.

In the beginning, I thought I can simply extend the test function (in ReactElement.ts) by adding some additional check next to ReactIs.isElement(val). But the problem turned out to be within the getType function, where we use for example ReactIs.isFragment (and other ReactIs.is<ReactComponentName> calls). Most of these ReactIs functions are using typeOf function under the hood, which we need to hijack in order to make react-is library return correct types. That is why I turned to copy-pasting the ReactIs implementation and customising it here and there. But that seems to be also a dead-end.

Right now, I would just wait for React v19 to be more widely used and then switch to it with next major release. If some people still use React v18, then they need to add the overrides configuration to their project -> #15402 (comment)

The only thing I am worried about is future React releases. If there is such a strong link between Jest and React versions, then this issue will keep reoccurring.

We could also make react-is library a peer dependency and make projects specify what version do they want (something like "react-is": "*"). But this is not very practical or user-friendly (but maybe better than overrides?).

We could also try to identify what react version is installed and select proper react-is implementation somehow, but I don't see an easy way how to do this.

I have no good solutions here.

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

Successfully merging this pull request may close these issues.

[Bug]: Snapshot tests failing for React 19
2 participants