-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: Add handleLoad hooks on client and server
#9543
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
🦋 Changeset detectedLatest commit: f7de955 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
1bfeb3e to
b41f7c4
Compare
|
Awesome stuff! Would this also allow some sort of locals for shared load functions? // hooks.client.js
export const handleLoad = ({event, resolve}) => {
event.locals.myFetch = createFetchClient(event);
// ^ better choose a different name
return resolve(event);
}// routes/some/page/+page.js
export const load = async ({ locals }) => {
const res = locals.myFetch(...)
...
}This would make libraries so much easier to build while also resolving the waterfall problem ( |
|
I haven't touched the type of I'd argue though that event type expansion is a bit out of scope for this intial PR/feature but I'd leave it up to the Kit maintainers to decide on that :) |
|
Re changeset: Just amend the PR, changesets will pick it up, and we sqash everything anyway. |
|
Seems like this pr got forgotten. I would absolutely love to see |
|
What do you mean by "shared locals"? Could you add your use case to the related issue? |
Basicly |
|
Would like to see this get merged since we are also leveraging dynamic |
|
Closing in favor of #11313 - thank you! |
This PR is a PoC implementation of our feature request from #9542. It adds support for a
handleLoadhook inhooks.client.jsas well ashandleLoadandhandleServerLoadhooks inhooks.server.js.The usage of these hooks is very similar to the usage of the server-side
handlehook, where users are provided with aneventand aresolvefunction.Please take a look at #9542 for further details.
At this stage, this PR definitely needs more tests and of course a proper review. I'm more than happy to continue working on this if you decide to go forward with the proposed
handleLoadhooks. Please feel free to request changes or apply changes yourself - whatever you prefer :)Also, happy to split this PR up into the individual hooks if you prefer that!
EDIT: I only ran
pnpm changesetafter opening this PR (sorry!). Should I re-open a new PR or does this still work?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:.