-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
docs: add tip when mixing universal and server load #11822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Since modifying `data` include non-serializable POJOs (such as components) will throw an error, this change provides a hint for users not to do that.
|
@@ -216,6 +216,8 @@ export async function load({ data }) { | |||
} | |||
``` | |||
|
|||
> It's important to not modify `data` to include any non-serializable objects since it will be processed by the **server** `load` after the **universal** `load` returns. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"[...] processed by the server
load
[...]"
Is not quite right. It is just that the result of the server load gets serialized for hydration, and you can modify this result (the data
prop) in the universal load function (which runs right after the server load function and before the serialization of the server load function's result).
Maybe this bug could also be fixed if we serialize the server load function's result before running the universal load function.
@eltigerchino solicited opinions about this in the maintainers' chat, and my opinion (which I see @PatrickG also commented with above) was that we should instead serialize the server |
I just noticed #12235, which if merged would close this PR, so that one should probably be reviewed first |
Unfortunately, I couldn’t figure out how to serialise the server load data before running the universal load functions without some major refactoring. A simple fix would be to clone the server data object before passing it to the universal load but that’s not ideal. |
closing this in favour of a new issue #12236 where the solution would be as mentioned in #11822 (comment) |
Relates to #11458
data
to include non-serializable POJOs (such as components) will throw an error, this change provides a hint for users not to do that.I came across an issue on Discord where someone tried using dynamic
import()
to load a component and pass it todata
in the universal load:This threw an error along the lines of "cannot return non-serializable POJOs" since
data
was being returned by the serverload
in+page.server.js
. Hopefully my contribution to the docs helps point out this lesser-known nuance.I see this as a nice-to-have, so I'll understand if you don't wish to merge it.
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.Edits