-
-
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
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.
|
| } | ||
| ``` | ||
|
|
||
| > 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) |
|
closing in favour of #14268 — thanks |
Relates to #11458
datato 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 todatain the universal load:This threw an error along the lines of "cannot return non-serializable POJOs" since
datawas being returned by the serverloadin+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 testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits