Skip to content

React Suspense components wrapped in Provider emit runtime errors when using SSR #6728

@russell-mckenzie

Description

@russell-mckenzie

Provide a general summary of the issue here

We've encountered an unexpected runtime error while attempting to server-side render <Suspense> lazy-loaded components using Next.js.

🤔 Expected Behavior?

When using a React <Suspense> component inside a <Provider>, there should be no runtime error emitted and the boundary should not switch to client rendering.

😯 Current Behavior

The browser displays the following error message when the <Suspense> component is rendered.

Error: This Suspense boundary received an update before it finished hydrating. This caused the boundary to switch to client rendering. The usual way to fix this is to wrap the original update in startTransition.

We receive this error consistently if the <Suspense> component is mounted inside a React Spectrum 3 <Provider> irrespective of the prop values provided.

💁 Possible Solution

My theory is that this is related to hooks like useMediaQuery() which are used in the Provider and implicitly cause an update client-side after or during hydration (but I'm not an expert here).

🔦 Context

No response

🖥️ Steps to Reproduce

I've prepared a minimal CodeSandbox to demonstrate the error: CodeSandbox Devbox. This sandbox has Next.js 14, with React Spectrum 3.35.1 and the next.config.js changes advised to enable CSS bundling with Next.js.

Simply open the Sandbox and navigate to /test (if not already displayed).

Version

3.35.1

What browsers are you seeing the problem on?

Firefox, Chrome, Safari, Microsoft Edge

If other, please specify.

No response

What operating system are you using?

macOS Sonoma

🧢 Your Company/Team

Adobe/Business Essentials

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions