Preloading data (React's cache part 2)

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ม.ค. 2025

ความคิดเห็น • 17

  • @gilsinhonunes
    @gilsinhonunes 11 หลายเดือนก่อน +6

    You and Sam are creating the best content about RSC by such a huge margin I can’t even describe.

    • @RyanToronto
      @RyanToronto  11 หลายเดือนก่อน +3

      Oh wow that's so great to hear! Thank you

  • @LutherDePapier
    @LutherDePapier 10 หลายเดือนก่อน +2

    I know exactly what you're talking about, I have these waterfalls all over my project, I think especially on its most important page. Here, by invoking loadPremiumArticles, you tell the server to not wait for confirmation on the user's premium status to start fetching on the server, you do the articles fetching at the same time on the server no matter what, knowing that if the user is free the articles will not be sent to the client anyways.
    In this case (I'm at 7:05) the articles are static so by default in Next.js they would have been cached, but if they were dynamic... Would the waterfall still be avoided?
    I'm rambling but I think it would if all the functions called would make their own entire calls themselves, have them cached with cache(), and that it would even be more secured because instead of passing an ID as a prop to launch another function to load a user's data on a dashboard, each data, each RSC component would do its own entire fetching meaning if someone in some way could pass a stolen ID to the component as a prop it wouldn't work... Sorry I'm going everywhere with this, I just hope my comment is not too convoluted. 😬

  • @ishaqbux2278
    @ishaqbux2278 11 หลายเดือนก่อน

    Just got introduced to this channel, the content is amazing.

    • @RyanToronto
      @RyanToronto  11 หลายเดือนก่อน

      Thank you!

  • @Luisllaboj19
    @Luisllaboj19 11 หลายเดือนก่อน

    I really appreciate this content about the features that come with app router, still can't understand when and where to use server actions vs route handlers, hopefully you soon find time to share the best practices. Thank you for this content!

  • @arslanali774
    @arslanali774 7 หลายเดือนก่อน

    preloading restricted data in RSC makes sense as its not visible in any way to the end user. good video

  • @asimalqasmi7316
    @asimalqasmi7316 11 หลายเดือนก่อน +2

    ❤ done watching

    • @RyanToronto
      @RyanToronto  11 หลายเดือนก่อน +1

      Thanks!

  • @hemantwasthere
    @hemantwasthere 11 หลายเดือนก่อน

    🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥

  • @cookiemonstr9071
    @cookiemonstr9071 11 หลายเดือนก่อน

    Amazing. I am your new subscriber, just one question will it affect on data change coming different from already cached data then will we get new or the cached one?

    • @RyanToronto
      @RyanToronto  11 หลายเดือนก่อน +1

      Thank you! And great question! The cache() function from React uses a very short lived cache that's only kept for the lifecycle of the current request. So if data changes and you reload the page you'll still see the new data. Check out this video that has some more details on how cache works: th-cam.com/video/MxjCLqdk4G4/w-d-xo.html

  • @redders6600
    @redders6600 10 หลายเดือนก่อน

    This is a good example of a scenario where cross-request caching could work well - I think it would be great if the `cache` function had some TTL options. In the meantime, assuming we're not/we can't use next's fetch cache, what's the best alternative for caching data that isn't request specific?

    • @RyanToronto
      @RyanToronto  10 หลายเดือนก่อน +1

      Yup! Great point, a long lived cross request cache for premium articles would be awesome.
      I think the best caching solution would be one that has low latency between the cache server and server component. If the latency is low enough then I think you can give Redis or Memcache a try. I've even heard of some people using Postgres or the file system for caching in their server apps.
      Personally, I tend to reach for Redis first, but no specific reason... I'm just familiar with it.

  • @ashleyredman
    @ashleyredman 11 หลายเดือนก่อน

    Great content, thanks for both videos. It feels very unnatural/hacky to call the async function, though can 100% see the benefits. Something to think about for sure

    • @RyanToronto
      @RyanToronto  11 หลายเดือนก่อน +2

      Glad you enjoyed the video and thanks for commenting!
      Yes, I totally agree on it being unnatural. I also feel the same away about Promise.all() data fetching as well.
      It's possible to take it too far and over-optimize by calling the preload functions everywhere. It's a useful tool to know about, but it doesn't need to be used on every page.