Skip to content

Commit

Permalink
Remove dead branches
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored and acdlite committed Oct 29, 2020
1 parent 763d5f2 commit 99a5f22
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,9 @@ describe('ReactDOMServerPartialHydration', () => {
// This is a new node.
expect(span).not.toBe(span2);

if (gate(flags => flags.new)) {
// The effects list refactor causes this to be null because the Suspense Offscreen's child
// is null. However, since we can't hydrate Suspense in legacy this change in behavior is ok
expect(ref.current).toBe(null);
} else {
expect(ref.current).toBe(span2);
}
// The effects list refactor causes this to be null because the Suspense Offscreen's child
// is null. However, since we can't hydrate Suspense in legacy this change in behavior is ok
expect(ref.current).toBe(null);

// Resolving the promise should render the final content.
suspend = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,14 @@ describe('DebugTracing', () => {
expect(logs).toEqual([
'group: ⚛️ render (0b0000000000000000000001000000000)',
'log: ⚛️ Example updated state (0b0000000000000000000001000000000)',
'log: ⚛️ Example updated state (0b0000000000000000000001000000000)', // debugRenderPhaseSideEffectsForStrictMode
'log: ⚛️ Example updated state (0b0000000000000000000001000000000)',
'groupEnd: ⚛️ render (0b0000000000000000000001000000000)',
]);
} else {
expect(logs).toEqual([
'group: ⚛️ render (0b0000000000000000000001000000000)',
'log: ⚛️ Example updated state (0b0000000000000000000010000000000)',
'log: ⚛️ Example updated state (0b0000000000000000000010000000000)', // debugRenderPhaseSideEffectsForStrictMode
'log: ⚛️ Example updated state (0b0000000000000000000010000000000)',
'groupEnd: ⚛️ render (0b0000000000000000000001000000000)',
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2356,7 +2356,6 @@ describe('ReactHooksWithNoopRenderer', () => {
describe('errors thrown in passive destroy function within unmounted trees', () => {
let BrokenUseEffectCleanup;
let ErrorBoundary;
let DerivedStateOnlyErrorBoundary;
let LogOnlyErrorBoundary;

beforeEach(() => {
Expand Down Expand Up @@ -2395,28 +2394,6 @@ describe('ReactHooksWithNoopRenderer', () => {
}
};

DerivedStateOnlyErrorBoundary = class extends React.Component {
state = {error: null};
static getDerivedStateFromError(error) {
Scheduler.unstable_yieldValue(
`DerivedStateOnlyErrorBoundary static getDerivedStateFromError`,
);
return {error};
}
render() {
if (this.state.error) {
Scheduler.unstable_yieldValue(
'DerivedStateOnlyErrorBoundary render error',
);
return <span prop="DerivedStateOnlyErrorBoundary fallback" />;
}
Scheduler.unstable_yieldValue(
'DerivedStateOnlyErrorBoundary render success',
);
return this.props.children || null;
}
};

LogOnlyErrorBoundary = class extends React.Component {
componentDidCatch(error, info) {
Scheduler.unstable_yieldValue(
Expand All @@ -2430,162 +2407,7 @@ describe('ReactHooksWithNoopRenderer', () => {
};
});

// @gate old
it('should call componentDidCatch() for the nearest unmounted log-only boundary', () => {
function Conditional({showChildren}) {
if (showChildren) {
return (
<LogOnlyErrorBoundary>
<BrokenUseEffectCleanup />
</LogOnlyErrorBoundary>
);
} else {
return null;
}
}

act(() => {
ReactNoop.render(
<ErrorBoundary>
<Conditional showChildren={true} />
</ErrorBoundary>,
);
});

expect(Scheduler).toHaveYielded([
'ErrorBoundary render success',
'LogOnlyErrorBoundary render',
'BrokenUseEffectCleanup useEffect',
]);

act(() => {
ReactNoop.render(
<ErrorBoundary>
<Conditional showChildren={false} />
</ErrorBoundary>,
);
expect(Scheduler).toFlushAndYieldThrough([
'ErrorBoundary render success',
]);
});

expect(Scheduler).toHaveYielded([
'BrokenUseEffectCleanup useEffect destroy',
'LogOnlyErrorBoundary componentDidCatch',
]);
});

// @gate old
it('should call componentDidCatch() for the nearest unmounted logging-capable boundary', () => {
function Conditional({showChildren}) {
if (showChildren) {
return (
<ErrorBoundary>
<BrokenUseEffectCleanup />
</ErrorBoundary>
);
} else {
return null;
}
}

act(() => {
ReactNoop.render(
<ErrorBoundary>
<Conditional showChildren={true} />
</ErrorBoundary>,
);
});

expect(Scheduler).toHaveYielded([
'ErrorBoundary render success',
'ErrorBoundary render success',
'BrokenUseEffectCleanup useEffect',
]);

act(() => {
ReactNoop.render(
<ErrorBoundary>
<Conditional showChildren={false} />
</ErrorBoundary>,
);
expect(Scheduler).toFlushAndYieldThrough([
'ErrorBoundary render success',
]);
});

expect(Scheduler).toHaveYielded([
'BrokenUseEffectCleanup useEffect destroy',
'ErrorBoundary componentDidCatch',
]);
});

// @gate old
it('should not call getDerivedStateFromError for unmounted error boundaries', () => {
function Conditional({showChildren}) {
if (showChildren) {
return (
<ErrorBoundary>
<BrokenUseEffectCleanup />
</ErrorBoundary>
);
} else {
return null;
}
}

act(() => {
ReactNoop.render(<Conditional showChildren={true} />);
});

expect(Scheduler).toHaveYielded([
'ErrorBoundary render success',
'BrokenUseEffectCleanup useEffect',
]);

act(() => {
ReactNoop.render(<Conditional showChildren={false} />);
});

expect(Scheduler).toHaveYielded([
'BrokenUseEffectCleanup useEffect destroy',
'ErrorBoundary componentDidCatch',
]);
});

// @gate old
it('should not throw if there are no unmounted logging-capable boundaries to call', () => {
function Conditional({showChildren}) {
if (showChildren) {
return (
<DerivedStateOnlyErrorBoundary>
<BrokenUseEffectCleanup />
</DerivedStateOnlyErrorBoundary>
);
} else {
return null;
}
}

act(() => {
ReactNoop.render(<Conditional showChildren={true} />);
});

expect(Scheduler).toHaveYielded([
'DerivedStateOnlyErrorBoundary render success',
'BrokenUseEffectCleanup useEffect',
]);

act(() => {
ReactNoop.render(<Conditional showChildren={false} />);
});

expect(Scheduler).toHaveYielded([
'BrokenUseEffectCleanup useEffect destroy',
]);
});

// @gate new
// @gate skipUnmountedBoundaries
it('should use the nearest still-mounted boundary if there are no unmounted boundaries', () => {
act(() => {
ReactNoop.render(
Expand All @@ -2611,8 +2433,8 @@ describe('ReactHooksWithNoopRenderer', () => {
]);
});

// @gate new
it('should skip unmounted boundaries and use the nearest still-mounted boundary', () => {
// @gate skipUnmountedBoundaries
it('should skip unmounted boundaries and use the nearest still-mounted boundary', () => {
function Conditional({showChildren}) {
if (showChildren) {
return (
Expand Down Expand Up @@ -2654,7 +2476,7 @@ describe('ReactHooksWithNoopRenderer', () => {
]);
});

// @gate new
// @gate skipUnmountedBoundaries
it('should call getDerivedStateFromError in the nearest still-mounted boundary', () => {
function Conditional({showChildren}) {
if (showChildren) {
Expand Down Expand Up @@ -2698,7 +2520,7 @@ describe('ReactHooksWithNoopRenderer', () => {
]);
});

// @gate new
// @gate skipUnmountedBoundaries
it('should rethrow error if there are no still-mounted boundaries', () => {
function Conditional({showChildren}) {
if (showChildren) {
Expand Down
22 changes: 2 additions & 20 deletions packages/react/src/__tests__/ReactDOMTracing-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,7 @@ describe('ReactDOMTracing', () => {
onInteractionScheduledWorkCompleted,
).toHaveBeenLastNotifiedOfInteraction(interaction);

if (gate(flags => flags.new)) {
expect(onRender).toHaveBeenCalledTimes(3);
} else {
// TODO: This is 4 instead of 3 because this update was scheduled at
// idle priority, and idle updates are slightly higher priority than
// offscreen work. So it takes two render passes to finish it. Profiler
// calls `onRender` for the first render even though everything
// bails out.
expect(onRender).toHaveBeenCalledTimes(4);
}
expect(onRender).toHaveBeenCalledTimes(3);
expect(onRender).toHaveLastRenderedWithInteractions(
new Set([interaction]),
);
Expand Down Expand Up @@ -310,16 +301,7 @@ describe('ReactDOMTracing', () => {
expect(
onInteractionScheduledWorkCompleted,
).toHaveBeenLastNotifiedOfInteraction(interaction);
if (gate(flags => flags.new)) {
expect(onRender).toHaveBeenCalledTimes(3);
} else {
// TODO: This is 4 instead of 3 because this update was scheduled at
// idle priority, and idle updates are slightly higher priority than
// offscreen work. So it takes two render passes to finish it. Profiler
// calls `onRender` for the first render even though everything
// bails out.
expect(onRender).toHaveBeenCalledTimes(4);
}
expect(onRender).toHaveBeenCalledTimes(3);
expect(onRender).toHaveLastRenderedWithInteractions(
new Set([interaction]),
);
Expand Down
43 changes: 8 additions & 35 deletions packages/react/src/__tests__/ReactProfiler-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,31 +364,9 @@ describe('Profiler', () => {

renderer.update(<App />);

if (gate(flags => flags.new)) {
// None of the Profiler's subtree was rendered because App bailed out before the Profiler.
// So we expect onRender not to be called.
expect(callback).not.toHaveBeenCalled();
} else {
// Updating a parent reports a re-render,
// since React technically did a little bit of work between the Profiler and the bailed out subtree.
// This is not optimal but it's how the old reconciler fork works.
expect(callback).toHaveBeenCalledTimes(1);

call = callback.mock.calls[0];

expect(call).toHaveLength(enableSchedulerTracing ? 7 : 6);
expect(call[0]).toBe('test');
expect(call[1]).toBe('update');
expect(call[2]).toBe(0); // actual time
expect(call[3]).toBe(10); // base time
expect(call[4]).toBe(30); // start time
expect(call[5]).toBe(30); // commit time
expect(call[6]).toEqual(
enableSchedulerTracing ? new Set() : undefined,
); // interaction events

callback.mockReset();
}
// None of the Profiler's subtree was rendered because App bailed out before the Profiler.
// So we expect onRender not to be called.
expect(callback).not.toHaveBeenCalled();

Scheduler.unstable_advanceTime(20); // 30 -> 50

Expand Down Expand Up @@ -3714,15 +3692,11 @@ describe('Profiler', () => {
wrappedCascadingFn();
expect(Scheduler).toHaveYielded(['onPostCommit', 'render']);

// The new reconciler does not call onPostCommit again
// because the resolved suspended subtree doesn't contain any passive effects.
// If <AsyncComponentWithCascadingWork> or its decendents had a passive effect,
// onPostCommit would be called again.
if (gate(flags => flags.new)) {
expect(Scheduler).toFlushAndYield([]);
} else {
expect(Scheduler).toFlushAndYield(['onPostCommit']);
}
// Does not call onPostCommit again because the resolved suspended
// subtree doesn't contain any passive effects. If
// <AsyncComponentWithCascadingWork> or its decendents had a passive
// effect, onPostCommit would be called again.
expect(Scheduler).toFlushAndYield([]);

expect(onInteractionScheduledWorkCompleted).toHaveBeenCalledTimes(1);
expect(
Expand Down Expand Up @@ -4209,7 +4183,6 @@ describe('Profiler', () => {
});

if (__DEV__) {
// @gate new
it('double invoking does not disconnect wrapped async work', () => {
ReactFeatureFlags.enableDoubleInvokingEffects = true;

Expand Down

0 comments on commit 99a5f22

Please sign in to comment.