Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable SSR (and CSR!) #231

Closed
Rich-Harris opened this issue Dec 5, 2020 · 8 comments · Fixed by #713
Closed

Disable SSR (and CSR!) #231

Rich-Harris opened this issue Dec 5, 2020 · 8 comments · Fixed by #713
Labels
feature / enhancement New feature or request
Milestone

Comments

@Rich-Harris
Copy link
Member

People often ask for SPA mode. We could do the following:

// svelte.config.js
module.exports = {
  adapter: '@sveltejs/adapter-node',
  serverSideRendering: false
};

(serverSideRendering: false might seem nonsensical in the context of adapter-node — why not just use adapter-static? — but we might still have dynamic endpoints, so it's something that should probably work with all adapters.)

Less commonly, people ask to disable client-side rendering (i.e. they just want SSR'd HTML, no interactivity) or at least client-side routing.

So we could have three new options that all default to true:

  • serverSideRendering
  • clientSideRendering
  • clientSideRouting

At least one of serverSideRendering or clientSideRendering would have to be true, and clientSideRouting couldn't be false if serverSideRendering was false.

@dummdidumm
Copy link
Member

Would an enum make this more clear so people cannot end up in impossible config states?

@benmccann
Copy link
Member

What is clientSideRendering without clientSideRouting or vice versa? I'm half feeling like the answer should be obvious to me, but at the same time I'm having a really hard time separating those in my mind

@Rich-Harris
Copy link
Member Author

clientSideRendering: false means 'don't run JS at all'. clientSideRouting: false means 'run JS, i.e. render/hydrate the component that defines the page we land on, but don't load/start the router, navigation will result in a full page reload'.

Obviously you couldn't have clientSideRendering: false, clientSideRouting: true, because you can't have client-side routing without loading JS.

What would the enum look like? It's easy enough to prevent impossible config states — we just throw an error

@isgj
Copy link

isgj commented Mar 23, 2021

Is it reasonable that the first steps for this feature will be

  1. make https://github.com/sveltejs/kit/blob/master/packages/kit/src/runtime/client/router.js able to start on the browser depending on the path
  2. add to https://github.com/sveltejs/kit/blob/master/packages/kit/src/core/adapt/Builder.js a method that will output (copy) a .html file without rendering the part of the target of app.html, and that in the script part will use the router as in point 1

?

@benmccann
Copy link
Member

To do only client-side rendering , I was thinking you'd want to skip running the load functions, etc. and just render the template (to replace %svelte.head%, etc.), which starts about here:

const links = options.amp

@benmccann benmccann added the feature / enhancement New feature or request label Mar 26, 2021
@lukasIO
Copy link
Contributor

lukasIO commented Mar 26, 2021

To do only client-side rendering , I was thinking you'd want to skip running the load functions, etc. and just render the template (to replace %svelte.head%, etc.), which starts about here:

For this proposal I was expecting the load function to still run on the client in order to fetch dynamic content from any endpoint, while still being able to deploy the site to let's say a shared web hoster that does not support nodejs.

@benmccann
Copy link
Member

Yes, I was referring only to server-side load

@benmccann benmccann linked a pull request Mar 29, 2021 that will close this issue
Rich-Harris pushed a commit that referenced this issue Mar 29, 2021
* documentation for ssr/router/hydrate (#231)

* buncha failing tests

* make ssr disable-able

* implement hydrate option

* prevent router from initing if router=false

* make router=false work for already inited apps

* implement page-level options

* rename doc section

* address feedback

* clarify
@regnaio
Copy link

regnaio commented Apr 10, 2022

To do only client-side rendering , I was thinking you'd want to skip running the load functions, etc. and just render the template (to replace %svelte.head%, etc.), which starts about here:

For this proposal I was expecting the load function to still run on the client in order to fetch dynamic content from any endpoint, while still being able to deploy the site to let's say a shared web hoster that does not support nodejs.

Since this has been closed, is this now possible?

How can we go about doing this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants