Skip to content

Conversation

@teemingc
Copy link
Member

@teemingc teemingc commented May 19, 2024

fixes #12236

A refactor attempt to serialize the server data before it's passed to the universal load functions.

I'm sure I haven't implemented this correctly:
1. I don't think it's correct to await all the server loads, to serialize the server data, and only then run the universal load functions (might slow down when they start and finish).
1. I also don't like the code duplication shared between rendering the page and error (and whatever needs to serialise server code in the future).

Maybe someone can take a better shot at this.

EDIT: decided on shallow cloning the server data (see #12235 (comment))


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot
Copy link

changeset-bot bot commented May 19, 2024

🦋 Changeset detected

Latest commit: d37f5f5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@teemingc
Copy link
Member Author

teemingc commented Oct 16, 2024

I think the simplest fix for this is to shallow clone the object because:

  1. serialising the server data earlier requires awaiting all the server loads and it also messes up the timing of the chunk streaming (causes one of the tests to fail).
  2. deep cloning the server data causes errors if there's a promise that's returned by the server load.

@teemingc teemingc requested a review from Conduitry October 16, 2024 06:14
@teemingc teemingc changed the title fix: serialize server data before running universal load on server fix: clone server data before running universal load on server Oct 16, 2024
@dummdidumm
Copy link
Member

Thanks for the exploration, but I'm closing this (for now, we can always reopen later) for the reasons given in #12236 (comment)

@dummdidumm dummdidumm closed this Jan 16, 2025
@dummdidumm dummdidumm deleted the serialize-server-data-earlier branch January 16, 2025 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants