Skip to content

Next.js Hosting frameworks SSR returns 500 for malformed application/json while local next start returns 400 #10404

@DPWonder

Description

@DPWonder

Summary

When deploying a Next.js app through Firebase Hosting framework support, malformed application/json requests can return 500 Internal Server Error from deployed SSR/API routes even when:

  • the route handlers themselves are hardened to return 400 Invalid JSON body
  • the same app returns 400 for the same malformed requests under plain local next start

In this case, the failure reproduces on both the custom domain and the direct generated SSR Cloud Run service URL, which suggests the issue is in the Firebase frameworks / deployed SSR adapter path rather than app route code or plain local Next runtime behavior.

Environment

  • firebase-tools local baseline: 15.5.1
  • firebase-tools stable lane also tested: 15.15.0
  • generated deploy bundle dependency: firebase-frameworks: 0.11.8
  • app next version: 14.2.35
  • hosting config uses framework-aware Hosting with frameworksBackend.region = us-central1

Generated SSR wrapper

From .firebase/dinepoll/functions/server.js:

const { onRequest } = require('firebase-functions/v2/https');
const server = import('firebase-frameworks');
exports.ssrdinepoll = onRequest({"region":"us-central1"}, (req, res) => server.then(it => it.handle(req, res)));

Repro shape

Affected endpoints in the app:

  • /api/notifications/register
  • /api/restaurant-leads
  • /api/notifications/restaurant-reply

These routes were explicitly hardened to read raw body text and return 400 Invalid JSON body on JSON parse failure.

Probe request

  • Method: POST
  • Header: Content-Type: application/json
  • Body: {

Observed behavior

Local plain Next runtime (next start)

Host:

  • http://127.0.0.1:4010

Observed on all three endpoints:

  • status 400
  • body contains Invalid JSON body

Deployed Firebase frameworks SSR path

Hosts:

  • https://dinepoll.com
  • https://ssrdinepoll-dm5q7suora-uc.a.run.app

Observed on all three endpoints:

  • status 500
  • body Internal Server Error

Expected behavior

Malformed application/json should return a client error such as 400 Bad Request, or at minimum allow the Next route handler to surface its guarded invalid-JSON response, instead of turning the request into an upstream 500 before route-level validation runs.

Why this seems adapter-specific

This behavior was narrowed with three controls:

  1. malformed text/plain against deployed routes now returns honest 400s after route hardening
  2. malformed application/json returns 500s on both the custom domain and the direct generated SSR service URL
  3. the exact same malformed application/json requests return 400s under plain local next start

That combination suggests the deployed Firebase frameworks / SSR adapter path is handling malformed application/json differently from both the route code and plain local Next runtime.

Additional deploy-path signal

To test whether this was only an older CLI behavior, the deploy was also retried with a pinned stable Firebase CLI lane (15.15.0).

Observed deploy sequence:

  • Next build completes
  • frameworks function packaging completes
  • .firebase/dinepoll/functions source upload completes
  • hosting file upload completes
  • deploy then stalls specifically at:
    • functions: updating Node.js 22 (2nd Gen) function firebase-frameworks-dinepoll:ssrdinepoll(us-central1)...

The same stall was also observed from the local 15.5.1 CLI. That means the deploy/update path itself is now suspect around the generated 2nd Gen function update, not just the malformed-JSON runtime behavior after deployment.

Related issues checked

Potentially related wrapper-path issues, but not this exact malformed-JSON symptom:

Requested outcome

  • confirm whether malformed application/json is being parsed upstream in the deployed Firebase frameworks SSR path before Next route handlers run
  • confirm whether this is expected behavior or a bug/regression in firebase-frameworks / firebase-tools
  • advise whether there is a current workaround for apps that need malformed JSON to fail as 400 instead of 500
  • advise whether the separate stall at functions: updating ... ssrdinepoll(us-central1) is a known frameworks deploy issue for 2nd Gen Next.js Hosting backends

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions