Skip to content
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

Delete vestigial RetryAfterError logic #23312

Merged
merged 1 commit into from
Feb 17, 2022
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
77 changes: 77 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,83 @@ describe('ReactDOMFizzServer', () => {
}
});

// @gate experimental
it(
'errors during hydration in the shell force a client render at the ' +
'root, and during the client render it recovers',
async () => {
let isClient = false;

function subscribe() {
return () => {};
}
function getClientSnapshot() {
return 'Yay!';
}

// At the time of writing, the only API that exposes whether it's currently
// hydrating is the `getServerSnapshot` API, so I'm using that here to
// simulate an error during hydration.
function getServerSnapshot() {
if (isClient) {
throw new Error('Hydration error');
}
return 'Yay!';
}

function Child() {
const value = useSyncExternalStore(
subscribe,
getClientSnapshot,
getServerSnapshot,
);
Scheduler.unstable_yieldValue(value);
return value;
}

const spanRef = React.createRef();

function App() {
return (
<span ref={spanRef}>
<Child />
</span>
);
}

await act(async () => {
const {pipe} = ReactDOMFizzServer.renderToPipeableStream(<App />);
pipe(writable);
});
expect(Scheduler).toHaveYielded(['Yay!']);

const span = container.getElementsByTagName('span')[0];

// Hydrate the tree. Child will throw during hydration, but not when it
// falls back to client rendering.
isClient = true;
ReactDOM.hydrateRoot(container, <App />, {
onRecoverableError(error) {
Scheduler.unstable_yieldValue(error.message);
},
});

// An error logged but instead of surfacing it to the UI, we switched
// to client rendering.
expect(() => {
expect(Scheduler).toFlushAndYield(['Yay!', 'Hydration error']);
}).toErrorDev(
'An error occurred during hydration. The server HTML was replaced',
{withoutStack: true},
);
expect(getVisibleChildren(container)).toEqual(<span>Yay!</span>);

// The node that's inside the boundary that errored during hydration was
// not hydrated.
expect(spanRef.current).not.toBe(span);
},
);

// @gate experimental
it(
'errors during hydration force a client render at the nearest Suspense ' +
Expand Down
11 changes: 0 additions & 11 deletions packages/react-reconciler/src/ReactFiberBeginWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,6 @@ import {
markSkippedUpdateLanes,
getWorkInProgressRoot,
pushRenderLanes,
getExecutionContext,
RetryAfterError,
NoContext,
} from './ReactFiberWorkLoop.new';
import {setWorkInProgressVersion} from './ReactMutableSource.new';
import {
Expand Down Expand Up @@ -2646,14 +2643,6 @@ function updateDehydratedSuspenseComponent(
// but after we've already committed once.
warnIfHydrating();

if ((getExecutionContext() & RetryAfterError) !== NoContext) {
return retrySuspenseComponentWithoutHydrating(
current,
workInProgress,
renderLanes,
);
}

if ((workInProgress.mode & ConcurrentMode) === NoMode) {
return retrySuspenseComponentWithoutHydrating(
current,
Expand Down
11 changes: 0 additions & 11 deletions packages/react-reconciler/src/ReactFiberBeginWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,6 @@ import {
markSkippedUpdateLanes,
getWorkInProgressRoot,
pushRenderLanes,
getExecutionContext,
RetryAfterError,
NoContext,
} from './ReactFiberWorkLoop.old';
import {setWorkInProgressVersion} from './ReactMutableSource.old';
import {
Expand Down Expand Up @@ -2646,14 +2643,6 @@ function updateDehydratedSuspenseComponent(
// but after we've already committed once.
warnIfHydrating();

if ((getExecutionContext() & RetryAfterError) !== NoContext) {
return retrySuspenseComponentWithoutHydrating(
current,
workInProgress,
renderLanes,
);
}

if ((workInProgress.mode & ConcurrentMode) === NoMode) {
return retrySuspenseComponentWithoutHydrating(
current,
Expand Down
15 changes: 4 additions & 11 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,10 @@ const {

type ExecutionContext = number;

export const NoContext = /* */ 0b0000;
const BatchedContext = /* */ 0b0001;
const RenderContext = /* */ 0b0010;
const CommitContext = /* */ 0b0100;
export const RetryAfterError = /* */ 0b1000;
export const NoContext = /* */ 0b000;
const BatchedContext = /* */ 0b001;
const RenderContext = /* */ 0b010;
const CommitContext = /* */ 0b100;

type RootExitStatus = 0 | 1 | 2 | 3 | 4 | 5 | 6;
const RootInProgress = 0;
Expand Down Expand Up @@ -945,9 +944,6 @@ function performConcurrentWorkOnRoot(root, didTimeout) {
}

function recoverFromConcurrentError(root, errorRetryLanes) {
const prevExecutionContext = executionContext;
executionContext |= RetryAfterError;

// If an error occurred during hydration, discard server response and fall
// back to client side render.
if (root.isDehydrated) {
Expand All @@ -970,9 +966,6 @@ function recoverFromConcurrentError(root, errorRetryLanes) {
} else {
// The UI failed to recover.
}

executionContext = prevExecutionContext;

return exitStatus;
}

Expand Down
15 changes: 4 additions & 11 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,10 @@ const {

type ExecutionContext = number;

export const NoContext = /* */ 0b0000;
const BatchedContext = /* */ 0b0001;
const RenderContext = /* */ 0b0010;
const CommitContext = /* */ 0b0100;
export const RetryAfterError = /* */ 0b1000;
export const NoContext = /* */ 0b000;
const BatchedContext = /* */ 0b001;
const RenderContext = /* */ 0b010;
const CommitContext = /* */ 0b100;

type RootExitStatus = 0 | 1 | 2 | 3 | 4 | 5 | 6;
const RootInProgress = 0;
Expand Down Expand Up @@ -945,9 +944,6 @@ function performConcurrentWorkOnRoot(root, didTimeout) {
}

function recoverFromConcurrentError(root, errorRetryLanes) {
const prevExecutionContext = executionContext;
executionContext |= RetryAfterError;

// If an error occurred during hydration, discard server response and fall
// back to client side render.
if (root.isDehydrated) {
Expand All @@ -970,9 +966,6 @@ function recoverFromConcurrentError(root, errorRetryLanes) {
} else {
// The UI failed to recover.
}

executionContext = prevExecutionContext;

return exitStatus;
}

Expand Down