Skip to content

Commit 3e76ed0

Browse files
chore: add warning encouraging react users to update mount function (#23182)
Co-authored-by: Zachary Williams <[email protected]>
1 parent f272c63 commit 3e76ed0

File tree

6 files changed

+219
-24
lines changed

6 files changed

+219
-24
lines changed

npm/react/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@cypress/mount-utils": "0.0.0-development",
1919
"@rollup/plugin-commonjs": "^17.1.0",
2020
"@rollup/plugin-node-resolve": "^11.1.1",
21+
"@types/semver": "7.3.9",
2122
"@vitejs/plugin-react": "1.3.1",
2223
"axios": "0.21.2",
2324
"cypress": "0.0.0-development",
@@ -28,6 +29,7 @@
2829
"react-router-dom": "6.0.0-alpha.1",
2930
"rollup": "^2.38.5",
3031
"rollup-plugin-typescript2": "^0.29.0",
32+
"semver": "^7.3.2",
3133
"typescript": "^4.2.3",
3234
"vite": "3.0.3",
3335
"vite-plugin-require-transform": "1.0.3"

npm/react/src/mount.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getContainerEl } from '@cypress/mount-utils'
22
import React from 'react'
33
import ReactDOM from 'react-dom'
4+
import major from 'semver/functions/major'
45
import {
56
makeMountFn,
67
makeUnmountFn,
@@ -25,6 +26,13 @@ const cleanup = () => {
2526
}
2627

2728
export function mount (jsx: React.ReactNode, options: MountOptions = {}, rerenderKey?: string) {
29+
if (major(React.version) === 18) {
30+
const message = '[cypress/react]: You are using `cypress/react`, which is designed for React <= 17. Consider changing to `cypress/react18`, which is designed for React 18.'
31+
32+
console.error(message)
33+
Cypress.log({ name: 'warning', message })
34+
}
35+
2836
const internalOptions: InternalMountOptions = {
2937
reactDom: ReactDOM,
3038
render: (reactComponent: ReturnType<typeof React.createElement>, el: HTMLElement, reactDomToUse: typeof ReactDOM) => {

0 commit comments

Comments
 (0)