Client Directive Hydration Sequence in Nested Component Trees
0 reputation · 08 Jul 2021, 13:54 UTC
0 reputation · 08 Jul 2021, 13:54 UTC
Astro's Islands Architecture allows for granular control over hydration using client:* directives. When implementing complex UI patterns, it is possible to nest components that each carry their own hydration strategy, such as a client:visible component wrapped within a client:load parent.
There is uncertainty regarding the execution order and dependency resolution when these directives conflict or overlap within a single component tree. Specifically, it is unclear if a child component's client:visible trigger is delayed by the parent's hydration process or if the Intersection Observer initiates independently of the parent's state.
client:only components nested inside a client:load wrapper?Parent client:load does not override a child client:visible. The child’s hydration trigger remains viewport-based. The parent must hydrate first so the child’s DOM node exists, after which the child’s Intersection Observer can be attached and will fire independently when the element enters the viewport.
client:only nested inside a client:load wrapper is rendered with no SSR markup and mounts client-side only, after the parent has hydrated. It does not block the parent.
client:load hydrates on initial page load, immediately after the DOM is ready for that island.client:visible defers hydration until the element intersects the viewport via Intersection Observer.client:only suppresses server rendering for that island entirely; only a client-side placeholder is emitted.With a client:visible child inside a client:load parent:
client:visible observer is set up, but hydration is not executed yet.With client:only inside client:load:
client:load island hydrates normally with SSR markup.client:only island has no SSR output. After the parent hydrates, Astro mounts the child purely on the client. The parent hydration is not blocked.Hydration directive ordering changed between Astro v1.x and v2.x. Exact timing of observer registration relative to parent hydration may vary by minor release. Intersection Observer behavior can also be affected by browser settings or polyfills.
data-astro-component and data-client attributes. client:load islands receive immediate script attachment; client:visible islands show lazy attachment until scroll.client:load should appear on load; child client:visible should appear on scroll.client:only, confirm the server HTML contains no component markup for the child, only a client placeholder.To give a version-specific recommendation, please confirm the Astro major version in use. Behavior differs meaningfully between v1 and v2+.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.