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

feat: handleLoad hooks #11313

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

feat: handleLoad hooks #11313

wants to merge 4 commits into from

Conversation

dummdidumm
Copy link
Member

Adds handleLoad and handleServerLoad hooks that run before any invocation of a corresponding load function.
closes #9542

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:.

Adds handleLoad and handleServerLoad hooks that run before any invocation of a corresponding load function.
closes #9542
Copy link

changeset-bot bot commented Dec 14, 2023

⚠️ No Changeset found

Latest commit: 15f508a

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

@dummdidumm
Copy link
Member Author

Noting the brief discussion Rich and I had about this: The fact that you need to be very careful about which things to read in handleLoad feels like a footgun. We're not sure yet if this is an unavoidable fact and that people writing these hooks are probably more aware of the nuances of load invalidation, or if we need to tweak the design a bit (for example only tracking stuff after the inner load was called)

@david-plugge
Copy link
Contributor

Is it necessary to track anything at all inside the hooks? It feels like that should happen inside the root layout instead and the hook should only be used for logging, modifying, ...

@dummdidumm
Copy link
Member Author

If you implement an auth guard you may want to ensure it runs on every request

@david-plugge
Copy link
Contributor

Yeah sure, but would it be a problem to always run the hook when the load function chain starts? It feels more intuitive to me, very similar to how the handle hook works.

@dummdidumm
Copy link
Member Author

handleLoad runs for each load function, not once at the beginning for all.

@david-plugge
Copy link
Contributor

Ah alright. But still, why do we need to track anything then? If your page load function depends on something that runs inside handleLoad it will always be there if it always runs. I don't see why you would need tracking. Maybe I just need an example that makes use of that functionality

@Lms24
Copy link
Contributor

Lms24 commented Dec 15, 2023

I believe there was discussion around providing an untracked version of event properties alongside the main tracked one at some point?

Something like this would greatly help us at Sentry. For example to obtain route information.
Right now we rely on a brittle mechanism of avoiding to invoke the invalidation trigger.

Worth noting that we don't alter any behaviour based on reading these values so I don't think it should cause an invalidation.

@dummdidumm
Copy link
Member Author

dummdidumm commented Dec 15, 2023

@Lms24 did fly a bit under the radar, but a mechanism to not cause reruns from reading properties exists in 2.0: https://kit.svelte.dev/docs/load#rerunning-load-functions-untracking-dependencies

In fact, it's used in this PR - else handleLoad doesn't make much sense to have in many cases.

Copy link
Contributor

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a mechanism to not cause reruns from reading properties exists in 2.0:

Oh awesome, thx for clarifying! I totally missed this

documentation/docs/30-advanced/20-hooks.md Outdated Show resolved Hide resolved
documentation/docs/30-advanced/20-hooks.md Outdated Show resolved Hide resolved
Co-authored-by: Lukas Stracke <lukas.stracke@sentry.io>
@Lms24
Copy link
Contributor

Lms24 commented Jan 26, 2024

Hi, is there anything I can help with to get this merged?

@eltigerchino
Copy link
Member

eltigerchino commented Jan 26, 2024

Hi, is there anything I can help with to get this merged?

Hi Lukas. There's still some deliberation ongoing due to the concern mentioned in #11313 (comment) and we're not sure how to address this yet.

@benmccann benmccann added the documentation Improvements or additions to documentation label Jun 19, 2024
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 feature request New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for handleLoad hook on client and server hooks
5 participants