Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/blue-dots-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/start": patch
---

Fixed an issue where runtimes like AWS Lambda would default to `application/json` when no header was present, causing parsing errors in `json` serialization mode. To ensure consistent behavior, the `Content-Type` is now explicitly set to `text/plain`.
8 changes: 8 additions & 0 deletions packages/start/src/runtime/server-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ async function handleServerFunction(h3Event: HTTPEvent) {
setHeader(h3Event, "content-type", "text/javascript");
return serializeToJSStream(instance, result);
}
// Explicitly set the Content-Type to avoid runtimes (e.g., AWS Lambda)
// that default to `application/json`, which can break serialization
// when the SEROVAL output is not valid JSON.
setHeader(h3Event, "content-type", "text/plain");
return serializeToJSONStream(result);
} catch (x) {
if (x instanceof Response) {
Expand Down Expand Up @@ -181,6 +185,10 @@ async function handleServerFunction(h3Event: HTTPEvent) {
setHeader(h3Event, "content-type", "text/javascript");
return serializeToJSStream(instance, x);
}
// Explicitly set the Content-Type to avoid runtimes (e.g., AWS Lambda)
// that default to `application/json`, which can break serialization
// when the SEROVAL output is not valid JSON.
setHeader(h3Event, "content-type", "text/plain");
return serializeToJSONStream(x);
}
return x;
Expand Down
10 changes: 5 additions & 5 deletions packages/start/src/runtime/server-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ async function fetchServerFunction(
const contentType = response.headers.get("Content-Type");
const cloned = response.clone();
let result;
if (contentType && contentType.startsWith("text/plain")) {
Comment thread
yinonburgansky marked this conversation as resolved.
result = await cloned.text();
} else if (contentType && contentType.startsWith("application/json")) {
result = await cloned.json();
} else if (response.headers.get("x-serialized")) {
if (response.headers.get("x-serialized")) {
if (import.meta.env.SEROVAL_MODE === "js") {
result = await deserializeJSStream(instance, cloned);
} else {
result = await deserializeJSONStream(cloned);
}
} else if (contentType && contentType.startsWith("text/plain")) {
result = await cloned.text();
} else if (contentType && contentType.startsWith("application/json")) {
result = await cloned.json();
}
if (response.headers.has("X-Error")) {
throw result;
Expand Down
Loading