Skip to content
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
17 changes: 11 additions & 6 deletions jsx-runtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@ const isArray = Array.isArray;
* @param {unknown} [__self]
*/
function createVNode(type, props, key, isStaticChildren, __source, __self) {
if (!props) props = {};
// 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.
let normalizedProps = {},
let normalizedProps = props,
ref,
i;
for (i in props) {
if (i == 'ref') {
ref = props[i];
} else {
normalizedProps[i] = props[i];

if ('ref' in normalizedProps) {
normalizedProps = {};
for (i in props) {
if (i == 'ref') {
ref = props[i];
} else {
normalizedProps[i] = props[i];
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion jsx-runtime/test/browser/jsx-runtime.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@ describe('Babel jsx/jsxDEV', () => {

it('should keep ref in props', () => {
const ref = () => null;
const vnode = jsx('div', { ref });
const props = { ref };
const vnode = jsx('div', props);
expect(vnode.ref).to.equal(ref);
expect(vnode.props).to.not.equal(props);
});

it('should not copy props wen there is no ref in props', () => {
const props = { x: 'y' };
const vnode = jsx('div', props);
expect(vnode.props).to.equal(props);
});

it('should add keys', () => {
Expand Down