Dynamic Import Client Only Support #1231
BurkeDesigns
started this conversation in
Proposal
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Body
Summary
Allow Astro to hydrate dynamically imported framework components (e.g., React
.tsx) when used withclient:*directives—soawait import()+client:only(or other client directives) works reliably without runtime errors. ([GitHub]1)Background & Motivation
Today, if you dynamically import a component and add
client:only, Astro fails to render it on the client; removingclient:onlymakes it render but non-interactive, defeating the purpose of client hydration. This gap blocks legitimate code-splitting/lazy-loading patterns common in larger apps and forces awkward workarounds or fully static rendering where interactivity is needed. ([GitHub]1)User problem: “When you dynamically import any react tsx component and then use the
client:onlydirective, Astro cannot render it on the client and throws an error… withoutclient:only, it renders but is not interactive.” ([GitHub]1)Why now: Projects increasingly rely on lazy loading to control bundle size and TTI. Astro v5’s ecosystem encourages islands + partial hydration; dynamic imports should be a first-class companion to those patterns.
Goals
client:*directives (client:only,client:load,client:visible, etc.) without runtime errors.import()are properly discovered, bundled, and loaded before hydration.client:*syntax to work with dynamic imports with no special wrappers or proprietary helpers.Example
Or even better (ideal senerio):
Or, with conditional/lazy evaluation:
Both examples should (a) split the component into a separate chunk, (b) load that chunk on the client when required by the directive, and (c) hydrate it without errors—addressing the current failure described in the issue. ([GitHub]1)
Beta Was this translation helpful? Give feedback.
All reactions