Astro

astro/directive-on-framework-component

Put client:* directives only on UI framework components imported into the .astro file, never on Astro components.

umiarkowanastatycznefe-astro

Dlaczego

An Astro component always renders to HTML on the server; it has no client runtime to hydrate. A client:load on <Header /> imported from Header.astro is not supported: it does not make the header interactive, and the author believes it is. The documented rule is that a client directive belongs on a UI framework component (React, Preact, Vue, Svelte, Solid) imported directly into the .astro file.

Poprawka

For small behaviour on an Astro component, add a <script> inside it (processed and bundled once per page), ideally defining a custom element. For stateful UI, write that part as a framework component and give it the directive where it is used.

Przykłady

---
import Header from '../components/Header.astro'
import MenuToggle from '../components/MenuToggle.tsx'
---
<!-- bad -->
<Header client:load />
<!-- good -->
<Header />
<MenuToggle client:idle />

Źródła

Fakty

Identyfikator
astro/directive-on-framework-component
Waga
umiarkowana
Sprawdzanie
statyczne sprawdzane w kodzie źródłowym przez audit
Dotyczy plików
astro
Tylko w projektach z
astro
Uczy jej skill
fe-astro Astro sites and islands
Od wersji
0.1.0

Plik reguły na GitHubie

Przeczytaj w terminalu

npx github:dawidolko/frontend-skills explain astro/directive-on-framework-component