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

Disregard falsy elements when walking tree #1495

Merged
merged 5 commits into from Dec 29, 2017

Conversation

Projects
None yet
4 participants
@bostrom
Copy link
Contributor

bostrom commented Dec 29, 2017

This PR fixes a problem with server side rendering when rendering an array and one or more of the items in the array is falsy (but other than null). This would throw an cannot read property type of null error.

An example case when this can happen is when you do a inline conditional render:

const renderSmth = false;

render() {
  return [
    renderSmth && (<Smth key="smth" />),
    <MoreContent key="morecontent" />
  ];
}

React handles this case gracefully by disregarding falsy values, not rendering them. I would like to assume that Apollo would do the same, but that's not the case, currently it only checks if an element is null.

This PR replaces the element == null with !element, effectively disregarding all falsy values altogether, more closely mimicking the behaviour of React.

@meteor-bot

This comment has been minimized.

Copy link

meteor-bot commented Dec 29, 2017

@bostrom: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Meteor Contributor Agreement here: https://contribute.meteor.com/

bostrom and others added some commits Dec 29, 2017

@rosskevin rosskevin merged commit c95f7cb into apollographql:master Dec 29, 2017

4 checks passed

CLA Author has signed the Meteor CLA.
Details
bundlesize ./lib/umd/react-apollo.js: 4.66KB < maxSize 4.7KB gzip (same as master)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage remained the same at 96.104%
Details
@rosskevin

This comment has been minimized.

Copy link
Collaborator

rosskevin commented Dec 29, 2017

Thanks @bostrom

@bostrom bostrom deleted the bostrom:ssr-disregard-falsy branch Dec 29, 2017

@tzvipm

This comment has been minimized.

Copy link

tzvipm commented Jan 2, 2018

@rosskevin any idea when the next react-apollo release will be, so we can take advantage of this fix?

@rosskevin

This comment has been minimized.

Copy link
Collaborator

rosskevin commented Jan 2, 2018

@Omniroot We don't have a timeline yet, but if you are up for using master, feel free to grab my package for the time being (you'll have to either alias your imports or search/replace for the time being). https://www.npmjs.com/package/@alienfast/react-apollo

We will be discussing strategy for the next release on Friday 1/5/18 with the committers.

@bostrom

This comment has been minimized.

Copy link
Contributor Author

bostrom commented Jan 3, 2018

@Omniroot as a workaround, you can filter the array:

render() {
  return [
    renderSmth && (<Smth key="smth" />),
    <MoreContent key="morecontent" />
  ].filter(Boolean);
}
@tzvipm

This comment has been minimized.

Copy link

tzvipm commented Jan 8, 2018

@rosskevin any idea what the plan is for the next release?

@rosskevin

This comment has been minimized.

Copy link
Collaborator

rosskevin commented Jan 8, 2018

@Omniroot we are discussing on a call tomorrow, call was moved from Friday.

@tzvipm

This comment has been minimized.

Copy link

tzvipm commented Jan 15, 2018

@rosskevin any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment