Skip to content

transport hooks did not encode falsy value #13847

@ariaandika

Description

@ariaandika

Describe the bug

Despite the docs says that encode should return false for anything that isn’t an instance of the type, returning falsy value, including 0, will not encode the type.

From sveltekit docs:

Each transporter contains an encode function, which encodes values on the server (or returns false for anything that isn’t an instance of the type) and a corresponding decode function

Reproduction

https://github.com/ariaandika/sveltekit-transport-falsy-reproduce

Logs

Error: Data returned from `load` while rendering / is not serializable: Cannot stringify arbitrary non-POJOs (data.role)

System Info

System:
    OS: Linux 6.14 Arch Linux
    CPU: (4) x64 AMD Ryzen 3 3250U with Radeon Graphics
    Memory: 792.28 MB / 5.73 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 23.11.1 - /usr/bin/node
    npm: 11.4.1 - /usr/bin/npm
    bun: 1.2.13 - ~/.bun/bin/bun
  npmPackages:
    @sveltejs/adapter-auto: ^6.0.0 => 6.0.1
    @sveltejs/kit: ^2.16.0 => 2.21.1
    @sveltejs/vite-plugin-svelte: ^5.0.0 => 5.0.3
    svelte: ^5.0.0 => 5.33.11
    vite: ^6.2.6 => 6.3.5

Severity

annoyance

Additional Information

Is the transport hooks is only intended for custom nested types like object and array ? Is there a way to represent a class that is a wrapper for primitive flat type ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions