Skip to content
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

[docs] clarify and add warning for load function #1807

Merged
merged 8 commits into from
Aug 1, 2021
Merged

[docs] clarify and add warning for load function #1807

merged 8 commits into from
Aug 1, 2021

Conversation

ignatiusmb
Copy link
Member

Closes #1542

@changeset-bot
Copy link

changeset-bot bot commented Jul 2, 2021

⚠️ No Changeset found

Latest commit: 214460b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@benmccann benmccann added the documentation Improvements or additions to documentation label Jul 3, 2021
documentation/docs/03-loading.md Outdated Show resolved Hide resolved
documentation/docs/03-loading.md Outdated Show resolved Hide resolved
@benmccann
Copy link
Member

I'm not sure any of this is particular to load, which makes it seem a bit odd to me to put it there. E.g. it's also true for endpoints that if you mutate a singleton that it will persist across calls. And sometimes you actually want to do that - it's how we recommend you setup a database https://kit.svelte.dev/faq#integrations

@ignatiusmb
Copy link
Member Author

That's true, but most of the problems occurs in load function and since we're writing it in the #loading section, I think it should be pretty clear that the warning only applies to mutations while loading. Endpoints are a different thing (and context) since they can only run in the server and never in client.

@ignatiusmb
Copy link
Member Author

I think this is really a common pitfall like what #1542 (comment) says, especially for users using plain SPA Svelte coming to SvelteKit. Newcomers aren't really aware of the underlying issue when using load and would treat it as "preparing the data of the current page for client", thus the assumption that each call was clean. One could argue that users should've read the docs more carefully, but we could also make it better and have this notes highlighted.

This is also probably why we get a lot of requests to have a separate load that can exclusively run on either server or client, and also a lot of other issues specifically relating to just the load function.

documentation/docs/03-loading.md Outdated Show resolved Hide resolved
documentation/docs/03-loading.md Outdated Show resolved Hide resolved
documentation/docs/03-loading.md Outdated Show resolved Hide resolved
documentation/docs/03-loading.md Outdated Show resolved Hide resolved
documentation/docs/03-loading.md Outdated Show resolved Hide resolved
@Rich-Harris
Copy link
Member

I realise this PR has got very involved for such a straightforward change, but this section of the docs needs some work anyway and this is as good a time as any, so I left some suggestions to that effect

@ignatiusmb
Copy link
Member Author

Updated.

FYI, the locals and session bit were from #1542 (comment) which I thought might be worth mentioning, but if it creates more confusion then it's probably best not to.

@Rich-Harris Rich-Harris merged commit 958d8dd into sveltejs:master Aug 1, 2021
@Rich-Harris
Copy link
Member

thanks!

@ignatiusmb ignatiusmb deleted the i1542/load-runs-on-server-and-client branch August 2, 2021 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Documentation should clarify that server state is not automatically per-request
3 participants