From e224922e972e78b4fb6cbd129d685c2317018ad1 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 28 Mar 2023 11:17:38 +0800 Subject: [PATCH] fix(types): revert jsx global removal (to be removed in 3.4) --- CHANGELOG.md | 10 ++++++---- packages/vue/package.json | 4 +--- packages/vue/types/jsx-register.d.ts | 4 ++++ 3 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 packages/vue/types/jsx-register.d.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index b9f06c28826..ca48762b41f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,13 +11,15 @@ * **dx:** improve readability of displayed types for props ([4c9bfd2](https://github.com/vuejs/core/commit/4c9bfd2b999ce472f7481aae4f9dc5bb9f76628e)) * **types/jsx:** support jsxImportSource, avoid global JSX conflict ([#7958](https://github.com/vuejs/core/issues/7958)) ([d0b7ef3](https://github.com/vuejs/core/commit/d0b7ef3b61d5f83e35e5854b3c2c874e23463102)) -### BREAKING CHANGES +### Note on JSX Types Change + +* In the next minor (3.4), Vue no longer registers the global `JSX` namespace by default. This is necessary to avoid global namespace collision with React so that TSX of both libs can co-exist in the same project. This should not affect SFC-only users with latest version of Volar. -* Vue no longer registers the global `JSX` namespace by default. This is necessary to avoid global namespace collision with React so that TSX of both libs can co-exist in the same project. This should not affect SFC-only users with latest version of Volar. + For TSX users, it is suggested to set [jsxImportSource](https://www.typescriptlang.org/tsconfig#jsxImportSource) to `'vue'` in `tsconfig.json` after upgrading to 3.3, or opt-in per file with `/* @jsxImportSource vue */`. This will allow you to opt-in to the new behavior now and upgrade seamlessly when 3.4 releases. - For TSX users, the old global behavior can be enabled by explicitly importing or referencing `vue/jsx`. Alternatively, the user can set [jsxImportSource](https://www.typescriptlang.org/tsconfig#jsxImportSource) to `'vue'` in `tsconfig.json`, or opt-in per file with `/* @jsxImportSource vue */`. + If there is code that depends on the presence of the global `JSX` namespace, you can retain the exact pre-3.4 global behavior by explicitly referencing `vue/jsx`, which registers the global `JSX` namespace. - Note this is a type-only breaking change in a minor release, which adheres to our [release policy](https://vuejs.org/about/releases.html#semantic-versioning-edge-cases). + Note that the planned change in 3.4 is a type-only breaking change in a minor release, which adheres to our [release policy](https://vuejs.org/about/releases.html#semantic-versioning-edge-cases). # [3.3.0-alpha.4](https://github.com/vuejs/core/compare/v3.3.0-alpha.3...v3.3.0-alpha.4) (2023-02-06) diff --git a/packages/vue/package.json b/packages/vue/package.json index 72be3e866f3..900ffe6a157 100644 --- a/packages/vue/package.json +++ b/packages/vue/package.json @@ -48,9 +48,7 @@ "import": "./jsx-runtime/index.mjs", "require": "./jsx-runtime/index.js" }, - "./jsx": { - "types": "./jsx.d.ts" - }, + "./jsx": "./jsx.d.ts", "./dist/*": "./dist/*", "./package.json": "./package.json", "./macros": "./macros.d.ts", diff --git a/packages/vue/types/jsx-register.d.ts b/packages/vue/types/jsx-register.d.ts new file mode 100644 index 00000000000..a626f798c2a --- /dev/null +++ b/packages/vue/types/jsx-register.d.ts @@ -0,0 +1,4 @@ +// this is appended to the end of ../dist/vue.d.ts during build. +// imports the global JSX namespace registration for compat. +// TODO: remove in 3.4 +import '../jsx'