Skip to content
This repository has been archived by the owner on Aug 1, 2018. It is now read-only.

Support React.Fragment #84

Merged
merged 3 commits into from
Mar 26, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 16 additions & 0 deletions src/__tests__/__node__/prepare-render.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,19 @@ tape('Preparing an async app with componentWillReceiveProps option', t => {
t.end();
});
});

tape('Preparing a Fragment', t => {
const app = (
<React.Fragment>
<span>1</span>
<span>2</span>
</React.Fragment>
);
const p = prepare(app);
t.ok(p instanceof Promise, 'prepare returns a promise');
p.then(() => {
const wrapper = shallow(<div>{app}</div>);
t.equal(wrapper.find('span').length, 2, 'has two children');
t.end();
});
});
2 changes: 1 addition & 1 deletion src/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function prepareElement(element, context) {
return Promise.resolve([null, context]);
}
const {type, props} = element;
if (typeof type === 'string') {
if (typeof type === 'string' || type === React.Fragment) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we should still traverse the children here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a code example where this would be leveraged? I checked with a simple <div> element, and this was the path that we fall into, so I imagined it would be similar to a div case. Seems like we should handle children the same in both cases?

return Promise.resolve([props.children, context]);
}
if (!isReactCompositeComponent(type)) {
Expand Down