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

TypeError: ReactDOMServer.renderToReadableStream is not a function #4608

Closed
1 task done
laymonage opened this issue Dec 15, 2024 · 8 comments · Fixed by #4678
Closed
1 task done

TypeError: ReactDOMServer.renderToReadableStream is not a function #4608

laymonage opened this issue Dec 15, 2024 · 8 comments · Fixed by #4678
Labels

Comments

@laymonage
Copy link

  • Check if updating to the latest Preact version resolves the issue

Describe the bug

Hi! I'm trying to update https://github.com/giscus/giscus to the latest Preact version (10.25.2) and I got a TypeError: ReactDOMServer.renderToReadableStream is not a function when I try to load any page. Not sure how helpful it is, but here's the stack trace:

Stack trace
Server Error
TypeError: ReactDOMServer.renderToReadableStream is not a function

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
Object.renderToInitialStream
file:///Users/sage/Code/git/github/giscus/giscus/node_modules/next/dist/server/node-web-streams-helper.js (123:27)
renderShell
file:///Users/sage/Code/git/github/giscus/giscus/node_modules/next/dist/server/render.js (755:57)
Object.renderPage
file:///Users/sage/Code/git/github/giscus/giscus/node_modules/next/dist/server/render.js (671:28)
Object.defaultGetInitialProps
file:///Users/sage/Code/git/github/giscus/giscus/node_modules/next/dist/server/render.js (350:67)
CustomDocument.getInitialProps
node_modules/next/dist/pages/_document.js (19:19)
Object.<anonymous>
file:///Users/sage/Code/git/github/giscus/giscus/node_modules/next/dist/shared/lib/utils.js (75:33)
Generator.next
<anonymous>
asyncGeneratorStep
file:///Users/sage/Code/git/github/giscus/giscus/node_modules/@swc/helpers/lib/_async_to_generator.js (23:28)
_next
file:///Users/sage/Code/git/github/giscus/giscus/node_modules/@swc/helpers/lib/_async_to_generator.js (12:17)
<unknown>
file:///Users/sage/Code/git/github/giscus/giscus/node_modules/@swc/helpers/lib/_async_to_generator.js (17:13)

To Reproduce

Honestly, it's probably my fault for still using Next.js that no longer supports Preact. I'm on Next.js 12.3.4 and next-plugin-preact 3.0.7, as those are the last versions that still work together.

I should probably either move on from Next.js or Preact, but I thought this could possibly a legit bug in Preact, so I'm raising this anyway. Feel free to close this if whatever caused this was intended.

For the record, this still worked fine in 10.23.2. Trying the versions between that and the latest 10.25.2, I found that it started to break in 10.24.0. I couldn't find anything in the release notes that could be related. The closest is probably #4490, but I'm not sure why a warning would cause it to crash.

Expected behavior

I expect it to work just fine, like in 10.23.2.

@JoviDeCroock
Copy link
Member

10.24.0 hasn't changed anything relating to exports https://github.com/preactjs/preact/releases/tag/10.24.0. We've also never had that export so maybe something else got upgraded?

@laymonage
Copy link
Author

I thought it might've been the case, but giscus/giscus#1576 shows that it is preact 10.24.0 (only) that caused the build to fail 😔

All the other packages (except Next.js ones) updated without issue giscus/giscus#1574.

@JoviDeCroock
Copy link
Member

That's very odd, we've never had that export in https://github.com/preactjs/preact/blob/main/compat/server.mjs#L11-L15 - kind of confused how that's possible, maybe because we updated the fake compat version Next thinks it can start leveraging the stream #4488

@rschristian
Copy link
Member

rschristian commented Dec 15, 2024

Indeed, Next sniffs out the React version and alters behavior (rather considerably) for 18.0+.

Any reason to avoid re-exporting it? Next may or may not work well with it of course, but that's a separate issue.

@JoviDeCroock
Copy link
Member

I am personally not confident in our streaming implementation atm as it's not battle tested so our issue counter might explode if we do 😅

@adhirajsinghchauhan
Copy link

Well, faking compat version might've fixed that other issue, but it's the culprit for this one. IMO it should be reverted, because updating Preact to a newer minor version should not be a breaking change, when all else is equal. #4441 is a peer dep thing that can probably be silenced on the user's end (?).

Anyway, we "solved" this issue by monkeypatching next/dist/server/utils.js:

sed -i -E "s|(const shouldUseReactRoot) = .+?;|\1 = false;|" ./node_modules/next/dist/server/utils.js

I recall performing a similar hack before preactjs/compat-alias-package#6 landed; in both cases NextJS' shouldUseReactRoot was the annoyance.

@rschristian
Copy link
Member

Unfortunately we can't do much about external packages that use version to determine feature availability, that's outside our control & what semver is meant to protect.

I'd be in favor of making renderToReadableStream available, letting bug reports come in as they may, but that might cause issues & force people to remain on older versions while we mature our implementation.

@JoviDeCroock
Copy link
Member

Yes, let's make the readableStream export available. That being said, next in general isn't officially supported as they made it pretty clear they don't want to collaborate on supporting preact. We supported next for a long time and did our very best to keep up with the changes but it's impossible as they dug through bundler internals a lot.

From that point of view I would not consider this a breaking change as it's a hack (stubbing the version) observed by another hack.

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

Successfully merging a pull request may close this issue.

4 participants