solid-start icon indicating copy to clipboard operation
solid-start copied to clipboard

[Feature?]: disable ssr for some pages

Open huseeiin opened this issue 4 months ago • 2 comments

Duplicates

  • [x] I have searched the existing issues

Latest version

  • [x] I have tested the latest version

Summary 💡

currently we can do this:

function Home() {
  return <h1>Home</h1>;
}

import { clientOnly } from "@solidjs/start";

export default clientOnly(() => Promise.resolve({ default: Home }));

but this doesn't work the same as ssr: false in ssr: false, initial data fetching happens on the client with clientOnly data is initially brought by the server

Examples 🌈

No response

Motivation 🔦

No response

huseeiin avatar Aug 05 '25 19:08 huseeiin

If you want to fetch data on the client, use a simple fetch inside the onMount hook. If you want to fetch data on the server, use SolidJS’s createResource hook. Another solution is to create an API endpoint and fetch from it on the client.

hytkhn01 avatar Aug 10 '25 09:08 hytkhn01

If you want to fetch data on the client, use a simple fetch inside the onMount hook. If you want to fetch data on the server, use SolidJS’s createResource hook. Another solution is to create an API endpoint and fetch from it on the client.

Your approach is sound, but I have encountered some issues. For instance, when attempting to use Axios for network requests and needing to retrieve a JWT from localStorage to configure an Axios interceptor, I receive the error “localStorage is not undefined”.

erickwokk avatar Oct 11 '25 01:10 erickwokk