diff --git a/Changelog.md b/Changelog.md index 24085b18b4..e9d669673b 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) @@ -33,6 +33,7 @@ first three params (`TChildProps` can be derived). [#1402](https://github.com/ap - 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) - Add `client` to `Query`'s `QueryResult` [#1488](https://github.com/apollographql/react-apollo/pull/1488) + - 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 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 }) => (