Why Your Load Functions are Slow

  Рет қаралды 21,989

Huntabyte

Huntabyte

Күн бұрын

Пікірлер: 80
@videosforthegoodlife2253
@videosforthegoodlife2253 Жыл бұрын
I just wanted to say again that you are doing an awesome job. I think I've seen your subs grow like 5x, and it's well deserved. I know you have a high bar, and I think you are on the right path - and deserving. Cheers!
@Huntabyte
@Huntabyte Жыл бұрын
Wow thanks for the kind words! I appreciate it! I am super thankful for the growth I’ve experience the last few months, I hope I can continue to deliver and meet expectations!
@blokche_dev
@blokche_dev Жыл бұрын
Oh! Interesting. Thanks for sharing. Love this short format. Much easier to digest 😅
@lian1238
@lian1238 Жыл бұрын
2:37 so you forgot to return await for b and c but it still worked. is arrow function implicitly returning? what is this called?
@jwankrho
@jwankrho Жыл бұрын
No. Defining a function as "async" is simply a shorthand way of indicating that the function returns a new Promise object. This means that the function will resolve automatically, even if you don’t explicitly include a return statement.
@TruthWalker
@TruthWalker Жыл бұрын
Thanks!
@Huntabyte
@Huntabyte Жыл бұрын
Thank you Daniel, I appreciate that!
@radimnedved1401
@radimnedved1401 Жыл бұрын
Is this still up to date? Can't find it in documentation
@kevinsaltarelli
@kevinsaltarelli Жыл бұрын
This came ON TIME!!! Thank you very much :)
@pascalwidmer3875
@pascalwidmer3875 Жыл бұрын
Thanks, this really speeds up things a lot. One question: how do you throw errors like this? I get Promise { }, how and at what point do I determine if the request has failed?
@Huntabyte
@Huntabyte Жыл бұрын
Check my video on ‘Defer’ which might help answer this question!
@Plunzi
@Plunzi Жыл бұрын
Thanks, this is awesome I am actually in need for this rn. Thank you very much!
@LukasSkywalker_
@LukasSkywalker_ Жыл бұрын
Thanks. Just yesterday I was using Promise.all. Did not know about this on Sveltekit, thanks.
@Huntabyte
@Huntabyte Жыл бұрын
You're welcome!
@MrAbuYT
@MrAbuYT Жыл бұрын
Thanks for sharing this helpful content. I look forward to seeing more of it.
@johnpeap
@johnpeap Жыл бұрын
Awesome man, I would never find this myself.
@jeremyikwuje
@jeremyikwuje Жыл бұрын
Thank you for this. Trying to improve the core web vital for a project, will try this tips out.
@ABsazerNer
@ABsazerNer Жыл бұрын
that's will be the heart of my project now, I'll modify any function, please can you tell me if supabase self hosted a good choice, in your experience? if there's a better can you suggest
@Huntabyte
@Huntabyte Жыл бұрын
Unfortunately, I don't have experience self-hosting Supabase!
@adimardev1550
@adimardev1550 Жыл бұрын
very useful information. thank you so much... really appreciate.
@AakashGoplani
@AakashGoplani Жыл бұрын
This is a great technique and you explained it quite well. I wish we had something similar for universal load functions as well :(
@gorbulevsv
@gorbulevsv Ай бұрын
Thank you, useful information!!
@nobodyshomeuk
@nobodyshomeuk Жыл бұрын
How do you handle the return not existing on "PageData" when using the methods? Is there a way to properly type it in TypeScript?
@Huntabyte
@Huntabyte Жыл бұрын
You can edit the PageData interface of the app.d.ts file!
@nobodyshomeuk
@nobodyshomeuk Жыл бұрын
@@Huntabyte I see! I would have to include the part about it being a promise too right? Thanks for the reply!
@TheOllieJT
@TheOllieJT Жыл бұрын
Thank you for sharing!
@Huntabyte
@Huntabyte Жыл бұрын
You're welcome!
@AlexvanderValk
@AlexvanderValk Жыл бұрын
What happens if any of the promises rejects?
@Huntabyte
@Huntabyte Жыл бұрын
The closest error boundary is rendered.
@bjul
@bjul Жыл бұрын
Awesome video, thank you very much!
@Huntabyte
@Huntabyte Жыл бұрын
You’re very welcome!
@kisaragi-hiu
@kisaragi-hiu Жыл бұрын
In the final example, I think it's possible to put the fetch calls in the object being returned to save a wrapper function or two at the cost of that object looking more messy; is this correct? Thank you for teaching us various parts of SvelteKit regardless!
@Huntabyte
@Huntabyte Жыл бұрын
That is correct! I typically will move the functions elsewhere eventually so it’s nice to have them ready to cut and paste!
@cami7o
@cami7o Жыл бұрын
Hi Hunter! If my request is done to Supabase for example, and I want to return to the page only a member from the "data" object that I should receive if the request is ok, how can I get the response from the Promise? using 'then'? Thanks!
@SebastianEling
@SebastianEling Жыл бұрын
You should await the call. The await will. resolve the promise, so that you get the "pure" type.
@hanshurtig5943
@hanshurtig5943 Жыл бұрын
Would it be possible to do this also when using API endpoints? I've tried, but so far haven't gotten anywhere.
@LapaNaungi
@LapaNaungi Жыл бұрын
Can i render my HTML before Load resolve ?
@LapaNaungi
@LapaNaungi Жыл бұрын
This is the answer i was looking for kzbin.info/www/bejne/rYWpaqiro92GrKM
@deephousefridays1911
@deephousefridays1911 Жыл бұрын
Great info, thank you!
@Huntabyte
@Huntabyte Жыл бұрын
My pleasure!
@nextjust
@nextjust Жыл бұрын
Can you make a video about using Sveltekit and Graphql? How can we work with Graphql endpoints? What is the correct and safe method? Do we need to use any graphql gateway/package? I am eagerly waiting for your video, thanks for every contribution to the ecosystem.
@ihsanmohamad521
@ihsanmohamad521 Жыл бұрын
houdini graphql are good
@HarunZafer-f3u
@HarunZafer-f3u 6 ай бұрын
With SvelteKit 2, the top-level promises are no longer awaited
@Huntabyte
@Huntabyte 5 ай бұрын
This is true!
@piquelchips8992
@piquelchips8992 5 ай бұрын
@@Huntabyte So how would you go about doing this if they are not resolved. Do I resolve the promises with await? cause that brings us back to square one. I have also seen people mention Promise.all(). How would that work? Thanks again for the great videos!
@Lukehagar
@Lukehagar Жыл бұрын
Fantastic Video!
@Huntabyte
@Huntabyte Жыл бұрын
Thanks, Luke!
@jonathangamble
@jonathangamble Жыл бұрын
Confused on how to do error handling with this...
@insa1988
@insa1988 5 ай бұрын
Awesome 🎉
@hiranga
@hiranga Жыл бұрын
Super useful!
@Huntabyte
@Huntabyte Жыл бұрын
Glad it was helpful!
@jaideepshekhar4621
@jaideepshekhar4621 Жыл бұрын
Wait, am I missing something, or will just making promises obviously reduce time to the longest timeout, since nothing is actually happening, it's just waiting for end time. Otoh, fetching data is not waiting for time end, but you're actually doing something in that time?
@Huntabyte
@Huntabyte Жыл бұрын
The timeout was just a demonstration - I could have put actual fetch requests there but network speed can change slightly per request so I found it more difficult to explain that point.
@TechBuddy_
@TechBuddy_ Жыл бұрын
Why wrap a single function call in a wrapper function can't we just remove the await and directly pass the promise as the return value??
@Huntabyte
@Huntabyte Жыл бұрын
You can certainly do this if the data doesn't require further transformation from the initial request! If I'm fetching from an API I will typically want to also do a `return await response.json()` after the `fetch` has resolved, which would require me to wrap them.
@TechBuddy_
@TechBuddy_ Жыл бұрын
@@Huntabyte well I'd chain a couple thens ( I am pretty sure thens return a new promise but I may be dumb so take that with a grain of salt )
@Huntabyte
@Huntabyte Жыл бұрын
@@TechBuddy_ I think it's all a matter of personal preference, I just prefer to wrap them! I think it makes it easier for others to visualize how they could potentially wrap some of their existing logic!
@TechBuddy_
@TechBuddy_ Жыл бұрын
@@Huntabyte so my way works too right ?
@sachahjkl
@sachahjkl Жыл бұрын
@@TechBuddy_ yes it does
@SheeceGardazi
@SheeceGardazi Жыл бұрын
waooo awesoem tut!
@paundrakkkrishna3214
@paundrakkkrishna3214 Жыл бұрын
❤️
@Football-miracle
@Football-miracle Жыл бұрын
Please make a vidio how to send a massage with redirect in sveltekit
@benny-shen
@benny-shen Жыл бұрын
nice tips
@Huntabyte
@Huntabyte Жыл бұрын
Thank you!
@tger3773
@tger3773 Жыл бұрын
ok
@tger3773
@tger3773 Жыл бұрын
ㅎㅎ
@underview8492
@underview8492 Жыл бұрын
How is this different from await Promise.all()?
@Huntabyte
@Huntabyte Жыл бұрын
It's not, it's just done for you :)
@nooalovern
@nooalovern Жыл бұрын
or just: const [d1,d2,d3] = await Promise.all([res(3000), res(2000), res(1000)])
@Huntabyte
@Huntabyte Жыл бұрын
Of course, but SvelteKit does it automatically for you
@mody-pq8kd
@mody-pq8kd Жыл бұрын
Promise.all can solve this problem and make your code more readable
@rohitkharche7562
@rohitkharche7562 Жыл бұрын
I wonder if Promise.all() will also achieve the same result
@Huntabyte
@Huntabyte Жыл бұрын
That's essentially what SvelteKit already does for you when you return promises in your load functions 🔥
@rohitkharche7562
@rohitkharche7562 Жыл бұрын
@@Huntabyte so what if promises have interdependence on each other will that also tank performance
@Huntabyte
@Huntabyte Жыл бұрын
@@rohitkharche7562 Yeah because if you think about it - you would HAVE to wait for one promise to resolve before using those results in the next request! There's no getting around that case.
@carlosmastin9852
@carlosmastin9852 Жыл бұрын
Promise.all or Promise.allsettelled should get you the same results, but definitely nice that Sveltekit can do this for you
SvelteKit & Prisma Full-Stack CRUD Application
14:38
Huntabyte
Рет қаралды 47 М.
Global Stores Are Dangerous
11:48
Huntabyte
Рет қаралды 18 М.
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
10X Your SvelteKit Developer Experience in VSCode
10:00
Huntabyte
Рет қаралды 39 М.
Loading Data in SvelteKit (+page.js & +page.server.js)
14:22
Huntabyte
Рет қаралды 83 М.
Better Protected Route Redirects
7:58
Huntabyte
Рет қаралды 28 М.
SvelteKit Layouts Explained (Nested, Groups, Resets)
17:46
Huntabyte
Рет қаралды 21 М.
Build a Reactive Search Filter with Svelte
16:11
Huntabyte
Рет қаралды 26 М.
Protect SvelteKit Routes with Hooks
21:10
Huntabyte
Рет қаралды 60 М.
Svelte 5's Secret Weapon: Classes + Context
18:14
Huntabyte
Рет қаралды 30 М.
Different Ways To Share State In Svelte 5
28:41
Joy of Code
Рет қаралды 11 М.