GithubHelp home page GithubHelp logo

Comments (3)

justinfagnani avatar justinfagnani commented on May 30, 2024

I don't think the use case you're taking about or the example your posted is really hydration in the sense that I know it. You essentially have a component that's already "hydrated" or just doesn't need hydration.

One case where defer-hydration would be critical is if instead of fetching data based on a user-id attribute, it fetched based on some non-serializable property set by the parent during the parent's hydration. Then you would want to wait until you had the data from the parent to begin the fetch so that you potentially didn't fetch twice and throw away one result. The component could wait to fetch if defer-hydration is present and fetch when it's removed. This would probably look like it deferring it's normal connected or attribute-changed logic.

Regardless, you have a component that async fetches data, and therefore all of the APIs based on that data need to be designed with that in mind. Whether getFriends() is async, or there's a promise on the component that resolves when it's ready, etc., would be up to the component. Presumably it has to answer all those questions for client-side rendering too, so there's nothing defer-hyderation could do to universally answer them.

from community-protocols.

dgp1130 avatar dgp1130 commented on May 30, 2024

I don't think the use case you're taking about or the example your posted is really hydration in the sense that I know it. You essentially have a component that's already "hydrated" or just doesn't need hydration.

I can see that await fetchUser is arguably not hydration, but do you also think Number(this.getAttribute('user-id')!) is not hydrating? The current defer-hydration proposal is kind of vague on the definition of "hydration" and I proposed a few different interpretations in my first comment. How do you define that term for the purposes of defer-hydration?

One case where defer-hydration would be critical is if instead of fetching data based on a user-id attribute, it fetched based on some non-serializable property set by the parent during the parent's hydration. Then you would want to wait until you had the data from the parent to begin the fetch so that you potentially didn't fetch twice and throw away one result. The component could wait to fetch if defer-hydration is present and fetch when it's removed. This would probably look like it deferring it's normal connected or attribute-changed logic.

Sure, if you believe that is a more compelling use case then I agree async hydration could be just as relevant there. I created a new Stackblitz which demonstrates this exact use case.

I don't personally see defer-hydration as intrinsically tied to top-down hydration or non-serializable inputs and I don't think this particular issue is all that affected by it.

Regardless, you have a component that async fetches data, and therefore all of the APIs based on that data need to be designed with that in mind. Whether getFriends() is async, or there's a promise on the component that resolves when it's ready, etc., would be up to the component. Presumably it has to answer all those questions for client-side rendering too, so there's nothing defer-hyderation could do to universally answer them.

I will point out that not all components will support client-side rendering. Server-only components which are progressively enhanced on the client that don't necessitate a re-render step are perfectly viable today. An async form of defer-hydration could be exactly what such components need to properly interoperate.

That said, I do agree client-side rendering has a very similar initialization problem, and maybe that's a signal that this is something which should be tackled independently of defer-hydration. Certainly I would want any general solution to initialization to also have a good story as relates to hydration and server-only components in particular.

from community-protocols.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.