Must Know App Router Secret: Promises For Props

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

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

  • @techs7296
    @techs7296 Год назад +16

    I didnt knew this but i faced this performance issue. Thanks Jack for help.

  • @viper_eyes
    @viper_eyes Год назад +14

    As always ,you are awesome Jack, you keep digging here and there and come out with something incredible like this , and I see the beard coming ,cheers man and tell the wife to let the beard grow

  • @developerpranav
    @developerpranav Год назад +1

    This is the most promising data-fetching and handling video I've seen regarding the new app router! Definitely signing up for Pro NextJS!

  • @brucegenerator2755
    @brucegenerator2755 9 месяцев назад +1

    jack you absolutely rule! so much of your content helps me at work and quite often; whether its brainstorming, understanding new concepts, or an idea of a new direction to look into. thanks so much and keep it up man!

  • @tonystark4416
    @tonystark4416 Год назад +1

    Thanks! Relatively new React web dev here, and I just wanted to say I am enjoying your lesson

  • @ollierkul
    @ollierkul Год назад +3

    Literally met an issue today that this seems to solve, perfect timing!

  • @PostMeridianLyf
    @PostMeridianLyf Год назад +2

    Thank you so much. Ive been building all my full stack next apps without using the Api functionality in next. Now I am definitely going to use it.

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

    What an absolute gem! You made it so easy to understand even for a beginner like me!

  • @echobucket
    @echobucket Год назад +13

    I'm constantly shocked by how complicated all of this has gotten.

  • @1felixxex1
    @1felixxex1 Год назад +2

    Nice vid! Bonus that I learned about the underscore idea for naming folders... I went back to the docs to read more about how that works.

  • @SchokoMuffinMhmhm
    @SchokoMuffinMhmhm Год назад +3

    Is there a particular reason you reached for react-error-boundary instead of the build in error.js file from Nextjs?

  • @kengreeff
    @kengreeff Год назад +1

    Nice work Jack!

  • @zackinfos5933
    @zackinfos5933 Год назад +1

    Thank you infinitely for the efoort and the knowledge you are spreading with us. May i forward my question or a request let's say... What is the best way to connecr nextjs and a separate backend in term of forming our logic, there are actually ways for example request direct from components or using api routes as a proxy

  • @CFXTBogard
    @CFXTBogard Год назад +1

    Nice, this content is so high I'm throwing away my old gummies.

    • @jherr
      @jherr  Год назад +1

      Yeah, don't throw away the new gummies. :)

  • @afion113
    @afion113 Год назад +2

    Thank you so much for explaining this Jack! When passing promises as props, does it mean the 'promise cracking' phrase is happening in React hydration stage? Does it also mean it might affect the CLS if I do not have the right size (dimensions) for a loading component as fallback? Thank you so much again for these awesome video!

    • @jherr
      @jherr  Год назад +2

      `use` is cracking the promise and most likely throwing the promise on render and then React is getting that promise and subscribing to it itself so that when it resolves it will re-render the component. And all that is done on the server side. If you look at the RSC payload you can see a "promise type" marker with the data from the promise, so it's resolved on the server. Then on the client during hydation they use do a Promise.resolve(payload) and pass that in.

    • @afion113
      @afion113 Год назад

      @@jherr Hi Jack, Thank you for explaining how the promise works both is RSC and client component! If everything rendered on the server side, would it be the same as SSR in page route and the page load should be fast? I thought I would not even see the loading stage when the html is ready to be served. However when I tried your example with image fetch instead, I would see a loading state before image loaded, rather than seeing the image right away (comparing to page route approach). Does it mean it is slow even when the promise gets resolved on the server?

    • @jherr
      @jherr  Год назад +3

      @@afion113 So if you are going to get the image data on the server, and that image API is slow, then ask yourself, would you rather the customer have an interactive page with a spinner, or a page that is slow to respond? Because the App Router gives you the ability to have a fully interactive page where parts of it stream and become interactive. Where the pages router simply blocks on getServerSideProps which means that the page would simply be slow to repond.

  • @NicholasAlico
    @NicholasAlico Год назад +1

    What a great video! So easy to understand and see the power of this pattern. Thanks Jack!

  • @DanielEmenikeCodes
    @DanielEmenikeCodes Год назад +1

    Awesome video. I actually use RTK and RTK query for my projects and hoping to move them into NextJs. Request: Please Can you make a video on using RTK with Next JS . I will be grateful.

  • @username4794
    @username4794 Год назад +3

    Pro tip: when creating files in VSCode you can write the file path. Vs code will automatically create all folders to that file.
    Found that feature wery useful when defining routes in app router 🙂

    • @jherr
      @jherr  Год назад +3

      That is an awesome tip! Thanks!

  • @codeChuck
    @codeChuck 5 месяцев назад +1

    This is mind-blowing! How can you pass a promise over the wire? How is this possible?

  • @PUTTEKOOL
    @PUTTEKOOL Год назад

    Don't you still feel we are introducing many anti patterns for server side components here? 1.Creating a api endpoint for fetch that should be done in the server component not an own api 2.Talking about React Query and such that becomes more obsolete with server side fetching and caching. 3.Using boundary package. The thing for me is that I have not come to face this kind of problem, maybe I will, but still this feels too complex.

  • @kumrogames
    @kumrogames Год назад +2

    Very cool! Great info as always sir!

  • @nilsandresen97
    @nilsandresen97 Год назад

    Would you say that the use hook is production ready? All documentation I could find about it is in the React RFC. 😥

  • @VincentFulco
    @VincentFulco Год назад +2

    Hey Jack. Huge fan of your stuff. Tried to sign up to the newsletter 3x and I get no response from your ESP. Using fastmail and not in spam. thx

    • @jherr
      @jherr  Год назад

      You can send a request directly to team@pronextjs.dev to get registered. The site is still new and there were some issues with the certificates.

  • @DesolationPhoenix
    @DesolationPhoenix Год назад +5

    Hi Jack! Do you have any references for understanding how client components that receive props from server components are rendered? It’s confusing to me that a client component that receives props from a server component would actually be server-rendered and “blocked” by the fetching in the server component, as you mentioned. What parts of such a client component are actually client-rendered then?
    Thanks!

    • @jherr
      @jherr  Год назад +2

      The actual blocking in the "client" component happens on the server side, the rendered component is sent to the client when the server render of the client component is completed. "Client" components are rendered on both the client and the server.

    • @DesolationPhoenix
      @DesolationPhoenix Год назад

      @@jherr In that case, is there a way to render a loading state in place of the client component while the server component is performing the data fetching? Should I use a loading.tsx? Thank you so much!

    • @jherr
      @jherr  Год назад +3

      @@DesolationPhoenix Yeah, if you use the `use` hook then wrap it in a Suspense as shown in the video. If you use the React-Query `useQuery` hook then look at the `isFetching` boolean and render a loading state if it's true (again, as shown in the video.)

    • @DesolationPhoenix
      @DesolationPhoenix Год назад

      @@jherrthank you so much!!!

    • @maltehecht1845
      @maltehecht1845 Год назад

      That question was in my head the whole time while watching the video 😅
      Honestly, the way that is handled with rsc is next level. That's so much more convenient.
      Btw. are the any good reasons for using react query etc over use + suspense?

  • @andrewc8125
    @andrewc8125 Год назад +2

    Wow...amazing as always.

  • @MrPlaiedes
    @MrPlaiedes Год назад

    If you're scaffolding to use app router but grab the football and instead pass the promise to a client component, why not just have the client component fetch with React Query to begin with?

  • @umargulzar2982
    @umargulzar2982 Год назад +1

    Next Js Guru ❤❤❤ Love from Pakistan ❤❤❤

  • @will_zzy
    @will_zzy Год назад

    Hi, Jack. I enjoyed this video a lot! I have one question though. In the documentation of react-error-boundary, the author says it can only be used in a client component. Why does it works fine in a server component in this case?

    • @jherr
      @jherr  Год назад

      Server compents can include client components. And client components can include server components and children or rendered props.

  • @SajidAliSoftwareEngineer
    @SajidAliSoftwareEngineer Год назад +1

    Thank you for the nice content. a request, can you please share your environment setup (Terminal with Theme/VSCode theme/fonts)

  • @osmanakar2507
    @osmanakar2507 Год назад +1

    great video 🙌 I do not understand why we had multiple copy of the data in vdom part 4:47 . what is the cause of this? data is already at page level and in one place. 😕

    • @jherr
      @jherr  Год назад +2

      Anything you pass to a client component as a property is serialized and serialized independently of any other component. That's why the multiple copies. The context is a single copy because we are only sending the prop to the provider client component and then it's sharing it around both on the server and on the client.

    • @osmanakar2507
      @osmanakar2507 Год назад +1

      thanks for the answer 🙌 I believe some kind of lint rule is needed to avoid this. It is a mistake that a developer can easily make and it can realy hurt the perf.
      was it like this before app router?

  • @Cahnisama
    @Cahnisama Год назад +1

    Interested in the app Router nextjs course. I am just hoping there is purchase power parity, brazillian real is super weak and my Jr salary doesn't go very far

  • @shin5302
    @shin5302 Год назад +2

    Thank you for these fantastic tips.

  • @JEM_GG
    @JEM_GG Год назад +2

    had to do a little reading on use() but this is looking really really cool

  • @DenisMitiliuc
    @DenisMitiliuc Год назад +1

    Hello Jack thank you for your awesome videos. I wanted to ask you a question that I’m struggling for a while. I have two projects one is a nextjs project of a website and the second one is a monorepo project that contains reusable components. These components are published to npmjs and are imported as dependency into the first one. The issue is in the development workflow. I’m trying to link with pnpm link the components packages to ease the workflow and it works but if you have any hook for example useState in any component it will throw an error saying can not read useState of undefined.
    Thank you

    • @jherr
      @jherr  Год назад +1

      You probably have competing React versions. So the components are on one version of React and the NextJS server is another. Is this 13? If so you want 18 across the board and probably more specific than that.
      FWIW, the best solve here is to bring everything into the monorepo.

    • @DenisMitiliuc
      @DenisMitiliuc Год назад

      @@jherr yes very good point and I checked it all projects are of the same version of react and common dependencies. You can easily test it by recreating two new projects from scratch (we tested it too). One strange thing is that when we where using nextjs 12 this issue was not present after upgrading it to 13 it appeared. I might be wrong but I think it is related to new transpile option in nextjs 13. Before we were using the withTM module.

  • @grugbrain
    @grugbrain Год назад +1

    Oh my god. You just know every aspect of Next.js.

  • @jiachen1078
    @jiachen1078 Год назад

    great video! thank you! somehow, after i change to use ReactQuery, the html in the client side component doesn't show up in the html dom. any idea what i might do wrong?

  • @underflowexception
    @underflowexception Год назад +1

    I would be interested to see you make a video exploring Livewire 3. I don't think it gets enough attention from the tech community here on RUclips considering what it's capable of doing.

    • @jherr
      @jherr  Год назад +1

      I do like Livewire, but I'll probably do htmx first because it's hot now (gotta love the YT algorithm) and it has that server-driven mechanic. :)

  • @AmanKumar-eg5rc
    @AmanKumar-eg5rc Год назад

    Which vs code extension are you using in which data is render on vs code itself 6:53 timestamp?It is really cool...

    • @SharunKumar
      @SharunKumar 7 месяцев назад

      I was thinking the same thing, did you happen to find it?

    • @AmanKumar-eg5rc
      @AmanKumar-eg5rc 7 месяцев назад

      @@SharunKumar console ninja

  • @RobbieDds
    @RobbieDds Год назад

    What is the name of extension where is counted component renders?

  • @atulkumar_zip
    @atulkumar_zip Год назад

    Next js 13 loading hooks very slow when page loaded then its loading hooks and javascript example my sidebar loaded its need hooks to works it take 2s to load hooks when page full loaded my web app look like its lagging

  • @joeyywill1234
    @joeyywill1234 Год назад +1

    Great vid again jack :)

  • @basheerberkdar5238
    @basheerberkdar5238 Год назад +1

    Always special one for me ❤️

  • @snehaldilipbhaipatel1421
    @snehaldilipbhaipatel1421 Год назад +2

    Great video, I am not sure how React query is able to stream HTML for loading indicator first and then foods later without using Suspense. I thought Suspense is the only mechanism to tell React that a certain part of the application is waiting for data.

    • @jherr
      @jherr  Год назад +3

      I need to investigate a little further how RQ is doing this.

    • @rokonzamann
      @rokonzamann Год назад

      I don't think streaming has anything to do with client component.
      It's fetching and rendering UI's after reaching the browser!

    • @snehaldilipbhaipatel1421
      @snehaldilipbhaipatel1421 Год назад

      Does this mean the loading indicator for RQ is replaced with foods by client side bundle. It is not same rendering pattern as React streaming using Suspense ?@@rokonzamann

    • @jherr
      @jherr  Год назад +1

      @@rokonzamann have a look at what’s coming out of the server. It’s holding the connection open then sending more HTML and JS as the streams are resolved. That’s not initiated by the client.

    • @rokonzamann
      @rokonzamann Год назад

      @@jherr Interesting how that might work! Let's wait for your findings.

  • @grif.n
    @grif.n Год назад

    Will react-query still re-fetch on invalidation in this example? Is it aware of how to make the fetch happen again if it is passed as a prop from server component?

    • @jherr
      @jherr  Год назад

      No, it will simply re-request the original promise which will return the original data.

  • @SharunKumar
    @SharunKumar 7 месяцев назад

    How to get those console looks inline in the ide? 👀

  • @ThomazMartinez
    @ThomazMartinez Год назад

    What keyboard you use? sounds nice

  • @moosegoose1282
    @moosegoose1282 Год назад

    whats that terminal u are using to view webpage?

  • @bioburden
    @bioburden Год назад

    That's quite a bit of extra boilerplate and complexity just to trim the fat from the v-DOM.

  • @chadborghinibeats8675
    @chadborghinibeats8675 Год назад

    Hey love the videos and ive been subbed for a while. Could you please make a video regarding csrf protection in the new app router dir. There seems to be no packages for the new update and there really isn't many videos covering how to create your own either.

  • @xerossx
    @xerossx Год назад

    Love it, thank you!

  • @Glorion666
    @Glorion666 Год назад

    What is the "use" hook that you're importing from "react" on 12:33 ? Because i can't find any information about it in React docs. Thanks!

    • @jherr
      @jherr  Год назад

      It's in the experimental build of React that the App Router uses.

    • @mountakhabi
      @mountakhabi Год назад

      @@jherr but its not production ready and NextJS don't recommend it in client. What is the alternative ?

  • @8koi245
    @8koi245 Год назад

    insta-subbed to the newsletter lol

  • @admiralicic
    @admiralicic Год назад +1

    Awesome 👍

  • @Andreiu2011
    @Andreiu2011 Год назад +2

    I'm not sure I understand the benefit of react server components if you're doing promises for props. Like what's even the point then? Seems like you're running in circle by doing this whole shazam, using tanstack query on the frontend would've provided the exact same benefit

    • @jherr
      @jherr  Год назад

      A big benefit is that you are making the request off the server. So you get better security and performance. In addition if you need SEO then there is a big benefit to rendering on the server because the HTML is generated on the server and is easier for the bots to handle.

    • @Andreiu2011
      @Andreiu2011 Год назад

      @@jherr I'm talking about this specific use case in the video (promises for props). Performance would be the same since you wait for the promise to finish.
      I'm not sure about the security part, what security issues does this prevent that a separate backend wouldn't?
      The other flow (with tanstack query for example) would be to fetch from the client from a backend server, then that server can fetch the same way it's being done in the video, only less convenient I guess.
      And I might be wrong on this, but server components don't generate HTML on the server (that's being done by renderToString) but instead send the serialized react tree to the client (so not *directly* html)

    • @jherr
      @jherr  Год назад +2

      @@Andreiu2011 So about whether the API is being called from the server or the client. There are several reasons why it's ideal to call from the server. First, NextJS servers are often deployed in the same VPC as the microservices they call, so it's a much faster connection. Second, the microservices don't need to be deployed to the open Internet because they are being called only by the NextJS servers within the VPC. And third, third party APIs often have access keys which shouldn't be sent to the client for security reasons. So making the requests from the server avoids the key leakage. There are more advantages, but those are some of the primary ones.
      And "server components don't generate HTML on the server" is pretty easy to test that yourself, just create a NextJS app, start it up and look at the page source in the browser. You will see all the rendered HTML (as well as the VDOM). "View Page Source" shows what comes back from the server, it does not show the current tree. For the current tree you can use the inspector. You can also see the HTML rendered from the server in the Network panel of the inspector as the response to the initial route request. Or you can just curl the server as see what comes back.

  • @rodolfosolano2229
    @rodolfosolano2229 Год назад

    Mr Jack set localhost as endpoint, but if we are working with real life project, how do we set the endpoint?

    • @jherr
      @jherr  Год назад

      My recommendation is to use middleware to inject an API header key into the request header with the prefix for the API. It might be something like `X-API-Base-URL` or something like that, which you can set however you want in the middleware and then the components pick it up with `headers`.

  • @meka4996
    @meka4996 Год назад +1

    Super man!

  • @Getentertainedp
    @Getentertainedp Год назад

    Awesome video. How do you get those long accurate suggestions?

    • @jherr
      @jherr  Год назад +1

      Copy and paste from a previously implemented correct version. I really don't see the need to make you watch me poorly type stuff. :)

    • @Getentertainedp
      @Getentertainedp Год назад +1

      @@jherr oh I see. Anyway nice video. I learn a lot of new stuff from you. Thanks man.

  • @minhhieu1896
    @minhhieu1896 Год назад

    Nice, but is there anyway to make RSC to refetch?

    • @rico5146
      @rico5146 Год назад +1

      try to use router.refresh on the client component or revalidatePath on api route

  • @tameem551
    @tameem551 Год назад

    If we don't include "no-cache" then we wouldn't be "awaiting" for the data in all the components and the components would just reuse the same promise.
    And I reckon if we use context for passing the actual data instead of the promise, it should also send only one copy of the data with the vdom

    • @jherr
      @jherr  Год назад +3

      If you a requesting off the client then yeah, they would all pick up the same cache. But that's not going to SSR, so if you want SSR then you have to request the data in an RSC.

  • @abhilashm5236
    @abhilashm5236 Год назад

    Can you please do a video on how to do a PWA using Next JS 13 ( with app router ).

  • @shadowfaxenator
    @shadowfaxenator Год назад +3

    The problem that now error handling is not progressively enhanced. You need JS to handle them

    • @jherr
      @jherr  Год назад +1

      I don't think that's correct. All of the action is happening on the server. So client-side JS or not you would still get the error boundary content (or error.tsx) content coming off the server if there was an error.

    • @shadowfaxenator
      @shadowfaxenator Год назад +3

      @@jherr try to turn off js, you wont get any errors to render. In remix you will. Dan Abramov, explained that there was a missing part for sending errors as an action return. And it’s not implemenred

    • @jherr
      @jherr  Год назад +3

      @@shadowfaxenator You are correct sir. Thanks for the heads up on that one.

  • @Thorax232
    @Thorax232 Год назад

    I took a break from this channel for a bit, I can't believe you're still talking about NextJS payloads, it's seems like every single video. Using context for promises is a decent pattern but not realistic in the long term. And to make use of Suspense with RQ, it has a flag for that. Just using isFetching by itself is a CSR indicator. And not likely what you want if you want that loading state to float up to a larger component.

  • @dd-gk3mv
    @dd-gk3mv Год назад +1

    What vsc's theme do you use?

    • @jherr
      @jherr  Год назад +1

      Night Wolf [black]

    • @dd-gk3mv
      @dd-gk3mv Год назад

      @@jherr Thank you so much!

  • @kassios
    @kassios Год назад +1

    Thanks

  • @codewithalade5399
    @codewithalade5399 Год назад +5

    Good content. But it's weird to create context for each entity in my app.

    • @jherr
      @jherr  Год назад +5

      Then have a single context that contains multiple promises.

    • @rubendacostaesilva8442
      @rubendacostaesilva8442 Год назад

      @@jherr instead of using context, could we use Zustand or Jotai, to achieve the same thing?

    • @jherr
      @jherr  Год назад +1

      @@rubendacostaesilva8442 I wouldn't use Zustand or Jotai in their default "global" mode since globals with App Router are a no-no. Instead I would provide Zustand or Jotai atoms via context so that you are guaranteed that the state managers are per-request. Zustand and Jotai totally support this model, it's just not as super-easy as it usually is. For Zustand for example, you first call a hook that gets the Zustand hook from the context, and then you call the Zustand hook just like before.

    • @rubendacostaesilva8442
      @rubendacostaesilva8442 Год назад

      @@jherr that's sound kind of "gimmickly", but I'm going to give it a try.
      Thanks for the response, and keep up the great work you're doing!

  • @realitydesigners
    @realitydesigners Год назад +1

    This helped alot thanks

  • @OmidFaryabi
    @OmidFaryabi Год назад

    Can we use the error.js and loading.js and not installl additional packages?

    • @jherr
      @jherr  Год назад

      I only brought in the external library in the error case for simplicity. An error boundary is a single class component that is ~10 lines of code. But yeah, if you just want a catch-all you can do error.tsx.

  • @Ga2-20
    @Ga2-20 Год назад

    What about SEO in this kind of usage? Is it going to be affected? :)

    • @jherr
      @jherr  Год назад

      No. Streaming doesn’t effect SEO.

    • @Ga2-20
      @Ga2-20 Год назад

      @@jherr thanks :)

  • @nabinsaud4688
    @nabinsaud4688 Год назад +1

    I need a robust machine like your

  • @anhvuuc8693
    @anhvuuc8693 Год назад

    I like you video edit, it's so details. I would love to learn your. Can you please make a course on Udemy?

  • @rajeshdavide
    @rajeshdavide Год назад

    If we are using Suspense, then I assume even if you pass a promise or await a promise on the server, the user would not notice a difference right ?

    • @jherr
      @jherr  Год назад

      It depends on what else you have going on. The await on the server blocks any other components that are also loading.

    • @rajeshdavide
      @rajeshdavide Год назад

      @@jherr Alright. So essentially you await on the client side using "use" hook instead of the server ! Right ?

    • @jherr
      @jherr  Год назад +1

      @@rajeshdavide That's actually pretty complicated because it's both on the client and the server. "client" components run on BOTH the client and the server. That's number one. So when a "client" component on the server that uses `use` gets a fulfilled promise it renders on the SERVER. The HTML and the data are then both sent to the client where the component instance on the client is hydrated symmetrically and the `use` is run there too.

    • @rajeshdavide
      @rajeshdavide Год назад

      So if that's the case, can I assume that the fullfilled promise is streamed after the client renders the component ?
      Do you have a material where I can read more ?

    • @rajeshdavide
      @rajeshdavide Год назад

      In my mental model use hook was akin to await, if the client component that uses "use" runs on the server will it not wait until promise is resolved ?

  • @dmitriykapeliushnii9017
    @dmitriykapeliushnii9017 Год назад

    The page source code contains "Foods: Pizza, Burger, Sandwich, Pasta", but not RQ Foods. So no streaming possible with react-query atm

    • @jherr
      @jherr  Год назад +1

      Yeah, I have to take another look at that. There might be a way to get that to work.

  • @Camilvslalisa
    @Camilvslalisa Год назад

    Awesome!

  • @rahmonpro381
    @rahmonpro381 Год назад

    thanks very useful 👍

  • @abdellahalaoui6609
    @abdellahalaoui6609 Год назад

    I can't understand why you didn't use loading.tsx and error.tsx to handle the loading and error state instead of using suspense and errorboundary

    • @jherr
      @jherr  Год назад +4

      Loading and error are great to handle the route level errors. Here I'm demonstrating how to manage errors and suspenses at whatever level of granularity you want within the component tree.

  • @avneet12284
    @avneet12284 Год назад +1

    Excellent

  • @swartex92
    @swartex92 Год назад

    what theme are you using in vscode ?

    • @jherr
      @jherr  Год назад +1

      Night Wolf [black]

    • @swartex92
      @swartex92 Год назад

      @@jherr thanks 👍

  • @griffadev
    @griffadev Год назад

    Neat trick but I wonder the benefits, we get no server rendering of data, so doesn't work for no js/crawlers and more complex than an API and use query

    • @jherr
      @jherr  Год назад

      What do you mean get no server rendering of data? I showed every time that the data is server rendered. Have a look at the HTML I showed from the page source. That's coming back from the server.

    • @griffadev
      @griffadev Год назад

      @@jherr I guess not if you disable js, as the promise has the data, and not the html? I guess I can see the value if the API is slow enough you wouldn't want it on initial render maybe

    • @jherr
      @jherr  Год назад +1

      @@griffadev If you look at the output of the server, regardless of whether the client has disabled JavaScript or not, the HTML coming out of the server has all the rendered HTML including the HTML that comes in late off the suspense because the connection is held open until the suspense completes.

    • @griffadev
      @griffadev Год назад

      @@jherr that makes sense, still getting used to this react sever component world, thanks for the explanation

    • @jherr
      @jherr  Год назад +1

      @@griffadev No problem. The whole client/server isomorphic thing has always been a little complicate when you look into the details. It was simpler with the Pages Router because the flow between getServerSideProps and then rendering, then sending it to the client, and hydrating and running there, blah blah blah, was pretty straightforward. Now, with RSCs and streaming, things are getting more complicated. They are CONSISTENT, which is cool, but complex.

  • @josevsebastian2909
    @josevsebastian2909 Год назад

    can't you just use the loading and error components in the app router instead?? (error.tsx and loading.tsx in same level as the route.tsx which is currently server side rendering)

    • @jherr
      @jherr  Год назад

      This demonstrates using error boundaries and suspenses within the component to all for a finer level of loading and error indication granularity. If you don't need that then feel free to use error and loading.

    • @josevsebastian2909
      @josevsebastian2909 Год назад

      @@jherr one of the reasons I'm invested in next js is because I don't have to deal with all those states. But I get it 👍

    • @yuvarajyuvi9691
      @yuvarajyuvi9691 Год назад

      @@josevsebastian2909 you can only use them in pages right , it will wrap up the whole page with the error fallback if something fails , but if u r only using that api response in particular component then I think its best to just wrap that piece of code with error boundary

    • @josevsebastian2909
      @josevsebastian2909 Год назад

      @@yuvarajyuvi9691 in page router it works like that. Wrapping everything in error boundary and suspense. But one of the main advantages of app router is that, it respects the nested layouts of different routes, only the "page" leaf component is replaced by the boundary, all the "layout" is still rendered. And most often that's the result you want, except when you need granular loading or error handling inside the "page" and even that can be done using parallel routes.

  • @wsh4and
    @wsh4and Год назад

    I dont think we need to give underscore for the component name, Nextjs is smart enough to not include it as part of the route page as long it doesnt have page file in it, cmiiw

    • @jherr
      @jherr  Год назад

      You don't need to, but this makes it really explicit.

  • @VATNIK-KILLER
    @VATNIK-KILLER Год назад

    you're just solving the data inside the client component, context, no context, don't matter it's cached.

    • @jherr
      @jherr  Год назад

      What's cached again? The only cache that is involved here is the fetch cache which is being turned off in the code.

  • @ollierkul
    @ollierkul Год назад +1

    wooo

  • @Nurof3n_
    @Nurof3n_ Год назад

    console ninja slaps!

  • @officialrajdeepsingh
    @officialrajdeepsingh Год назад

    👍👍👍👍👍

  • @MrPlaiedes
    @MrPlaiedes Год назад

    Love your videos but promises as props just feels wrong.

  • @wasd3108
    @wasd3108 Год назад

    but if you just await the result and put it into provider you get the exact same result... lol?
    promises were irrelevant

  • @MrZiyak99
    @MrZiyak99 Год назад

    i dont understand why u are using suspense and error boundaries when next has loading.tsx and error.tsx specifically for this. also why use react query here it does not make sense to me. lastly i feel like this is not a common usecase does the next/react team encourage us to do something like this? i feel like situations like this huge payload are fairly uncommon. plz do lemme know cause there is still a lot i need to learn about the app router

    • @jherr
      @jherr  Год назад

      error and loading are route level, using suspense gives you the ability to give skeletons/spinners at a component level.
      the addition of react-query is the basis of a nice pattern of re-fetch and valuable to folks who already use that library (or SWR) to manage promises. it's just further validation that the promises are indeed promises.
      as for common use case, there are lots of use cases. i've personally worked with very large data sets on both client and server side. the nice thing about the App Router is that we are no longer sending everything out of getServerSideProps to the client, now with RSCs some data can remain strictly on the server and we can limit the amount of data going to the client.

    • @MrZiyak99
      @MrZiyak99 Год назад

      @@jherr would parallel routes be a better alternative to the suspense and error boundry situation? also what do you think of the long term use of something like react query and swr with next now pushing to have mutations with fetch? i had never faced this data issue so far (mostly cause we still use pages at work haha) but will keep this in mind!

    • @jherr
      @jherr  Год назад

      @@MrZiyak99 parallel routes are for rendering separate sections of the page like the header/footer/nav or the cart, or something like that. And the idea is that each parallel route has its own sync/async behavior. I wouldn't create a parallel route for every component on the page.
      If you are going to do mutations via API route, then RQ or SWR would be fine. If you are going to do them via server action then RQ or SWR would not be necessary and you could use something like `useTransition` to monitor them.

    • @MrZiyak99
      @MrZiyak99 Год назад

      @@jherr i use parallel routes for every independent section on my page with their own error.tsx and loading.tsx files 😭
      will keep whatever you've said in mind incase work does decide to move from pages to app
      great content thanks for the help!

    • @jherr
      @jherr  Год назад

      @@MrZiyak99 We are probably talking about the same thing. There is the main content section of the page and then other sections that can be independently rendered/streamed and that's what parallel routes are great for.

  • @Chloe-Software-Dev
    @Chloe-Software-Dev Год назад

    Why not just pass the actual data to context and then distribute it this seems just overcomplicaton

    • @jherr
      @jherr  Год назад +1

      That's another option, but in this case that would mean blocking the RSC making the request because it would have to await the request. That would mean that any other components it contained that had additional requests would be blocked on the request.

  • @onta.nicolae
    @onta.nicolae Год назад +3

    I found out that server actions are now fully usable in both server and client components and have replaced all of my api routes with those. Integrates amazingly with tanstack query too and its much easier to write them. Is there any downside to this?

    • @curufinw3
      @curufinw3 Год назад

      I found using server actions for data fetching to have some important limitations.
      For me the deal breaker was having no built-in way to abort requests, like you would using an AbortController on normal fetch calls. This is a big issue with typeahead server validation or autocomplete requests, where promises may be resolved out of order