Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: hydration fails when using Promise values with React Server Components #27247

Closed
lazarv opened this issue Aug 18, 2023 · 5 comments
Closed
Labels

Comments

@lazarv
Copy link

lazarv commented Aug 18, 2023

React version: [email protected]

Steps To Reproduce

  1. use inlined Promise values in JSX
  2. hydration fails

Link to code example: https://stackblitz.com/edit/stackblitz-starters-u9soom?file=app%2Fpage.jsx

The current behavior

While rendering of HTML is correct and HTML and flight response seems to be ok, hydration fails.
Maybe the issue correlates with ordering and timing replacing of suspended fragments in the DOM tree and processing the flight response for hydration.

The expected behavior

React tree gets hydrated correctly.

@lazarv lazarv added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Aug 18, 2023
@sophiebits
Copy link
Collaborator

@gnoff Thoughts? The code looks legit to me at a glance.

@lazarv
Copy link
Author

lazarv commented Nov 7, 2023

Thanks for checking this out @sophiebits!

This might be a super edge-case, but is it not concerning to have an issue like this in React core? First I thought I implemented SSR in my experimental meta-framework wrong, then I counter checked it with next.js and while the React versions were roughly the same, this is still reproducible with next.js 13.5+.

Is there anything not supported by React in the example, that should be avoided? If the AsyncComponent is changed to be a non-async function and promises are wrapped in use() this works, but that changes how is this getting rendered as Promise values are no longer references, but primitive values as children.

I updated the example to include both use case.

Copy link

github-actions bot commented Apr 7, 2024

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Apr 7, 2024
@eps1lon eps1lon added React 19 and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug Resolution: Stale Automatically closed due to inactivity labels Apr 7, 2024
@eps1lon
Copy link
Collaborator

eps1lon commented Apr 7, 2024

Also reproduces with just

import { Suspense } from 'react';

const child1 = new Promise((resolve) =>
  setTimeout(() => resolve('Lorem ipsum 111...'), 100)
);

async function AsyncComponent() {
  return <div>{child1}</div>;
}

export default function App() {
  return (
    <Suspense fallback={null}>
      <AsyncComponent />
    </Suspense>
  );
}

-- https://stackblitz.com/edit/stackblitz-starters-ssafqw?file=app%2Ferror%2Fpage.jsx,app%2Fok%2Fpage.jsx

Need to double check if promise-as-a-child support is complete or if we should warn.

@eps1lon
Copy link
Collaborator

eps1lon commented Apr 7, 2024

I can repro this in our Flight fixture when I checkout the React version that's used by this specific Next.js. However, on main this no longer reproduces in our fixtures since it was fixed in #28284

Closing this in favor of vercel/next.js#56470 to figure out which React version we need in Next.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants