From a1ff5f32e8a1a9e73e9da70abfe85a7a80b282fd Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Tue, 7 Jan 2025 10:08:53 +0100 Subject: [PATCH] Adds support for react 19 (#4623) * Adds support for react 19 * Add to fgiles --- compat/package.json | 4 ++++ compat/react-19.js | 12 ++++++++++++ compat/react-19.mjs | 12 ++++++++++++ package.json | 7 +++++++ 4 files changed, 35 insertions(+) create mode 100644 compat/react-19.js create mode 100644 compat/react-19.mjs diff --git a/compat/package.json b/compat/package.json index bb80a0fa7a..352e754634 100644 --- a/compat/package.json +++ b/compat/package.json @@ -34,6 +34,10 @@ "import": "./server.mjs", "require": "./server.js" }, + "./react-19": { + "import": "./react-19.mjs", + "require": "./react-19.js" + }, "./jsx-runtime": { "import": "./jsx-runtime.mjs", "require": "./jsx-runtime.js" diff --git a/compat/react-19.js b/compat/react-19.js new file mode 100644 index 0000000000..f640085413 --- /dev/null +++ b/compat/react-19.js @@ -0,0 +1,12 @@ +require('preact/compat'); + +const { options } = require('preact'); + +const oldVNode = options.vnode; +options.vnode = vnode => { + if (typeof vnode.type === 'function') { + vnode.type._forwarded = true; + } + + if (oldVNode) oldVNode(vnode); +}; diff --git a/compat/react-19.mjs b/compat/react-19.mjs new file mode 100644 index 0000000000..f88e011e35 --- /dev/null +++ b/compat/react-19.mjs @@ -0,0 +1,12 @@ +import 'preact/compat'; + +import { options } from 'preact'; + +const oldVNode = options.vnode; +options.vnode = vnode => { + if (typeof vnode.type === 'function') { + vnode.type._forwarded = true; + } + + if (oldVNode) oldVNode(vnode); +}; diff --git a/package.json b/package.json index f92ca82cdd..3ea0361556 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,11 @@ "import": "./compat/jsx-runtime.mjs", "require": "./compat/jsx-runtime.js" }, + "./compat/react-19": { + "types": "./compat/src/index.d.ts", + "import": "./compat/react-19.mjs", + "require": "./compat/react-19.js" + }, "./compat/jsx-dev-runtime": { "types": "./jsx-runtime/src/index.d.ts", "import": "./compat/jsx-dev-runtime.mjs", @@ -166,6 +171,8 @@ "compat/test-utils.js", "compat/jsx-runtime.js", "compat/jsx-runtime.mjs", + "compat/react-19.js", + "compat/react-19.mjs", "compat/jsx-dev-runtime.js", "compat/jsx-dev-runtime.mjs", "compat/package.json",