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:
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:
- malformed
text/plain against deployed routes now returns honest 400s after route hardening
- malformed
application/json returns 500s on both the custom domain and the direct generated SSR service URL
- 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
Summary
When deploying a Next.js app through Firebase Hosting framework support, malformed
application/jsonrequests can return500 Internal Server Errorfrom deployed SSR/API routes even when:400 Invalid JSON body400for the same malformed requests under plain localnext startIn 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
15.5.115.15.0firebase-frameworks: 0.11.814.2.35frameworksBackend.region = us-central1Generated SSR wrapper
From
.firebase/dinepoll/functions/server.js:Repro shape
Affected endpoints in the app:
/api/notifications/register/api/restaurant-leads/api/notifications/restaurant-replyThese routes were explicitly hardened to read raw body text and return
400 Invalid JSON bodyon JSON parse failure.Probe request
POSTContent-Type: application/json{Observed behavior
Local plain Next runtime (
next start)Host:
http://127.0.0.1:4010Observed on all three endpoints:
400Invalid JSON bodyDeployed Firebase frameworks SSR path
Hosts:
https://dinepoll.comhttps://ssrdinepoll-dm5q7suora-uc.a.run.appObserved on all three endpoints:
500Internal Server ErrorExpected behavior
Malformed
application/jsonshould return a client error such as400 Bad Request, or at minimum allow the Next route handler to surface its guarded invalid-JSON response, instead of turning the request into an upstream500before route-level validation runs.Why this seems adapter-specific
This behavior was narrowed with three controls:
text/plainagainst deployed routes now returns honest400s after route hardeningapplication/jsonreturns500s on both the custom domain and the direct generated SSR service URLapplication/jsonrequests return400s under plain localnext startThat combination suggests the deployed Firebase frameworks / SSR adapter path is handling malformed
application/jsondifferently 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:
.firebase/dinepoll/functionssource upload completesfunctions: updating Node.js 22 (2nd Gen) function firebase-frameworks-dinepoll:ssrdinepoll(us-central1)...The same stall was also observed from the local
15.5.1CLI. 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:
server.then(it => it.handle(req, res))500behavior differing from local/emulator behaviorRequested outcome
application/jsonis being parsed upstream in the deployed Firebase frameworks SSR path before Next route handlers runfirebase-frameworks/firebase-tools400instead of500functions: updating ... ssrdinepoll(us-central1)is a known frameworks deploy issue for 2nd Gen Next.js Hosting backends