Skip to content

Commit

Permalink
RelayContainer: pass empty arrays through for plural fragments
Browse files Browse the repository at this point in the history
Summary:Fixes an issue where passing an empty array as a prop corresponding to a plural fragment would warn about mock data. The empty array is now passed through to the component as-is.
Closes #875

Reviewed By: yungsters

Differential Revision: D2970111

fb-gh-sync-id: c3a1f3af2426c1170b8b04922df7c5600ef806bb
shipit-source-id: c3a1f3af2426c1170b8b04922df7c5600ef806bb
  • Loading branch information
josephsavona authored and facebook-github-bot-4 committed Feb 24, 2016
1 parent 8e498e7 commit 20bdae4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/container/RelayContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@ function createContainerComponent(
fragmentName,
componentName
);
if (!propValue.length) {
// Nothing to observe: pass the empty array through
fragmentPointers[fragmentName] = null;
return;
}
let dataIDs = null;
propValue.forEach((item, ii) => {
if (typeof item === 'object' && item != null) {
Expand Down
11 changes: 11 additions & 0 deletions src/container/__tests__/RelayContainer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,17 @@ describe('RelayContainer', function() {
);
});

it('passes through empty arrays for plural fragments', () => {
RelayTestRenderer.render(
() => <MockContainer bar={[]} />,
relayContext,
mockRoute
);
expect(MockContainer.mock.render.mock.calls.length).toBe(1);
expect(MockContainer.mock.render.mock.calls[0].props.bar).toEqual([]);
expect(relayContext.getFragmentResolver).not.toBeCalled();
});

it('does not re-render if props resolve to the same object', () => {
var mockData = {__dataID__: '42', id: '42', name: 'Tim'};

Expand Down

0 comments on commit 20bdae4

Please sign in to comment.