Skip to content

mutating the data prop in a universal load affects the data returned from a server load #12236

Open
@eltigerchino

Description

@eltigerchino

Describe the bug

I came across an issue on Discord where someone tried using dynamic import() to load a component and pass it to data in the universal load:

export async function load({ data }) {
  data.component = (await import('$lib/components/Button.svelte')).default
  return data
  //     ^ error
}

This threw an error along the lines of "cannot return non-serializable POJOs" since data was being returned by the server load in +page.server.js. Hopefully my contribution to the docs helps point out this lesser-known nuance.

#11822 (comment)

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-qnnygo?file=src%2Froutes%2F%2Bpage.js

Logs

No response

System Info

StackBlitz

Severity

annoyance

Additional Information

We could:

  1. Keep the current behaviour where data is mutated.
  2. Prevent mutations of data from affecting the serialization of the server load data.
  3. Throw an error telling users not to mutate data.

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