Preloading data (React's cache part 2)

Поделиться
HTML-код
  • Опубликовано: 22 окт 2024

Комментарии • 17

  • @gilsinhonunes
    @gilsinhonunes 8 месяцев назад +6

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

    • @RyanToronto
      @RyanToronto  8 месяцев назад +3

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

  • @ishaqbux2278
    @ishaqbux2278 8 месяцев назад

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

  • @LutherDePapier
    @LutherDePapier 7 месяцев назад +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. 😬

  • @Luisllaboj19
    @Luisllaboj19 8 месяцев назад

    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 4 месяца назад

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

  • @cookiemonstr9071
    @cookiemonstr9071 8 месяцев назад

    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  8 месяцев назад +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: ruclips.net/video/MxjCLqdk4G4/видео.html

  • @redders6600
    @redders6600 8 месяцев назад

    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  8 месяцев назад +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.

  • @asimalqasmi7316
    @asimalqasmi7316 8 месяцев назад +2

    ❤ done watching

  • @ashleyredman
    @ashleyredman 8 месяцев назад

    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  8 месяцев назад +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.

  • @hemantwasthere
    @hemantwasthere 8 месяцев назад

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