-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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: Add handleLoad
hooks on client and server
#9543
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
handleLoad
hook inhooks.client.js
as well ashandleLoad
andhandleServerLoad
hooks inhooks.server.js
.The usage of these hooks is very similar to the usage of the server-side
handle
hook, where users are provided with anevent
and aresolve
function.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
handleLoad
hooks. 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 changeset
after 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 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:
.