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

Impossible to Server-Render Client Components in API Routes #68150

Open
Titou325 opened this issue Jul 25, 2024 · 0 comments
Open

Impossible to Server-Render Client Components in API Routes #68150

Titou325 opened this issue Jul 25, 2024 · 0 comments
Labels
bug Issue was opened via the bug report template.

Comments

@Titou325
Copy link

Titou325 commented Jul 25, 2024

Link to the code that reproduces this issue

https://github.com/Titou325/dev-next-ssr

To Reproduce

  1. Start the application
  2. Go to http://localhost:3000/api
  3. The server errors with 500

Current vs. Expected behavior

It seems that it is not possible to render "use client" components from API routes. We need to do this to create emails and documents that get sent to a third party.

In basic React, we can just render to readableStream and get the static HTML even for a "use client" component. However, this doesn't seem to work with Next.js, as the component seems to be passed as an empty object.

Server components work fine.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.6.0: Thu Jun 20 00:25:05 PDT 2024; root:xnu-10063.140.29.0.1~15/RELEASE_ARM64_T6020
  Available memory (MB): 32768
  Available CPU cores: 12
Binaries:
  Node: 20.12.2
  npm: 10.8.0
  Yarn: 1.22.17
  pnpm: 7.14.1
Relevant Packages:
  next: 15.0.0-canary.83 // Latest available version is detected (15.0.0-canary.83).
  eslint-config-next: 14.2.4
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.5.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

next dev (local), next build (local), Vercel (Deployed)

Additional context

I have upgraded to Next canary but still encounter the same discrepancy, with either the react-dom APIs being patched by Next or the component being pre-processed.

While this demo shows something that could be achieved by a page directly, the idea is that we take the HTML string and send it to a third party (in our case fileforge.com)

@Titou325 Titou325 added the bug Issue was opened via the bug report template. label Jul 25, 2024
@Titou325 Titou325 changed the title Impossible to Server-Render Client Components Outside in Routes Impossible to Server-Render Client Components in API Routes Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

1 participant