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

SSR broken for React-Router v7 #12249

Open
craigsmitham opened this issue Jan 1, 2025 · 1 comment
Open

SSR broken for React-Router v7 #12249

craigsmitham opened this issue Jan 1, 2025 · 1 comment

Comments

@craigsmitham
Copy link

craigsmitham commented Jan 1, 2025

Issue Description

When adding Apollo client to a react-router v7 app with SSR, the following error is encountered when handling the server side request:

Unexpected Server Error

TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is locked

Link to Reproduction

https://stackblitz.com/~/github.com/craigsmitham/react-router-apollo-client

Reproduction Steps

See stackblitz and github repo for more details.

This repro case was created by:

  1. Creating a new react-router app npx create-react-router@latest react-router-apollo-client
  2. Revealing the server entry point by running npx react-router reveal
  3. Updating revealed server entry point entry.server.tsx based on guidance for Remix in https://www.apollographql.com/blog/how-to-use-apollo-client-with-remix

To reproduce the issue, simply run npm run dev and visit dev server http://localhost:5173 and observe the following error:

Unexpected Server Error

TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is locked

More information:

This error appears to be triggered when the getDataFromTree(App) line is called: https://github.com/craigsmitham/react-router-apollo-client/blob/1cb7514b7403a456bc141ef1e5b658e1cfb13b91/app/entry.server.tsx#L44C1-L44C32

@apollo/client version

3.12.4

@phryneas
Copy link
Member

phryneas commented Jan 6, 2025

Hmm.

Generally, getDataFromTree is meant for "classic" SSR, not the new renderTo*Stream methods React provides.
Unfortunately, React itself is missing the necessary features that any data fetching library could support the modern streaming SSR out of the box without framework-specific hacks. We are talking with the React team, they are aware of the problem, but I don't expect a solution from their side soon.

In the meantime, we need to rely on framework-specific hacks, and I am currently working on a helper package for React Router 7 over here: apollographql/apollo-client-nextjs#394

I hope to get something shipped for this within the next few weeks, but we also rely on some PRs to land in React Router, so I can't give you a definitive timeline.

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

No branches or pull requests

3 participants