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

Reduce bundle size from 'react-use' #80181

Closed
Dosant opened this issue Oct 12, 2020 · 2 comments
Closed

Reduce bundle size from 'react-use' #80181

Dosant opened this issue Oct 12, 2020 · 2 comments
Labels
Team:Operations Team label for Operations Team

Comments

@Dosant
Copy link
Contributor

Dosant commented Oct 12, 2020

react-use is often used in Kibana for react hooks.

There are 2 ways to import a hook

import {useDebounce} from 'react-use' // import the whole lib
import useDebounce from 'react-use/lib/useDebounce' // imports a specific hook

The whole lib is pretty heavy (20kb gzipped over network), example of visDefaultEditor bundle:

Screenshot 2020-10-12 at 17 45 55

There are ~50 occurrences of importing lib in non optimal way in different plugins:

Screenshot 2020-10-12 at 17 47 03

Fixing this should be an easy win, even though initial bundle size likely won't be affected that much (because hooks are mostly used in already code splitted UI code), but it is still nice to cut on async chunks.


@elastic/kibana-operations, what would be a preferred way?

  1. Single global react-use instance like we did with lodash
  2. Or a lint rule that forbids to import from react-use directly? ( I would vote for this one, because I think only 10% of hooks are really used)
@Dosant Dosant added the Team:Operations Team label for Operations Team label Oct 12, 2020
@spalger
Copy link
Contributor

spalger commented Oct 12, 2020

I would prefer that we use tree-shaking to remove unnecessary portions of react-use automatically (though we've had issues getting that working #62390, webpack 5 upgrade might help with that).

Another option I like is an extension to the module-migration rule that automatically rewrites the imports to use the sub-modules similar to how imports for react-router and numeral are rewritten during development.

@tylersmalley tylersmalley added 1 and removed 1 labels Oct 11, 2021
@exalate-issue-sync exalate-issue-sync bot added impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. loe:small Small Level of Effort labels Oct 12, 2021
@tylersmalley tylersmalley removed loe:small Small Level of Effort impact:low Addressing this issue will have a low level of impact on the quality/strength of our product. EnableJiraSync labels Mar 16, 2022
@Dosant
Copy link
Contributor Author

Dosant commented Oct 11, 2024

this was done via linting that restricts importing from the root of the lib

@Dosant Dosant closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Operations Team label for Operations Team
Projects
None yet
Development

No branches or pull requests

3 participants