Skip to content

fix: remove unused client nodes if CSR is disabled#15936

Draft
teemingc wants to merge 5 commits into
mainfrom
remove-unused-client-nodes
Draft

fix: remove unused client nodes if CSR is disabled#15936
teemingc wants to merge 5 commits into
mainfrom
remove-unused-client-nodes

Conversation

@teemingc
Copy link
Copy Markdown
Member

@teemingc teemingc commented May 31, 2026

closes #9703

Seeing if we can remove client nodes if they're unused. Disabling CSR in combination with server-side resolution should help obscure routes.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 31, 2026

🦋 Changeset detected

Latest commit: b40014f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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

@svelte-docs-bot
Copy link
Copy Markdown

@teemingc teemingc marked this pull request as ready for review June 1, 2026 14:27
@Rich-Harris
Copy link
Copy Markdown
Member

I don't think this is right. csr = false means that we don't load the client if we land on the page directly. If we navigate to the page from a different page with csr = true, then we can't 'unload' the client, we just treat it as a normal client-side navigation. With this change, that's impossible, because the client will attempt to import a non-existent module.

And it's not like we can opt out of client-side navigation in those cases, because we would need to either a) store the information about which pages have csr = false in the route manifest or b) fall back to a hard reload after a soft navigation failed. Neither seems desirable.

So I think the only time we would want to get rid of these files is if we know that all routes are csr = false, and in that case we'd just skip the client build altogether.

@teemingc
Copy link
Copy Markdown
Member Author

teemingc commented Jun 2, 2026

I don't think this is right. csr = false means that we don't load the client if we land on the page directly. If we navigate to the page from a different page with csr = true, then we can't 'unload' the client, we just treat it as a normal client-side navigation. With this change, that's impossible, because the client will attempt to import a non-existent module.

Ah yeah, I overlooked that.

So I think the only time we would want to get rid of these files is if we know that all routes are csr = false, and in that case we'd just skip the client build altogether.

Skipping the client build might be a little tricky. We still use the CSS files generated from that build, which is also why we couldn’t simply omit the nodes from the client build but had to delete them after the build.

@Rich-Harris
Copy link
Copy Markdown
Member

Ah. We don't generate CSS files during the server build?

@teemingc
Copy link
Copy Markdown
Member Author

teemingc commented Jun 2, 2026

We do but our current logic parses the client manifest to associate the client stylesheets with the route. Let me see if I can rework that to use the server stylesheets instead...

@teemingc teemingc marked this pull request as draft June 2, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

adapter-static generates unused js chunks when csr=false

2 participants