From e6162e0ca40b6f6136886660b2a2a7cc532086ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Bostr=C3=B6m?= Date: Fri, 29 Dec 2017 13:21:51 +0200 Subject: [PATCH 1/2] Disregard falsy elements when walking tree --- src/getDataFromTree.ts | 2 +- test/server/getDataFromTree.test.tsx | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/getDataFromTree.ts b/src/getDataFromTree.ts index 49f5f3897d..935794262a 100755 --- a/src/getDataFromTree.ts +++ b/src/getDataFromTree.ts @@ -37,7 +37,7 @@ export function walkTree( return; } - if (element == null) return; + if (!element) return; const Component = element.type; // a stateless functional component or a class diff --git a/test/server/getDataFromTree.test.tsx b/test/server/getDataFromTree.test.tsx index 3f4922deda..2c18204d7e 100644 --- a/test/server/getDataFromTree.test.tsx +++ b/test/server/getDataFromTree.test.tsx @@ -41,6 +41,24 @@ describe('SSR', () => { expect(elementCount).toEqual(1); }); + it('basic element trees with false', () => { + let elementCount = 0; + const rootElement =
{false}
; + walkTree(rootElement, {}, element => { + elementCount += 1; + }); + expect(elementCount).toEqual(1); + }); + + it('basic element trees with empty string', () => { + let elementCount = 0; + const rootElement =
{''}
; + walkTree(rootElement, {}, element => { + elementCount += 1; + }); + expect(elementCount).toEqual(1); + }); + it('basic element trees with arrays', () => { let elementCount = 0; const rootElement = [1, 2]; @@ -50,6 +68,15 @@ describe('SSR', () => { expect(elementCount).toEqual(2); }); + it('basic element trees with false or null', () => { + let elementCount = 0; + const rootElement = [1, false, null, '']; + walkTree(rootElement, {}, element => { + elementCount += 1; + }); + expect(elementCount).toEqual(1); + }); + it('functional stateless components', () => { let elementCount = 0; const MyComponent = ({ n }) => ( From ecae06da22eff7fa2236e72a5c3b06619840a372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Bostr=C3=B6m?= Date: Fri, 29 Dec 2017 13:33:42 +0200 Subject: [PATCH 2/2] Add changelog --- Changelog.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index c43fec465c..c89a381d30 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,10 +3,10 @@ ### next - **BREAKING CHANGES** - - typescript - `graphql` parameterized types streamlined for -a) full typing; and b) ease of use; and c) consistency. New parameterized is: + - typescript - `graphql` parameterized types streamlined for +a) full typing; and b) ease of use; and c) consistency. New parameterized is: `graphql` where none are required and full typing only requires the -first three params (`TChildProps` can be derived). [#1402](https://github.com/apollographql/react-apollo/pull/1402) +first three params (`TChildProps` can be derived). [#1402](https://github.com/apollographql/react-apollo/pull/1402) - Remove deprecated `operationOptions.options.skip`, use `operationOptions.skip` instead - Rename type `ProviderProps` to `ApolloProviderProps` [#1467](https://github.com/apollographql/react-apollo/pull/1467) - Rename `getDataFromTree` type `QueryResult` to `QueryTreeResult` [#1467](https://github.com/apollographql/react-apollo/pull/1467) @@ -31,6 +31,7 @@ first three params (`TChildProps` can be derived). [#1402](https://github.com/ap - Updates to `examples/typescript` [#1471](https://github.com/apollographql/react-apollo/pull/1471) - Mutation test cleanup [#1480](https://github.com/apollographql/react-apollo/pull/1480) - Removed react-native from the test suite [#1451](https://github.com/apollographql/react-apollo/pull/1451) + - Disregard falsy elements when walking tree in SSR [#1495](https://github.com/apollographql/react-apollo/pull/1495) ### 2.0.4 - rolled back on the lodash-es changes from