Skip to content

Commit 63cf49f

Browse files
clayne11James Baxley
authored andcommitted
Support arrays in server-side rendering (apollographql#1265)
React 16 now allows arrays to be returned from render. Update walkTree to support this.
1 parent aa2e13e commit 63cf49f

File tree

3 files changed

+122
-133
lines changed

3 files changed

+122
-133
lines changed

Changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
- Fix: ensure `client` option can be used with mutation query [#1145](https://github.com/apollographql/react-apollo/pull/1145)
66

77
- Made `OptionProps.data`'s `TResult` partial [#1231](https://github.com/apollographql/react-apollo/pull/1231)
8-
8+
- Support arrays being returned from render in SSR [#1158](https://github.com/apollographql/react-apollo/pull/1158)
99

1010
### 1.4.16
1111
- upgrade to react-16

src/server.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ export function walkTree(
3737
context: Context,
3838
) => boolean | void,
3939
) {
40+
// elements can now be arrays (react@16)
41+
if (Array.isArray(element)) {
42+
element.forEach(item => walkTree(item, context, visitor));
43+
return;
44+
}
45+
4046
const Component = element.type;
4147
// a stateless functional component or a class
4248
if (typeof Component === 'function') {
@@ -90,7 +96,11 @@ export function walkTree(
9096
}
9197

9298
if (child) {
93-
walkTree(child, childContext, visitor);
99+
if (Array.isArray(child)) {
100+
child.forEach(item => walkTree(item, context, visitor));
101+
} else {
102+
walkTree(child, childContext, visitor);
103+
}
94104
}
95105
} else {
96106
// a basic string or dom element, just get children

0 commit comments

Comments
 (0)