-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[fix] revert change to rendering options (#2008) #2047
Conversation
🦋 Changeset detectedLatest commit: b19c371 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Eeks! You're right. Mea culpa.
That was not a goal of the original PR. Instead, the goal of the original PR was to allow you to turn off SSR full-stop by simply setting Now of course this didn't go to plan. Where I screwed up was not realizing that JS promises started evaluating immediately and not when
agree this is a terrible option (and I missed that we were doing it in dev - thanks for pointing that out)
yeah, it certainly is a downside. I thought it was worth the tradeoff for the increased power. at the very least we'd need to document it, but it is a bit of a footgun potentially I'd really like if there were a way to provide options at runtime. Right now they all have to be provided an built-time and get baked into the final app. But you could imagine someone wants their SRE to change an config value and restart the app. We shouldn't have to build a new version of the app for that. If you could provide config at runtime then we could provide functions, which would be really nice. It's something that the chart.js guys do and is by far my favorite part of that API because it lets us reject all types of feature requests by telling people they can just do it with the existing options. Another SvelteKit option was changed to a function in #2007 though that one's not an issue because it's an option that controls building and isn't a runtime thing. I think it was a really nice solution to the issue there as well
I'm not quite sure how
I don't know that we can simply ignore |
That definitely seems unconventional! Regardless, the build currently contains stringified functions, so you would need to import the config file for that to work, which we agree is bad. If it were expressed via
A couple of straw men: export function handle({ request, resolve, shell }) {
if (should_server_render(request)) {
return resolve(request);
}
return shell();
} export function handle({ request, resolve }) {
return resolve(request, {
ssr: should_server_render(request)
});
}
If you're server-rendering, that's fine, since you're loading the code anyway. If you're not server-rendering, |
Option 2 seems like the nicer choice to me and not a bad option
Could you not do
That happened frequently at Google and LinkedIn. Even for this option I could imagine it being used. E.g. if your Node servers are falling over from a spike in traffic, some SRE might turn off server rendering and just let the clients do it.
I actually was doing |
In SvelteKit, if we skip SSR then we're also skipping |
Unfortunately I don't think the changes introduced in #2008 are viable, and we need to go back to the drawing board.
Firstly, it doesn't appear to solve #1650. Even when just using
false
, SvelteKit still imports the module of a page, which blows up if the page imports a client-only dependency. And even if we deferred the import, we still can't useexport const ssr
to selectively turn off SSR, because we can't 'see' that export without importing the page.More generally, we can't really have functions in the config that execute at runtime, because doing so presents only bad options:
svelte.config.js
, which could depend on who-knows-what dependencies that shouldn't be included in prodCurrently we're using the actual function in dev, but stringifying in the build. So something like this...
...will work in dev but fail in production. This is maximally confusing.
None of this is to deny that the issues the PR was aimed at are worth solving. Until we can come up with a more robust solution I think we should revert #2008 before people start using the new config options in their apps.
If we want to use a function to determine
ssr
on a per-request basis, the proper place to express that is probably inhandle
. We could make a case for doing the same forrouter
andhydrate
but I'm not sure there's as much of a reason to do so;export const hydrate = false
seems fine.Before submitting the PR, please make sure you do the following
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0