Skip to content
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

Treeshake exported client components that are not imported #6527

Merged
merged 3 commits into from
Mar 13, 2023

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Mar 13, 2023

Changes

Fix #6467

When a hydrated or client:only component is passed to the client build, only build those that are imported. e.g. import { Foo } from './ManyComponents.jsx', the bundled entry should only export Foo and not other unused components.

This PR changes our client component collection logic to also track exports names imported. A custom Vite plugin is used to proxy entries to something like export { Foo } from '/resolved/path/ManyComponents.jsx', so that we treeshake the unused components.

Testing

Added a bundling test to make sure unused components are treeshaken.

Docs

n/a. Bug fix.

@changeset-bot
Copy link

changeset-bot bot commented Mar 13, 2023

🦋 Changeset detected

Latest commit: 887fae4

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

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Mar 13, 2023
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice test, this change looks great. Thanks for tackling!

@matthewp matthewp merged commit 04e624d into main Mar 13, 2023
@matthewp matthewp deleted the treeshake-client-entries branch March 13, 2023 17:16
@astrobot-houston astrobot-houston mentioned this pull request Mar 13, 2023
@mydracula
Copy link

1679328618205

Is this not merged into the main branch? I updated 2.1.3 and still report an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Whole ui package get bundled in astro
4 participants