这是indexloc提供的服务,不要输入任何密码
Skip to content

Bug: [React 19] Suspense fallback with periodic state updates causes suspense children with slow render functions to never show #33939

@yiding

Description

@yiding

React version: 19.1.0

Steps To Reproduce

  1. Go to the example project.
  2. Tweak the compute iterations (simulating a slow render function) to a sufficiently large number.

Link to code example: https://stackblitz.com/edit/react-mwegmaqm?file=App.jsx

Reproduced here:

import React, { useState, useEffect, use } from 'react';

const LOADING_UPDATE_INTERVAL = 10;

// Setting this value to a large number such that slowCompute() takes longer than the LOADING_UPDATE_INTERVAL means that the suspense will always show the fallback.
const DELAY_ITERS = 200_000;
function slowCompute() {
  for (let i = 0; i < DELAY_ITERS; i++) crypto.randomUUID();
}

// A loading fallback that updates itself, for example to display some cute loading messages.
function Loading() {
  const [count, setCount] = useState(0);
  useEffect(() => {
    const interval = setInterval(() => {
      setCount((prev) => prev + 1);
    }, LOADING_UPDATE_INTERVAL);
    return () => clearInterval(interval);
  }, []);
  return <>Waiting for {count} </>;
}

// The child that renders slowly, in practice this might be a large data table.
function SlowThing(props) {
  const v = use(props.promise);
  slowCompute();
  return <>Loaded</>;
}

const App = () => {
  const promise = new Promise((resolve, reject) => {
    setTimeout(() => {
      resolve('yay');
    }, 100);
  });

  return (
    <React.Suspense fallback={<Loading />}>
      <SlowThing promise={promise} />
    </React.Suspense>
  );
};

export default App;

The current behavior

The fallback will be displayed indefinitely, while the actual component rerender gets triggered over and over again.

The expected behavior

The actual component is displayed eventually.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions