-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
SvelteKit allows building Single Page Apps with the following config:
const adapter = require('@sveltejs/adapter-static');
module.exports = {
kit: {
adapter: adapter({
fallback: '200.html'
},
prerender: {
enabled: false
},
ssr: false
}
};Is your feature request related to a problem? Please describe.
Even with the ssr disabled in config file, it is impossible to reference window or document without wrapping it in an environment check. This is because each component needs to be evaluated to determine whether it has SSR export, as @Rich-Harris explained here:
The fundamental issue is that the component must be imported in order to determine whether it has an ssr export. That would continue to be true if we checked each page for ssr at build time and added the information to a manifest.
There's a couple of options that spring to mind - we find some other way of establishing whether a given page should be SSR'd, or we determine it with static analysis (which has the usual caveats but should be pretty robust in this case).
Describe the solution you'd like
I'd like to have a way of configuring SvelteKit as a true SPA, in which I need not worry about referencing browser globals.
As a possible way forward, @benmccann suggested to expand the ssr option, allowing not just a boolean value:
The other option would be to make the setting more than just a boolean. E.g. we could have true/false/per-page or something like that or always/never/true-by-default/false-by-default or whatever makes sense
I think this would be a fine solution.
Describe alternatives you've considered
The only alternative I currently see is to preface browser globals with environment check and load naughty dependencies dynamically.
How important is this feature to you?
Slightly annoying. Gets in the way. Forces to add meaningless code.
Additional context
The original issue regarding SPA in SvelteKit #754