Skip to content

Improve handling of compilerOptions.hydratable #120

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

Closed
dominikg opened this issue Jul 26, 2021 · 6 comments
Closed

Improve handling of compilerOptions.hydratable #120

dominikg opened this issue Jul 26, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@dominikg
Copy link
Member

Describe the problem

Currently vite-plugin-svelte defaults to hydratable: true which is not the default for svelte and mostly due to the reason that it reliably works with and without ssr.

In situations where you don't use ssr and/or don't need clientside hydration, this leads to increased output size.

Describe the proposed solution

Only compile with hydratable: true when one of the following is true

  • compilerOptions.hydratable is set to true in svelte config
  • compilerOptions.hydratable is not defined in svelte config and viteConfig.ssr exists

Alternatives considered

stick with the current default. Users that want hydratable: false should set it in svelte config.

Importance

nice to have

@dominikg dominikg added enhancement New feature or request triage Awaiting triage by a project member and removed triage Awaiting triage by a project member labels Jul 26, 2021
@benmccann
Copy link
Member

Sounds fine to me as long as we specify a default of true in SvelteKit still

@dominikg
Copy link
Member Author

Explicit compilerOptions.hydratable in kit is a good idea if #121 doesn't work out.

It would work even with the current version of kit as it sets viteConfig.ssr.

That check isn't ideal (false positive if the config value is set but ssr isn't used), but the more correct/strict check

const isSSR = !!(viteEnv.command === 'serve' ? viteConfig.server.middlewareMode : viteConfig.build.ssr);

would be false for the build of client bundle, where hydratable is needed.

@bluwy
Copy link
Member

bluwy commented Jul 26, 2021

I never realized hydratable was set to true by default all these time. Is it true for production builds too? I think this is a welcomed change.

@dominikg
Copy link
Member Author

dominikg commented Jul 26, 2021

It would work even with the current version of kit as it sets viteConfig.ssr.

turns out i was wrong. the kit client build does not set it, and it breaks as expected. So this change would require kit to explicitly set it.

@dominikg
Copy link
Member Author

PR in kit to set hydratable: sveltejs/kit#2024

using viteConfig.ssr turned out to be not the best idea as this is not always set when hydratable is needed. So instead of adding an automatic default that only works half of the time, vite-plugin-svelte will default to hydratable: false always

@dominikg
Copy link
Member Author

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

No branches or pull requests

3 participants