-
Notifications
You must be signed in to change notification settings - Fork 345
add docs about serialization modes #1436
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
Merged
+137
−18
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7ffe317
add docs about serialization modes
atilafassina b7e218a
Merge branch 'main' into serialization/docs
kodiakhq[bot] 0193dd5
Merge branch 'main' into serialization/docs
kodiakhq[bot] 8cd5b3e
Merge branch 'main' into serialization/docs
kodiakhq[bot] 2e29c72
Merge branch 'main' into serialization/docs
kodiakhq[bot] fc9066f
Update src/routes/solid-start/reference/config/define-config.mdx
atilafassina 28e05cf
Update src/routes/solid-start/guides/security.mdx
atilafassina 9d7faa6
Update src/routes/solid-start/reference/server/use-server.mdx
atilafassina 75d802c
Update src/routes/solid-start/guides/security.mdx
atilafassina 193015e
add new serialization section
atilafassina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| --- | ||
| title: Serialization | ||
| use_cases: >- | ||
| server function payloads, data transfer, csp, security, performance | ||
| tags: | ||
| - serialization | ||
| - server-functions | ||
| - csp | ||
| - security | ||
| - performance | ||
| version: "1.0" | ||
| description: >- | ||
| Understand how SolidStart serializes server function payloads, supported | ||
| types, and CSP tradeoffs. | ||
| --- | ||
|
|
||
| SolidStart serializes server function arguments and return values so they can travel between server and client. It uses Seroval under the hood and streams payloads to keep responses responsive. | ||
|
|
||
| ## Configuration | ||
|
|
||
| Configure serialization in your `app.config.ts` with `defineConfig`: | ||
|
|
||
| ```tsx tab title="v1" | ||
| import { defineConfig } from "@solidjs/start/config"; | ||
|
|
||
| export default defineConfig({ | ||
| serialization: { | ||
| mode: "js", | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| ```tsx tab title="v2" | ||
| import { defineConfig } from "vite"; | ||
| import { solidStart } from "@solidjs/start"; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [ | ||
| solidStart({ | ||
| serialization: { | ||
| mode: "json", | ||
| }, | ||
| }), | ||
| ], | ||
| }); | ||
| ``` | ||
|
|
||
| See the full config reference in [`defineConfig`](/solid-start/reference/config/define-config#serialization). | ||
|
|
||
| ## Modes | ||
|
|
||
| - `json`: Uses `JSON.parse` on the client. Best for strict CSP because it avoids `eval`. Payloads can be slightly larger. | ||
| - `js`: Uses Seroval's JS serializer for smaller payloads and better performance, but it requires `unsafe-eval` in CSP. | ||
|
|
||
| :::caution[v2 Breaking Change: Defaults] | ||
| SolidStart v1 defaults to `js` for backwards compatibility. SolidStart v2 defaults to `json` for CSP compatibility. | ||
| ::: | ||
|
|
||
| ## Supported types (default) | ||
|
|
||
| SolidStart enables Seroval plus a default set of web platform plugins. These plugins add support for: | ||
|
|
||
| - `AbortSignal`, `CustomEvent`, `DOMException`, `Event` | ||
| - `FormData`, `Headers`, `ReadableStream` | ||
| - `Request`, `Response` | ||
| - `URL`, `URLSearchParams` | ||
|
|
||
| Seroval supports additional value types. The compatibility list is broader than what SolidStart enables by default, so treat it as a superset. See the [Seroval compatibility docs](http://github.com/lxsmnsyc/seroval/blob/main/docs/COMPATIBILITY.md). | ||
|
|
||
| ## Limits and exclusions | ||
|
|
||
| - `RegExp` is disabled by default. | ||
| - JSON mode enforces a maximum serialization depth of 64. If you exceed this, flatten the structure or return a simpler payload. | ||
|
|
||
| ## Related guidance | ||
|
|
||
| - Configure modes and defaults in [`defineConfig`](/solid-start/reference/config/define-config#serialization). | ||
| - CSP implications and nonce examples live in the [Security guide](/solid-start/guides/security#content-security-policy-csp). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.