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

Treeshaking not working properly #544

Closed
thebuilder opened this issue Apr 20, 2022 · 2 comments · Fixed by #545
Closed

Treeshaking not working properly #544

thebuilder opened this issue Apr 20, 2022 · 2 comments · Fixed by #545

Comments

@thebuilder
Copy link
Owner

Currently the index.ts files rexports the InvIew and useInView function. This should allow the consumer to import either, and have the other removed when bundling.

https://github.com/thebuilder/react-intersection-observer/blob/master/src/index.tsx#L3-L4

export { InView } from './InView';
export { useInView } from './useInView';

However, this doesn't appear to happen when building for production. Importing either, results in all the exports being included.
Look at https://bundlephobia.com/package/[email protected] where all the exports have the same size (1.8kB)

@thebuilder
Copy link
Owner Author

Turns out the issue was caused by static values (displayName and defaultProps) on the InView component. These were extracted by babel, and in turn prevents it from being excluded from the bundle.

@thebuilder thebuilder linked a pull request Apr 21, 2022 that will close this issue
thebuilder added a commit that referenced this issue Apr 21, 2022
Tree shaking was broken due to the InView component.

This fixes it, and adds the size-limit package to better keep track of the size going forward.

This resolves #544

BREAKING CHANGE: Can no longer do the default import of InView
@thebuilder
Copy link
Owner Author

🎉 This issue has been resolved in version 9.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant