Skip to content

Commit d8a76ad

Browse files
authored
Allow Suspense Mismatch on the Client to Silently Proceed (#16943)
* Regression test: Suspense + hydration + legacy * Allow Suspense Mismatch on the Client to Silently Proceed This fixes but isn't actually the semantics that we want this case to have.
1 parent 9d63784 commit d8a76ad

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,4 +659,15 @@ describe('ReactDOMServerHydration', () => {
659659

660660
document.body.removeChild(parentContainer);
661661
});
662+
663+
it('regression test: Suspense + hydration in legacy mode ', () => {
664+
const element = document.createElement('div');
665+
element.innerHTML = '<div>Hello World</div>';
666+
ReactDOM.hydrate(
667+
<React.Suspense>
668+
<div>Hello World</div>
669+
</React.Suspense>,
670+
element,
671+
);
672+
});
662673
});

packages/react-reconciler/src/ReactFiberHydrationContext.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,10 @@ function skipPastDehydratedSuspenseInstance(
404404
let suspenseState: null | SuspenseState = fiber.memoizedState;
405405
let suspenseInstance: null | SuspenseInstance =
406406
suspenseState !== null ? suspenseState.dehydrated : null;
407-
invariant(
408-
suspenseInstance,
409-
'Expected to have a hydrated suspense instance. ' +
410-
'This error is likely caused by a bug in React. Please file an issue.',
411-
);
407+
if (suspenseInstance === null) {
408+
// This Suspense boundary was hydrated without a match.
409+
return nextHydratableInstance;
410+
}
412411
return getNextHydratableInstanceAfterSuspenseInstance(suspenseInstance);
413412
}
414413

0 commit comments

Comments
 (0)