React: Bug: SuspenseList revealOrder="together" and error boundaries

Created on 29 Mar 2020  路  4Comments  路  Source: facebook/react

React version: 0.0.0-experimental-aae83a4b9

Steps To Reproduce

  1. Wrap and error boundary around a suspense boundary inside a <SuspenseList revealOrder="together" />
  2. Crash with Cannot read property 'shared' of null

Link to code example:

https://codesandbox.io/s/quirky-cannon-e4t1c is forked from https://codesandbox.io/s/black-wind-byilt

The current behavior

The following code causes the described crash:

<SuspenseList revealOrder="together">
  <ErrorBoundary fallback={null}>
    <Suspense fallback={<h2>Loading posts...</h2>}>
      <ProfileTimeline resource={resource} />
    </Suspense>
  </ErrorBoundary>
  <Suspense fallback={<h2>Loading fun facts...</h2>}>
    <ProfileTrivia resource={resource} />
  </Suspense>
</SuspenseList>

revealOrder="forwards" does not crash as well as placing the error boundary inside the suspense boundary like so:

<SuspenseList revealOrder="together">
  <Suspense fallback={<h2>Loading posts...</h2>}>
    <ErrorBoundary fallback={null}>
      <ProfileTimeline resource={resource} />
    </ErrorBoundary>
  </Suspense>
  <Suspense fallback={<h2>Loading fun facts...</h2>}>
    <ProfileTrivia resource={resource} />
  </Suspense>
</SuspenseList>

The expected behavior

The position of the ErrorBoundary is likely wrong in the first place (since I can move it around to not cause a crash while preserving the semantics I expect). Maybe this needs a descriptive warning/error why this is happening and how I should resolve it?

Suspense Bug

Most helpful comment

Would you mind sending this as a PR with a failing test? You can see existing SuspenseList tests as an inspiration.

All 4 comments

Sounds like a bug.

Would you mind sending this as a PR with a failing test? You can see existing SuspenseList tests as an inspiration.

Added test in https://github.com/facebook/react/pull/18432

This is reproducible with a basic class component which means the assumption in
https://github.com/facebook/react/blob/c5d2fc7127654e43de59fff865b74765a103c4a5/packages/react-reconciler/src/ReactUpdateQueue.js#L399-L401

does not hold. This guard was removed in https://github.com/facebook/react/commit/7bf40e1cfdb780788700a41bf30163fdb8d105a3#diff-b69c8f2165f95ef2355ac661c12fa407L867

Closed in #18448

Was this page helpful?
0 / 5 - 0 ratings