Skip to content

Commit

Permalink
Revert "Improve performance and reduce memory allocation" (#4611)
Browse files Browse the repository at this point in the history
This reverts commit 79303ec.
  • Loading branch information
JoviDeCroock authored Dec 18, 2024
1 parent bb68456 commit 0023670
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
11 changes: 4 additions & 7 deletions compat/src/forwardRef.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { options } from 'preact';
import { assign } from './util';

let oldDiffHook = options._diff;
options._diff = vnode => {
Expand All @@ -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
Expand Down
12 changes: 9 additions & 3 deletions jsx-runtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }} */
Expand Down
3 changes: 1 addition & 2 deletions jsx-runtime/test/browser/jsx-runtime.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 0023670

Please sign in to comment.