Skip to content

Commit ac0a87e

Browse files
authored
docs: Improve transport hook docs (#13996)
1 parent 3386f3c commit ac0a87e

File tree

3 files changed

+7
-3
lines changed
  • documentation/docs/20-core-concepts
  • packages/kit

3 files changed

+7
-3
lines changed

documentation/docs/20-core-concepts/20-load.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ Universal `load` functions are called with a `LoadEvent`, which has a `data` pro
206206

207207
A universal `load` function can return an object containing any values, including things like custom classes and component constructors.
208208

209-
A server `load` function must return data that can be serialized with [devalue](https://github.com/rich-harris/devalue) — anything that can be represented as JSON plus things like `BigInt`, `Date`, `Map`, `Set` and `RegExp`, or repeated/cyclical references — so that it can be transported over the network. Your data can include [promises](#Streaming-with-promises), in which case it will be streamed to browsers.
209+
A server `load` function must return data that can be serialized with [devalue](https://github.com/rich-harris/devalue) — anything that can be represented as JSON plus things like `BigInt`, `Date`, `Map`, `Set` and `RegExp`, or repeated/cyclical references — so that it can be transported over the network. Your data can include [promises](#Streaming-with-promises), in which case it will be streamed to browsers. If you need to serialize/deserialize custom types, use [transport hooks](https://svelte.dev/docs/kit/hooks#Universal-hooks-transport).
210210

211211
### When to use which
212212

packages/kit/src/runtime/server/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ export function redirect_response(status, location) {
133133
*/
134134
export function clarify_devalue_error(event, error) {
135135
if (error.path) {
136-
return `Data returned from \`load\` while rendering ${event.route.id} is not serializable: ${error.message} (${error.path})`;
136+
return (
137+
`Data returned from \`load\` while rendering ${event.route.id} is not serializable: ${error.message} (${error.path}). ` +
138+
`If you need to serialize/deserialize custom types, use transport hooks: https://svelte.dev/docs/kit/hooks#Universal-hooks-transport.`
139+
);
137140
}
138141

139142
if (error.path === '') {

packages/kit/test/apps/basics/test/cross-platform/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ test.describe('Shadowed pages', () => {
220220

221221
expect(await page.textContent('h1')).toBe('500');
222222
expect(await page.textContent('#message')).toBe(
223-
'This is your custom error page saying: "Data returned from `load` while rendering /shadowed/serialization is not serializable: Cannot stringify arbitrary non-POJOs (data.nope) (500 Internal Error)"'
223+
'This is your custom error page saying: "Data returned from `load` while rendering /shadowed/serialization is not serializable: Cannot stringify arbitrary non-POJOs (data.nope).' +
224+
' If you need to serialize/deserialize custom types, use transport hooks: https://svelte.dev/docs/kit/hooks#Universal-hooks-transport. (500 Internal Error)"'
224225
);
225226
});
226227
}

0 commit comments

Comments
 (0)