Skip to content
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

Fix: Remove props.key even when key === 0 or key === "" #1607

Merged
merged 1 commit into from May 6, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/create-element.js
Expand Up @@ -30,9 +30,9 @@ export function createElement(type, props, children) {
}
}
let ref = props.ref;
if (ref) delete props.ref;
let key = props.key;
if (key) delete props.key;
if (ref!=null) delete props.ref;
if (key!=null) delete props.key;

return createVNode(type, props, key, ref);
}
Expand Down
12 changes: 12 additions & 0 deletions test/shared/createElement.test.js
Expand Up @@ -48,13 +48,25 @@ describe('createElement(jsx)', () => {
expect(<div key="1" />).to.have.property('key', '1');
});

it('should not set VNode#props.key property', () => {
expect(<div />).to.not.have.nested.property('props.key');
expect(<div key="1" />).to.not.have.nested.property('props.key');
expect(<div key={0} />).to.not.have.nested.property('props.key');
expect(<div key={''} />).to.not.have.nested.property('props.key');
});

it('should set VNode#ref property', () => {
expect(<div />).to.have.property('ref').that.is.undefined;
expect(<div a="a" />).to.have.property('ref').that.is.undefined;
const emptyFunction = () => {};
expect(<div ref={emptyFunction} />).to.have.property('ref', emptyFunction);
});

it('should not set VNode#props.ref property', () => {
expect(<div />).to.not.have.nested.property('props.ref');
expect(<div ref={() => {}} />).to.not.have.nested.property('props.ref');
});

it('should have ordered VNode properties', () => {
expect(Object.keys(<div />).filter(key => !/^_/.test(key))).to.deep.equal(['type', 'props', 'key', 'ref']);
});
Expand Down