From 5eecaf110cf8aa97a2b034ed161c0fe4f982a222 Mon Sep 17 00:00:00 2001 From: Titus Date: Fri, 3 Feb 2023 10:45:41 +0100 Subject: [PATCH] Fix parameters or JSX dev runtime (#3880) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * There was a parameter missing (`isStaticChildren: boolean`), which is not useful\*, but is still being passed * Fix order of `source` and `self` again (incorrectly introduced in GH-3459) * Fix some (internal JSDoc) types for these parameters My guess is that the previous PR “fixed” the earlier problem because `self` isn’t used, so by calling `isStaticChildren` “`self`”, a bug went away. The source for where this `jsxDEV` call is generated in Babel is here: . The React RFC for the transform that mentions the dev runtime is here: \* `isStaticChildren` is the same as whether `jsxs` would be used, instead of `jsx`. Which is also whether there are 2 or more children passed: * `` -> `jsx('a', {})` * `b` -> `jsx('a', {children: 'b'})` * `{1}{2}` -> `jsxs('a', {children: [1, 2]})` Related-to: GH-3459. --- jsx-runtime/src/index.js | 7 ++++--- jsx-runtime/test/browser/jsx-runtime.test.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/jsx-runtime/src/index.js b/jsx-runtime/src/index.js index 260d68703e..b578b9da7e 100644 --- a/jsx-runtime/src/index.js +++ b/jsx-runtime/src/index.js @@ -20,10 +20,11 @@ let vnodeId = 0; * @param {VNode['type']} type * @param {VNode['props']} props * @param {VNode['key']} [key] - * @param {string} [__self] - * @param {string} [__source] + * @param {unknown} [isStaticChildren] + * @param {unknown} [__source] + * @param {unknown} [__self] */ -function createVNode(type, props, key, __self, __source) { +function createVNode(type, props, key, isStaticChildren, __source, __self) { // We'll want to preserve `ref` in props to get rid of the need for // forwardRef components in the future, but that should happen via // a separate PR. diff --git a/jsx-runtime/test/browser/jsx-runtime.test.js b/jsx-runtime/test/browser/jsx-runtime.test.js index daf71ae3be..7fd48b896f 100644 --- a/jsx-runtime/test/browser/jsx-runtime.test.js +++ b/jsx-runtime/test/browser/jsx-runtime.test.js @@ -66,7 +66,7 @@ describe('Babel jsx/jsxDEV', () => { }); it('should set __source and __self', () => { - const vnode = jsx('div', { class: 'foo' }, 'key', 'self', 'source'); + const vnode = jsx('div', { class: 'foo' }, 'key', false, 'source', 'self'); expect(vnode.__source).to.equal('source'); expect(vnode.__self).to.equal('self'); });