Skip to content

Commit

Permalink
Add test for context consumers inside hidden subtree
Browse files Browse the repository at this point in the history
Should not bail out during subsequent update. (This isn't directly
related to this PR because we should have had this test, anyway.)
  • Loading branch information
acdlite committed Jan 16, 2019
1 parent f13dccf commit 4c65d54
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ function updateHostComponent(current, workInProgress, renderExpirationTime) {
shouldDeprioritizeSubtree(type, nextProps)
) {
// Schedule this fiber to re-render at offscreen priority. Then bailout.
workInProgress.expirationTime = Never;
workInProgress.expirationTime = workInProgress.childExpirationTime = Never;
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,37 @@ describe('ReactNewContext', () => {
expect(ReactNoop.getChildren()).toEqual([span(2), span(2)]);
});

it("context consumer doesn't bail out inside hidden subtree", () => {
const Context = React.createContext('dark');
const Consumer = getConsumer(Context);

function App({theme}) {
return (
<Context.Provider value={theme}>
<div hidden={true}>
<Consumer>{value => <Text text={value} />}</Consumer>
</div>
</Context.Provider>
);
}

ReactNoop.render(<App theme="dark" />);
expect(ReactNoop.flush()).toEqual(['dark']);
expect(ReactNoop.getChildrenAsJSX()).toEqual(
<div hidden={true}>
<span prop="dark" />
</div>,
);

ReactNoop.render(<App theme="light" />);
expect(ReactNoop.flush()).toEqual(['light']);
expect(ReactNoop.getChildrenAsJSX()).toEqual(
<div hidden={true}>
<span prop="light" />
</div>,
);
});

// This is a regression case for https://github.com/facebook/react/issues/12389.
it('does not run into an infinite loop', () => {
const Context = React.createContext(null);
Expand Down

0 comments on commit 4c65d54

Please sign in to comment.