Skip to content

Enforce that endpoint responses can be serialized #4944

@paperclover

Description

@paperclover

Describe the bug

When using page endpoints, the JSON output of the request isn't serialized before passing it to the component/load(), causing the SSR version of these pages to be different than the client rendered version. To extend this, you can pass any value through the endpoint, including functions and classes (these ones wont pass type checking), and it will be passed as props to the ssr component.

Reproduction

Repo: https://github.com/davecaruso/bug-sveltekit-tojson-endpoints

Logs

[no relevant logs]

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (32) x64 AMD Ryzen 9 5950X 16-Core Processor
    Memory: 41.17 GB / 63.90 GB
  Binaries:
    Node: 17.8.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.5.5 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (101.0.1210.47)
    Internet Explorer: 11.0.22000.120
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.42 
    @sveltejs/kit: next => 1.0.0-next.330 
    svelte: ^3.44.0 => 3.48.0

Severity

annoyance

Additional Information

I believe the part of the code that has to be changed is here
https://github.com/sveltejs/kit/blob/master/packages/kit/src/runtime/server/page/load_node.js#L520
as body is just passed through. it should either be passed through JSON.stringify or some helper function to flatten all objects with .toJSON

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature / enhancementNew feature or requestp1-importantSvelteKit cannot be used by a large number of people, basic functionality is missing, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions