To use SolidJS in Astro, run npx astro add solid, write components in .jsx or .tsx with signals from solid-js, and render them with a client directive such as client:visible. Astro SolidJS islands are small and fast because Solid compiles JSX into direct DOM updates with no virtual DOM. If the project also uses React or Preact, tell each integration which files are its own with include.
Key Takeaways
npx astro add solidinstalls@astrojs/solid-jsand configures JSX for Solid.- Solid components run once; signals update only the DOM that reads them.
- Don’t destructure props in Solid; read
props.nameso values stay reactive.- Use
includewhen Solid shares.tsxfiles with React or Preact.
Install
# terminal
npx astro add solid
// astro.config.mjs
import { defineConfig } from 'astro/config';
import solidJs from '@astrojs/solid-js';
export default defineConfig({
integrations: [solidJs()],
});
The command also sets "jsxImportSource": "solid-js" in tsconfig.json, so TypeScript understands Solid’s JSX.
A first Solid island
// src/components/Counter.tsx
import { createSignal } from 'solid-js';
export default function Counter(props: { start?: number }) {
const [count, setCount] = createSignal(props.start ?? 0);
return (
<button type="button" onClick={() => setCount(count() + 1)}>
Clicked {count()} times
</button>
);
}
---
// src/pages/index.astro
import Counter from '../components/Counter.tsx';
---
<Counter client:visible start={5} />
Signals are functions: read with count(), write with setCount(). The component function runs once; when the signal changes, Solid updates only the text node that reads it.
The props rule
Solid tracks reactivity through property access, so destructuring props breaks it:
// Avoid in Solid: loses reactivity
// export default function Greeting({ name }) { return <p>Hi {name}</p>; }
// Do this
export default function Greeting(props: { name: string }) {
return <p>Hi {props.name}</p>;
}
In an Astro island, props are set once at hydration, so you won’t always notice. It matters as soon as the component is nested inside another Solid component that passes changing values.
Sharing state between Solid islands
A signal or store created at module level is shared by every island that imports it:
// src/state/cart.ts
import { createSignal } from 'solid-js';
export const [cartCount, setCartCount] = createSignal(0);
Any Solid island can import cartCount and setCartCount. To share with islands in other frameworks, use Nano Stores with @nanostores/solid.
Solid next to React or Preact
Solid, React and Preact all claim .jsx and .tsx. With more than one, scope each integration:
// astro.config.mjs
import solidJs from '@astrojs/solid-js';
import react from '@astrojs/react';
export default defineConfig({
integrations: [
solidJs({ include: ['**/solid/*'] }),
react({ include: ['**/react/*'] }),
],
});
Keep the files in src/components/solid/ and src/components/react/. TypeScript can only use one jsxImportSource by default, so add a pragma comment at the top of files for the other framework: /** @jsxImportSource react */.
Solid-specific gotchas
- Use
<Show>and<For>for conditionals and lists; they keep updates fine-grained. Plainarray.map()works but re-creates rows. - Resources and Suspense work in islands, but data fetched in the browser isn’t in the server HTML. Fetch in the Astro frontmatter and pass it as a prop when the content matters for SEO.
- Browser APIs go in
onMount, which only runs on the client. For components that can’t render on the server at all, see client:only.
When Solid fits
Solid suits interactive widgets with frequent updates (filters, live data, editors) where you want React-like JSX with a small runtime. For simple toggles, a plain script or Alpine.js is lighter. The islands architecture guide explains how islands hydrate. The config docs show where integrations go, and any of our Astro themes can take a Solid island with the command above.
FAQ
Does Astro support SolidJS?
Yes, through the official @astrojs/solid-js integration. Solid components render to HTML on the server and hydrate with any client:* directive.
Why isn’t my Solid component updating?
Usually because props were destructured, or a signal was read as count instead of count(). Read props as props.name and call signals as functions.
Can I use Solid and React in the same Astro project?
Yes. Use the include option on each integration so Astro knows which .tsx files belong to which framework, and add a JSX pragma in files for the non-default framework.