-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[feat] allow ssr to be configurable in +page.js and +layout.js (enhanced version) #6207
Conversation
🦋 Changeset detectedLatest commit: 6a7b8c5 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the simpler version if I'm honest. This adds a bit more complexity than I think is warranted by the feature — if page.js
references a browser-only global then we already can't import it to see if ssr
is true or false, which means AFAICT this only helps when ssr
is false
in handle
and the page needs to fetch some data from the server when it hydrates, which feels pretty niche.
Given that you can always work around including browser globals (worst case scenario, import()
inside your load
), it feels like overkill to me. #6197 by contrast is a thing of beauty! (though the inline comments apply there too — not sure why we'd treat ssr
differently to the other page options?)
@@ -13,23 +11,27 @@ SvelteKit includes a [client-side router](/docs/appendix#routing) that intercept | |||
In certain circumstances you might need to disable [client-side routing](/docs/appendix#routing) with the app-wide [`browser.router` config option](/docs/configuration#browser) or the page-level `router` export: | |||
|
|||
```js | |||
/// file: +page.js/+page.server.js | |||
/// file: +page.js/+page.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// file: +page.js/+page.js | |
/// file: +page.js |
### hydrate | ||
|
||
Ordinarily, SvelteKit [hydrates](/docs/appendix#hydration) your server-rendered HTML into an interactive page. Some pages don't require JavaScript at all — many blog posts and 'about' pages fall into this category. In these cases you can skip hydration when the app boots up with the app-wide [`browser.hydrate` config option](/docs/configuration#browser) or the page-level `hydrate` export: | ||
|
||
```js | ||
/// file: +page.js/+page.server.js | ||
/// file: +page.js/+page.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// file: +page.js/+page.js | |
/// file: +page.js |
export const ssr = false; | ||
``` | ||
|
||
In contrast to the other options, you can set this option in both `+page.js` and `+layout.js`. `ssr` options in subsequent layouts or the page overwrite earlier options. You cannot set this option in `+page.server.js` or `+layout.server.js`. This option does not take effect if the `ssr` option [in the handle hook](/docs/hooks#handle) is evaluated to `false`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for treating ssr
differently? This feels a bit confusing to me. If we made it a page option like all the others then we could move the 'You can control this setting...' paragraph back to the top instead of repeating it
To add to that thought: the whole value of The But we can only realistically get rid of the |
There are a lot of reasons why being able to set the I don't really understand the argument that a resolve option lets people opt-out of SSR too easily. Wouldn't a global flag let them opt-out even more easily and on a much wider basis? I saw the page-level option being used as an opt-out far more than I've ever seen the resolve option being used. If we're really concerned about the consistency we could make hydrate and client be resolve options as well, but really I think we should move more in the direction of getting rid of those options. Hydrate should go away longer-term after Svelte supports partial hydration. |
I'm ok with closing this PR for now and wait for an actual use case someone has where it doesn't work anymore - given the fact, that someone opened an issue right away that the ssr option wasn't working anymore, and we changed the component to be lazy-loaded, and didn't hear anything from there on, it should be ok. On the Regardless how we decide, we would still need to duplicate that option, because that "also applies to layouts" sentence is still true - except we change the logic so that other options can also be set in layouts and the same behavior applies (last one wins). I don't see a drawback for that and it would make things more consistent. |
I'll close this PR in favour of #6197 and reply to the above over there instead |
Superseedes #6197. This is the same PR as #6179 with the addition of lazy-loading the shared node, which means you can use browser-only globals in
+page.js
, too.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0