| name | solidstart-client-only |
| description | SolidStart clientOnly: render components/pages exclusively on client, bypass SSR for browser APIs (window, document), dynamic imports with fallbacks. |
| metadata | {"globs":["src/routes/**/*"]} |
SolidStart clientOnly
The clientOnly function renders components or pages exclusively on the client side, bypassing SSR.
Component Usage
- Create separate file for client-only component:
export default function ClientOnlyComponent() {
const location = document.location.href;
return <div>Current URL: {location}</div>;
}
- Import with
clientOnly:
import { clientOnly } from "@solidjs/start";
const ClientOnlyComp = clientOnly(() => import("./ClientOnlyComponent"));
export default function IsomorphicComponent() {
return <ClientOnlyComp />;
}
- Optional fallback:
<ClientOnlyComp fallback={<div>Loading...</div>} />
Page-Level Usage
Disable SSR for entire page:
import { clientOnly } from "@solidjs/start";
export default clientOnly(async () => ({ default: Page }), { lazy: true });
function Page() {
return <div>Client-only page content</div>;
}
Parameters
fn: () => Promise<{ default: () => JSX.Element }>
- Function that dynamically imports component
options: { lazy?: boolean }
lazy: true (default) - Lazy load component
lazy: false - Eager loading
props: Record<string, any> & { fallback?: JSX.Element }
- Props passed to component
- Optional
fallback for loading state
Use Cases
- Browser APIs (
window, document, localStorage)
- Third-party widgets (maps, charts)
- DOM manipulation
- Avoiding SSR hydration issues
- Code that can't run on server
Best Practices
- Isolate client-only logic in separate files
- Provide meaningful fallbacks for loading states
- Use sparingly - prefer SSR when possible
- Consider progressive enhancement where possible