From 319b3f5e5902c71e21dd1a1b3c9b7a7d2d8d09c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 15 Dec 2024 12:01:51 +0100 Subject: [PATCH] Use React 19 (#3291) * Use React 19 * Specify TS 5.0 as min TS version in most dtslint tests * try patching dtslint * update lockfile * fixed TS error * dedupe `@types/react` * update react testing library * add `@testing-library/dom` * migrate tests * migrate more * moar * moar * fix * more * more * more * more * more * more * more * more * fix * migrate more tests * moar * moar * moar * moar * moar * more * more * more * tweak * more converted tests * fix thing * fix * tweak * fixed test * tweaks * unskip 2 tests * unskip again * stuff * fix streams * skip some tests * tweak * fix things * fix snap * fixed snapshot indent * fixed extra snapshot issue * strip-ansi * Require TS 5.1 * `useInsertionEffect` directly in `Global` * keep old peer dep range in `use-insertion-effect-with-fallbacks` * add changeset * fixed lockfile --- .changeset/amaranth-owls-dream.md | 6 + .github/workflows/main.yml | 10 - ...ript-versions-npm-0.0.112-f668f50e03.patch | 16 + docs/testing.mdx | 8 +- jest-react18.config.js | 9 - package.json | 19 +- .../component-selector.test.js.snap | 4 +- .../css/test/__snapshots__/css.test.js.snap | 111 ++-- .../css/test/__snapshots__/cx.test.js.snap | 10 +- .../test/__snapshots__/keyframes.test.js.snap | 4 +- .../__snapshots__/label-pattern.test.js.snap | 2 +- .../test/__snapshots__/warnings.test.js.snap | 2 +- packages/css/test/component-selector.test.js | 17 +- packages/css/test/css.test.js | 170 +++--- packages/css/test/cx.test.js | 59 +- .../instance/__snapshots__/css.test.js.snap | 100 ++-- packages/css/test/instance/css.test.js | 157 +++--- packages/css/test/instance/inline.test.js | 15 +- packages/css/test/instance/stream.test.js | 20 +- packages/css/test/keyframes.test.js | 60 +- packages/css/test/label-pattern.test.js | 18 +- .../no-babel/__snapshots__/index.test.js.snap | 36 +- packages/css/test/no-babel/index.test.js | 101 ++-- packages/css/test/warnings.test.js | 8 +- packages/jest/README.md | 50 +- packages/jest/package.json | 5 +- .../test/__snapshots__/matchers.test.js.snap | 8 +- .../test/__snapshots__/printer.test.js.snap | 4 +- packages/jest/test/matchers.test.js | 256 +++++---- packages/jest/test/printer.test.js | 107 ++-- packages/jest/test/prod.test.js | 40 +- packages/jest/types/index.d.ts | 2 +- packages/native/package.json | 2 +- packages/native/test/native-styled.test.js | 129 +++-- packages/native/types/base.d.ts | 2 +- packages/native/types/index.d.ts | 2 +- packages/primitives-core/package.json | 4 +- packages/primitives/package.json | 4 +- .../emotion-primitives.test.js.snap | 64 +-- .../test/emotion-primitives.test.js | 108 ++-- .../no-babel/__snapshots__/basic.test.js.snap | 8 +- .../primitives/test/no-babel/basic.test.js | 21 +- .../__tests__/__snapshots__/at-import.js.snap | 8 +- .../__snapshots__/class-names.js.snap | 6 +- .../__snapshots__/css-cache-hash.js.snap | 2 +- .../react/__tests__/__snapshots__/css.js.snap | 50 +- .../__tests__/__snapshots__/keyframes.js.snap | 18 +- .../__snapshots__/legacy-class-name.js.snap | 4 +- .../__tests__/__snapshots__/prod.js.snap | 10 + .../__snapshots__/theme-provider.js.snap | 4 +- .../__tests__/__snapshots__/use-theme.js.snap | 6 +- .../__tests__/__snapshots__/warnings.js.snap | 78 ++- .../__snapshots__/with-theme.js.snap | 2 +- packages/react/__tests__/at-import.js | 13 +- .../__tests__/babel/__snapshots__/css.js.snap | 4 +- packages/react/__tests__/babel/css.js | 11 +- packages/react/__tests__/class-names.js | 18 +- packages/react/__tests__/css-cache-hash.js | 6 +- packages/react/__tests__/css.js | 85 +-- packages/react/__tests__/custom-cache.js | 10 +- packages/react/__tests__/import-prod.js | 23 +- packages/react/__tests__/keyframes.js | 7 +- packages/react/__tests__/legacy-class-name.js | 42 +- packages/react/__tests__/prod.js | 6 +- packages/react/__tests__/ref.js | 2 +- packages/react/__tests__/rehydration.js | 3 +- packages/react/__tests__/theme-provider.js | 74 ++- packages/react/__tests__/use-theme.js | 28 +- packages/react/__tests__/warnings.js | 333 +++++------ packages/react/__tests__/with-theme.js | 20 +- packages/react/package.json | 4 +- packages/react/src/global.tsx | 9 +- packages/react/src/jsx-namespace.ts | 94 +--- packages/react/types/index.d.ts | 2 +- packages/react/types/tests-theming.tsx | 2 +- packages/react/types/tests.tsx | 24 - packages/server/test/inline.test.js | 18 +- packages/server/test/stream.test.js | 20 +- packages/server/test/util.js | 18 +- packages/server/types/create-instance.d.ts | 2 +- packages/server/types/index.d.ts | 2 +- .../__snapshots__/edge-cases.js.snap | 4 +- .../__tests__/__snapshots__/styled.js.snap | 142 +++-- packages/styled/__tests__/edge-cases.js | 12 +- packages/styled/__tests__/styled-dom.js | 2 +- packages/styled/__tests__/styled.js | 529 ++++++++---------- packages/styled/package.json | 4 +- packages/styled/src/index.ts | 6 +- packages/styled/src/jsx-namespace.ts | 12 - packages/styled/src/types.ts | 22 +- .../__snapshots__/babel-plugin.test.js.snap | 11 + .../component-selector.test.js.snap | 24 +- .../__snapshots__/composition.test.js.snap | 20 +- .../test/__snapshots__/index.test.js.snap | 66 ++- .../__snapshots__/prop-filtering.test.js.snap | 100 ++-- .../__snapshots__/source-map.test.js.snap | 36 +- .../test/__snapshots__/theming.test.js.snap | 8 +- packages/styled/test/babel-plugin.test.js | 7 +- .../styled/test/component-selector.test.js | 58 +- packages/styled/test/composition.test.js | 96 ++-- packages/styled/test/index.test.js | 180 +++--- packages/styled/test/prop-filtering.test.js | 255 +++++---- packages/styled/test/source-map.test.js | 8 +- packages/styled/test/theming.test.js | 41 +- packages/styled/types/base.d.ts | 2 +- packages/styled/types/index.d.ts | 2 +- .../package.json | 2 +- playgrounds/cra/package.json | 4 +- playgrounds/nextjs/package.json | 4 +- scripts/benchmarks/package.json | 4 +- scripts/ssr-benchmarks/package.json | 4 +- scripts/test-utils/src/index.js | 7 +- site/package.json | 6 +- yarn.lock | 342 +++++------ 114 files changed, 2297 insertions(+), 2569 deletions(-) create mode 100644 .changeset/amaranth-owls-dream.md create mode 100644 .yarn/patches/@definitelytyped-typescript-versions-npm-0.0.112-f668f50e03.patch delete mode 100644 jest-react18.config.js create mode 100644 packages/react/__tests__/__snapshots__/prod.js.snap delete mode 100644 packages/styled/src/jsx-namespace.ts create mode 100644 packages/styled/test/__snapshots__/babel-plugin.test.js.snap diff --git a/.changeset/amaranth-owls-dream.md b/.changeset/amaranth-owls-dream.md new file mode 100644 index 0000000000..38b5f13f77 --- /dev/null +++ b/.changeset/amaranth-owls-dream.md @@ -0,0 +1,6 @@ +--- +'@emotion/styled': major +'@emotion/react': major +--- + +Dropped support for older React versions. React 19 becomes the only compatible version with this package. diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f6933c340e..71d76eb687 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -41,16 +41,6 @@ jobs: - name: Check Types run: yarn tsc:all - test_react18: - name: Test React 18 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: ./.github/actions/ci-setup - - - name: Run Tests with React 18 - run: yarn test:react18:ci - test_prod: name: Test Prod runs-on: ubuntu-latest diff --git a/.yarn/patches/@definitelytyped-typescript-versions-npm-0.0.112-f668f50e03.patch b/.yarn/patches/@definitelytyped-typescript-versions-npm-0.0.112-f668f50e03.patch new file mode 100644 index 0000000000..4e828d0aa5 --- /dev/null +++ b/.yarn/patches/@definitelytyped-typescript-versions-npm-0.0.112-f668f50e03.patch @@ -0,0 +1,16 @@ +diff --git a/dist/index.js b/dist/index.js +index 0a9abde5fbe918397794db0c0962129cf6bec3fa..26fe2b048b7fa898282d2d9d0dbd1719384b1f60 100644 +--- a/dist/index.js ++++ b/dist/index.js +@@ -8,9 +8,9 @@ const assert_1 = __importDefault(require("assert")); + var TypeScriptVersion; + (function (TypeScriptVersion) { + /** Add to this list when a version actually ships. */ +- TypeScriptVersion.shipped = ["3.9", "4.0", "4.1", "4.2", "4.3", "4.4", "4.5", "4.6"]; ++ TypeScriptVersion.shipped = ["3.9", "4.0", "4.1", "4.2", "4.3", "4.4", "4.5", "4.6", "4.7", "4.8", "4.9", "5.0", "5.1", "5.2", "5.3", "5.4", "5.5", "5.6", "5.7"]; + /** Add to this list when a version is available as typescript@next */ +- TypeScriptVersion.supported = [...TypeScriptVersion.shipped, "4.7"]; ++ TypeScriptVersion.supported = [...TypeScriptVersion.shipped, "5.8"]; + /** Add to this list when it will no longer be supported on Definitely Typed */ + TypeScriptVersion.unsupported = [ + "2.0", diff --git a/docs/testing.mdx b/docs/testing.mdx index cd4b92ad1a..447265df72 100644 --- a/docs/testing.mdx +++ b/docs/testing.mdx @@ -34,11 +34,11 @@ expect.addSnapshotSerializer(createSerializer()) ### Writing a test -Writing a test with `@emotion/jest` involves creating a snapshot from the `react-test-renderer`'s resulting JSON. +Writing a test with `@emotion/jest` involves creating a snapshot from the `@testing-library/react`'s result. ```jsx import React from 'react' -import renderer from 'react-test-renderer' +import { render } from '@testing-library/react' const Button = props => ( ).toJSON() + render().container ).toMatchSnapshot() }) ``` @@ -67,7 +67,7 @@ exports[`Button renders correctly 1`] = ` }
This is hotpink.
diff --git a/jest-react18.config.js b/jest-react18.config.js deleted file mode 100644 index 119490a9b6..0000000000 --- a/jest-react18.config.js +++ /dev/null @@ -1,9 +0,0 @@ -const baseConfig = require('./jest.config.js') - -module.exports = Object.assign({}, baseConfig, { - moduleNameMapper: { - '^react($|\\/.+)': 'react18$1', - '^react-dom($|\\/.+)': 'react18-dom$1', - '^react-test-renderer($|\\/.+)': 'react18-test-renderer$1' - } -}) diff --git a/package.json b/package.json index fba49a4d31..0dc1dae885 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,8 @@ "test:size": "npm-run-all build size", "test:debug": "node --inspect-brk ./node_modules/jest/bin/jest.js --runInBand --watch", "test": "jest", - "test:react18": "jest -c jest-react18.config.js", "test:typescript": "yarn workspaces foreach --verbose --exclude emotion-monorepo run test:typescript", "test:ci": "jest --coverage --no-cache --ci --runInBand", - "test:react18:ci": "yarn test:react18 --coverage --no-cache --ci --runInBand", "test:dist": "yarn build && jest -c jest.dist.js --no-cache --ci --runInBand", "test:prod": "jest -c jest.prod.js --no-cache --ci --runInBand", "lint:check": "eslint .", @@ -185,10 +183,11 @@ "@changesets/cli": "^2.27.7", "@manypkg/cli": "^0.19.1", "@preconstruct/cli": "^2.8.8", - "@testing-library/react": "13.0.0-alpha.5", + "@testing-library/dom": "^10.4.0", + "@testing-library/react": "^16.1.0", "@types/jest": "^29.5.12", "@types/node": "^12.20.37", - "@types/react": "18.3.12", + "@types/react": "19.0.1", "@typescript-eslint/eslint-plugin": "^7.13.0", "@typescript-eslint/parser": "^7.13.0", "babel-check-duplicated-nodes": "^1.0.0", @@ -226,14 +225,11 @@ "polished": "^1.2.1", "prettier": "^3.3.2", "raf": "^3.4.0", - "react": "16.14.0", - "react-dom": "16.14.0", + "react": "19.0.0", + "react-dom": "19.0.0", "react-native": "^0.63.2", "react-primitives": "^0.8.1", - "react-test-renderer": "16.8.6", - "react18": "npm:react@18.0.0-rc.0-next-aa8f2bdbc-20211215", - "react18-dom": "npm:react-dom@18.0.0-rc.0-next-aa8f2bdbc-20211215", - "react18-test-renderer": "npm:react-test-renderer@18.0.0-rc.0-next-aa8f2bdbc-20211215", + "react-test-renderer": "19.0.0", "svg-tag-names": "^1.1.1", "through": "^2.3.8", "typescript": "^5.4.5", @@ -242,6 +238,7 @@ }, "packageManager": "yarn@3.2.3", "resolutions": { - "@definitelytyped/dtslint@0.0.112": "patch:@definitelytyped/dtslint@npm%3A0.0.112#./.yarn/patches/@definitelytyped-dtslint-npm-0.0.112-1e6b842976.patch" + "@definitelytyped/dtslint@0.0.112": "patch:@definitelytyped/dtslint@npm%3A0.0.112#./.yarn/patches/@definitelytyped-dtslint-npm-0.0.112-1e6b842976.patch", + "@definitelytyped/typescript-versions@^0.0.112": "patch:@definitelytyped/typescript-versions@npm%3A0.0.112#./.yarn/patches/@definitelytyped-typescript-versions-npm-0.0.112-f668f50e03.patch" } } diff --git a/packages/css/test/__snapshots__/component-selector.test.js.snap b/packages/css/test/__snapshots__/component-selector.test.js.snap index 0831e50cb4..f5816e1d25 100644 --- a/packages/css/test/__snapshots__/component-selector.test.js.snap +++ b/packages/css/test/__snapshots__/component-selector.test.js.snap @@ -10,10 +10,10 @@ exports[`component selector should be converted to use the emotion target classN }
`; diff --git a/packages/css/test/__snapshots__/css.test.js.snap b/packages/css/test/__snapshots__/css.test.js.snap index fcf9de1124..c4b2a1a926 100644 --- a/packages/css/test/__snapshots__/css.test.js.snap +++ b/packages/css/test/__snapshots__/css.test.js.snap @@ -8,7 +8,7 @@ exports[`css @supports 1`] = ` }
`; @@ -19,7 +19,7 @@ exports[`css array fallback 1`] = ` }
`; @@ -32,7 +32,7 @@ exports[`css array with explicit false 1`] = ` }
`; @@ -45,7 +45,7 @@ exports[`css array with explicit true 1`] = ` }
`; @@ -63,7 +63,7 @@ exports[`css auto px 1`] = ` }
`; @@ -76,7 +76,7 @@ exports[`css boolean as value 1`] = ` }
`; @@ -89,7 +89,7 @@ exports[`css composition stuff 1`] = ` }
`; @@ -102,7 +102,7 @@ exports[`css composition stuff 2`] = ` }
`; @@ -136,7 +136,7 @@ exports[`css composition with objects 1`] = ` }
`; @@ -147,7 +147,7 @@ exports[`css computed key is only dynamic 1`] = ` }
`; @@ -158,7 +158,7 @@ exports[`css css variables 1`] = ` }
`; @@ -171,7 +171,7 @@ exports[`css explicit & 1`] = ` }
`; @@ -186,7 +186,7 @@ exports[`css explicit & 2`] = ` exports[`css explicit false 1`] = `
`; @@ -199,7 +199,7 @@ exports[`css falsy property value in object 1`] = ` }
`; @@ -209,7 +209,7 @@ exports[`css falsy value in nested selector on object 1`] = ` }
`; @@ -219,7 +219,7 @@ exports[`css float property 1`] = ` }
`; @@ -232,13 +232,13 @@ exports[`css flushes correctly 1`] = ` }
`; exports[`css flushes correctly 2`] = `
`; @@ -249,7 +249,7 @@ exports[`css handles array of objects 1`] = ` }
`; @@ -270,7 +270,7 @@ exports[`css handles more than 10 dynamic properties 1`] = ` }
`; @@ -288,7 +288,7 @@ exports[`css handles objects 1`] = ` }
`; @@ -298,7 +298,7 @@ exports[`css manually use label property 1`] = ` }
`; @@ -338,7 +338,7 @@ exports[`css media query specificity 2`] = ` }
`; @@ -349,7 +349,7 @@ exports[`css multiline declaration 1`] = ` }
`; @@ -359,7 +359,7 @@ exports[`css multiline selector 1`] = ` }
`; @@ -386,13 +386,13 @@ exports[`css nested 1`] = ` }
@@ -417,7 +417,7 @@ exports[`css nested array 1`] = ` }
`; @@ -435,19 +435,52 @@ exports[`css nested at rule 1`] = ` }
+`; + +exports[`css nested at rules 1`] = ` +@supports (display: grid) { + .emotion-0 { + display: grid; + } + + @supports (display: flex) { + .emotion-0 { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + } + } +} + +@media (min-width: 420px) { + .emotion-0 { + color: pink; + } + + @media (max-width: 500px) { + .emotion-0 { + color: hotpink; + } + } +} + +
`; exports[`css null rule 1`] = `
`; exports[`css null value 1`] = `
`; @@ -467,7 +500,7 @@ exports[`css random expression 1`] = ` }
`; @@ -480,7 +513,7 @@ exports[`css random interpolation with undefined values 1`] = ` }
`; @@ -494,7 +527,7 @@ exports[`css registered styles as nested selector value in object 1`] = ` }
`; @@ -510,7 +543,7 @@ exports[`css rule after media query 1`] = ` }
`; @@ -531,7 +564,7 @@ exports[`css simple composition 1`] = ` }
`; @@ -544,7 +577,7 @@ exports[`css weakmap 1`] = ` }
`; @@ -557,6 +590,6 @@ exports[`css weakmap 2`] = ` }
`; diff --git a/packages/css/test/__snapshots__/cx.test.js.snap b/packages/css/test/__snapshots__/cx.test.js.snap index 4c80ffe3ed..5fae78ea10 100644 --- a/packages/css/test/__snapshots__/cx.test.js.snap +++ b/packages/css/test/__snapshots__/cx.test.js.snap @@ -11,7 +11,7 @@ exports[`cx all types 1`] = ` }