Skip to content

Revert "Improve performance and reduce memory allocation" #4611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading