Skip to content

Commit 0023670

Browse files
authored
Revert "Improve performance and reduce memory allocation" (#4611)
This reverts commit 79303ec.
1 parent bb68456 commit 0023670

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

compat/src/forwardRef.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { options } from 'preact';
2+
import { assign } from './util';
23

34
let oldDiffHook = options._diff;
45
options._diff = vnode => {
@@ -24,13 +25,9 @@ export const REACT_FORWARD_SYMBOL =
2425
*/
2526
export function forwardRef(fn) {
2627
function Forwarded(props) {
27-
if (!('ref' in props)) return fn(props, null);
28-
29-
let ref = props.ref;
30-
delete props.ref;
31-
const result = fn(props, ref);
32-
props.ref = ref;
33-
return result;
28+
let clone = assign({}, props);
29+
delete clone.ref;
30+
return fn(clone, props.ref || null);
3431
}
3532

3633
// mobx-react checks for this being present

jsx-runtime/src/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,15 @@ function createVNode(type, props, key, isStaticChildren, __source, __self) {
3535
ref,
3636
i;
3737

38-
if ('ref' in props) {
39-
ref = props.ref;
40-
delete props.ref;
38+
if ('ref' in normalizedProps) {
39+
normalizedProps = {};
40+
for (i in props) {
41+
if (i == 'ref') {
42+
ref = props[i];
43+
} else {
44+
normalizedProps[i] = props[i];
45+
}
46+
}
4147
}
4248

4349
/** @type {VNode & { __source: any; __self: any }} */

jsx-runtime/test/browser/jsx-runtime.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ describe('Babel jsx/jsxDEV', () => {
3737
const props = { ref };
3838
const vnode = jsx('div', props);
3939
expect(vnode.ref).to.equal(ref);
40-
expect(vnode.props).to.equal(props);
41-
expect(vnode.props.ref).to.equal(undefined);
40+
expect(vnode.props).to.not.equal(props);
4241
});
4342

4443
it('should not copy props wen there is no ref in props', () => {

0 commit comments

Comments
 (0)