diff --git a/compat/src/forwardRef.js b/compat/src/forwardRef.js index 35105eadc5..25791285b9 100644 --- a/compat/src/forwardRef.js +++ b/compat/src/forwardRef.js @@ -1,4 +1,5 @@ import { options } from 'preact'; +import { assign } from './util'; let oldDiffHook = options._diff; options._diff = vnode => { @@ -24,13 +25,9 @@ export const REACT_FORWARD_SYMBOL = */ export function forwardRef(fn) { function Forwarded(props) { - if (!('ref' in props)) return fn(props, null); - - let ref = props.ref; - delete props.ref; - const result = fn(props, ref); - props.ref = ref; - return result; + let clone = assign({}, props); + delete clone.ref; + return fn(clone, props.ref || null); } // mobx-react checks for this being present diff --git a/jsx-runtime/src/index.js b/jsx-runtime/src/index.js index 6f20acd42f..6bf06a06ec 100644 --- a/jsx-runtime/src/index.js +++ b/jsx-runtime/src/index.js @@ -35,9 +35,15 @@ function createVNode(type, props, key, isStaticChildren, __source, __self) { ref, i; - if ('ref' in props) { - ref = props.ref; - delete props.ref; + if ('ref' in normalizedProps) { + normalizedProps = {}; + for (i in props) { + if (i == 'ref') { + ref = props[i]; + } else { + normalizedProps[i] = props[i]; + } + } } /** @type {VNode & { __source: any; __self: any }} */ diff --git a/jsx-runtime/test/browser/jsx-runtime.test.js b/jsx-runtime/test/browser/jsx-runtime.test.js index c3b338d2db..ac678ce477 100644 --- a/jsx-runtime/test/browser/jsx-runtime.test.js +++ b/jsx-runtime/test/browser/jsx-runtime.test.js @@ -37,8 +37,7 @@ describe('Babel jsx/jsxDEV', () => { const props = { ref }; const vnode = jsx('div', props); expect(vnode.ref).to.equal(ref); - expect(vnode.props).to.equal(props); - expect(vnode.props.ref).to.equal(undefined); + expect(vnode.props).to.not.equal(props); }); it('should not copy props wen there is no ref in props', () => {