Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/react-reconciler/src/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,11 +791,12 @@ function completeUnitOfWork(workInProgress: Fiber): Fiber | null {

if ((workInProgress.effectTag & Incomplete) === NoEffect) {
// This fiber completed.
let next = completeWork(
nextUnitOfWork = completeWork(
current,
workInProgress,
nextRenderExpirationTime,
);
let next = nextUnitOfWork;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

next is always null ever since we deleted call/return. Let's just remove the block below.

stopWorkTimer(workInProgress);
resetExpirationTime(workInProgress, nextRenderExpirationTime);
if (__DEV__) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,27 @@ describe('ReactNewContext', () => {
]);
});

it('unwinds after errors in complete phase', () => {
const Context = React.createContext(0);

// This is a regression test for stack misalignment
// caused by unwinding the context from wrong point.
ReactNoop.render(
<errorInCompletePhase>
<Context.Provider />
</errorInCompletePhase>,
);
expect(ReactNoop.flush).toThrow('Error in host config.');

ReactNoop.render(
<Context.Provider value={10}>
<Context.Consumer>{value => <span prop={value} />}</Context.Consumer>
</Context.Provider>,
);
ReactNoop.flush();
expect(ReactNoop.getChildren()).toEqual([span(10)]);
});

describe('fuzz test', () => {
const Fragment = React.Fragment;
const contextKeys = ['A', 'B', 'C', 'D', 'E', 'F', 'G'];
Expand Down
11 changes: 11 additions & 0 deletions packages/react/src/__tests__/ReactProfiler-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,17 @@ describe('Profiler', () => {
);
expect(ReactNoop.flush).toThrow('Error in host config.');

// A similar case we've seen caused by an invariant in ReactDOM.
// It didn't reproduce without a host component inside.
ReactNoop.render(
<React.unstable_Profiler id="profiler" onRender={jest.fn()}>
<errorInCompletePhase>
<span>hi</span>
</errorInCompletePhase>
</React.unstable_Profiler>,
);
expect(ReactNoop.flush).toThrow('Error in host config.');

// So long as the profiler timer's fiber stack is reset correctly,
// Subsequent renders should not error.
ReactNoop.render(
Expand Down