#How do solid framework components work
1 messages · Page 1 of 1 (latest)
SolidJS framework components in Astro work similarly to other UI framework components. Here’s how they function and how they are mounted:
-
Rendering and Hydration
- By default, when you use a SolidJS component in an Astro project, it is rendered on the server to static HTML. This is useful for non-interactive components and avoids sending unnecessary JavaScript to the client.
- If you want your SolidJS component to be interactive in the browser, you add a
client:*directive (e.g.,client:load,client:idle,client:visible). This tells Astro to send the component’s JavaScript to the browser and hydrate it, making it interactive. Hydration means the component is mounted and becomes interactive on the client side at the time specified by the directive (e.g., when the page loads, when idle, or when visible) Hydrating interactive components.
-
Mounting Process
- When a SolidJS component is hydrated, Astro ensures the necessary JavaScript (including the SolidJS runtime) is loaded in the browser. The component is then mounted and becomes interactive according to the hydration directive you used.
- For server-only and hydrating components, Astro automatically wraps them in a top-level Suspense boundary and renders them on the server using Solid’s
renderToStringAsync. This means async data (e.g., fetched with Solid’screateResource) is included in the initial HTML Usage: Suspense Boundaries.
-
Usage Example
- Import your SolidJS component in your Astro file and use it like any other component. For interactivity, add a client directive:
---import MySolidComponent from '../components/MySolidComponent.jsx';--- <MySolidComponent client:load /> - This will render the component on the server and hydrate (mount) it on the client when the page loads.
- Import your SolidJS component in your Astro file and use it like any other component. For interactivity, add a client directive:
-
Mixing Frameworks
- Astro allows you to use multiple frameworks (React, Solid, etc.) in the same project. You can specify which files belong to which framework using the
includeoption in yourastro.config.mjsCombining multiple JSX frameworks.
- Astro allows you to use multiple frameworks (React, Solid, etc.) in the same project. You can specify which files belong to which framework using the
In summary, SolidJS components in Astro are rendered to static HTML by default and become interactive (mounted) in the browser when you use a client:* directive. Astro handles the server-side rendering and client-side hydration/mounting for you Front-end frameworks.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@swift wolf Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@gilded jolt when can we start using zod 4 ?
Let me check the knowledge base for you again. One moment! :books: