-
Notifications
You must be signed in to change notification settings - Fork 49.9k
Closed as not planned
Description
React 19 Beta: Component Suspense Not Fallbacking as Expected
I'm experiencing an issue with the Suspense feature in React 19 beta. The fallback component is not rendering when the child component is in a suspended state, leading to a blank screen instead of the intended loading indicator.
Steps to Reproduce:
- Create a simple component that fetches data asynchronously.
- Wrap the component with
<Suspense fallback={<Loading />} />. - Trigger the fetch operation that causes the component to suspend.
- Observe that the fallback is not displayed, and the screen remains blank.
Expected Behavior:
I expected the <Loading /> component to display while the data is being fetched.
Actual Behavior:
The screen remains blank instead of showing the fallback component.
Code Snippet:
App
import React, { Suspense } from "react";
import Loading from "./components/Loading";
import TestComponent from "./components/TestComponent";
const App = () => {
return (
<Suspense fallback={<Loading />}>
<TestComponent />
</Suspense>
);
};
export default App;TestComponent
import React, { useState, useEffect } from "react";
const TestComponent = () => {
const [data, setData] = useState(null);
// Simulate data fetching
useEffect(() => {
const fetchData = async () => {
const response = await fetch("https://fakestoreapi.com/users");
const result = await response.json();
setData(result);
};
fetchData();
}, []);
if (!data) {
throw new Promise(() => {}); // Intentionally suspends the component
}
return <div>Data: {data}</div>;
};
export default TestComponent;Loading Component
import React from "react";
import "./Loading.css"; // Import the CSS file for styles
const Loading = () => {
return (
<div className="loading-container">
<h1 className="loading-title">Loading...</h1>
<div className="spinner"></div>
<h2 className="loading-subtitle">Please wait JasGiigli</h2>
</div>
);
};
export default Loading;Environment
- React Version: 19 beta
- Node Version: v22.8.0
- Operating System: Windows 10
- Browser:Google Chrome Version 129.0.6668.90 (Official Build) (64-bit)
Additional Context
I have tested this issue with the latest React 19 beta. It seems that the fallback component is not being activated as expected during the data fetching process. Please let me know if you need any further details or if there are specific scenarios you'd like me to test.
Thank you for your attention to this issue.