Skip to content

Unleash Next.js Integration Issue - "body has already been consumed" Error in Server Components #105

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

Open
ValerieEvans opened this issue Feb 27, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@ValerieEvans
Copy link

ValerieEvans commented Feb 27, 2025

Bug Report: Unleash Next.js Integration Issue - "body has already been consumed" Error in Server Components

Environment Details

  • @unleash/nextjs: 1.4.4
  • Next.js: 14.2.7
  • React: 18.2.0
  • TypeScript: 5.4.5
  • Deployment Platform: Vercel

Questions for the Unleash Team

  1. Is version 1.4.4 of @unleash/nextjs fully compatible with Next.js 14's server components?
  2. Are there known issues with body consumption in server component contexts?
  3. Are there recommended patterns for using Unleash with Next.js 14 server components?

Steps to reproduce the bug

  1. Set up a Next.js 14 project with App Router and Server Components
  2. Integrate @unleash/nextjs version 1.4.4
  3. Implement feature flag checking in a server component
  4. Attempt to render the component with feature flag validation
  5. Deploy the project to Vercel

Expected behavior

  • The server should successfully check feature flags during server-side rendering
  • The component should render without any body consumption errors
  • Feature flags should be evaluated correctly

Actual Behaviour :

  • Server throws "body has already been consumed" error
  • The error appears to be related to how request bodies are handled during server-side rendering
  • Possible performance issues or race conditions with Unleash flag evaluation

Logs, error output, etc.

Error checking feature access: TypeError: Response.clone: Body has already been consumed.
    at webidl.errors.exception (node:internal/deps/undici/undici:3384:14)
    at _Response.clone (node:internal/deps/undici/undici:8883:31)
    at /var/task/node_modules/.pnpm/next@14.2.7_@babel+core@7.25.2_@opentelemetry+api@1.9.0_@playwright+test@1.48.1_react-dom@18._s6i3mmeecyghkm4uajs4djv4gi/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:181023

Error: Error checking feature access: TypeError: Response.clone: Body has already been consumed.
    at i (/var/task/apps/core-web/.next/server/app/[locale]/copilots/create/page.js:1:6334)
    at async /var/task/apps/core-web/.next/server/app/[locale]/copilots/settings/official/page.js:1:3502

Screenshots

No response

Additional context

No response

Unleash version

1.4.4

Subscription type

Open source

Hosting type

Self-hosted

SDK information (language and version)

No response

@ValerieEvans ValerieEvans added the bug Something isn't working label Feb 27, 2025
@chriswk chriswk transferred this issue from Unleash/unleash Feb 28, 2025
@FredrikOseberg FredrikOseberg moved this from New to Investigating in Issues and PRs Mar 4, 2025
@FredrikOseberg FredrikOseberg self-assigned this Mar 4, 2025
@FredrikOseberg
Copy link
Contributor

@ValerieEvans

Thanks for this report. Can you please provide a small reproducible example so we can easily check this out and debug the issue? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Investigating
Development

No branches or pull requests

2 participants