Skip to content

feat: make internal Svelte Custom Element treeshakable #16075

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

Conversation

minht11
Copy link

@minht11 minht11 commented Jun 3, 2025

When inspecting my own application I noticed that despite not using any custom elements Svelte still includes code for it. This PR marks Svelte Custom Element with pure annotation so when it is not used it can safely removed.

I was not able to make it work with conditional assigment so I moved class definition into function, in my testing this reduces size of minified code by ~2kb.

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
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

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

Copy link

changeset-bot bot commented Jun 3, 2025

🦋 Changeset detected

Latest commit: 802afc6

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

This PR includes changesets to release 1 package
Name Type
svelte 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

@dummdidumm
Copy link
Member

Thank you! Which bundler are you using? We have a treeshaking check using Rollup in our test suite which didn't seem to have caught this.

@minht11
Copy link
Author

minht11 commented Jun 4, 2025

Rolldown which possibly is not yet smart enough to treeshake this. Will test it with Rollup later.

@minht11
Copy link
Author

minht11 commented Jun 4, 2025

Checked with Rollup and seems like Rolldown issue indeed, likely rolldown/rolldown#4258.

@minht11 minht11 closed this Jun 4, 2025
@minht11 minht11 deleted the feat/make-svelte-custom-element-treeshable branch June 4, 2025 18:36
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.

2 participants