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

@zooniverse/react-components: improvements to the output bundle size #3761

Closed
wants to merge 1 commit into from

Conversation

eatyourgreens
Copy link
Contributor

@eatyourgreens eatyourgreens commented Oct 11, 2022

  • add webpack bundle analyser
  • import only the bell and envelope icons from Font Awesome.
  • import only the lodash utilities that are used in the code.
  • mark i18next and react-18next as external dependencies in libraries.
  • update tests to query elements by their translation keys.
  • replace mime-types with mime/lite.
  • replace @fortawesome/react-fontawesome and @fortawesome/fontawesome-svg-core with Grommet Icons Blank.

Should reduce the build size by ~350k.

Package

lib-classifier
lib-react-components

Linked Issue and/or Talk Post

How to Review

Build the library with yarn build and look at the bundle size (dist/main.js). The built library should still work when imported into the classifier and NextJS apps.

Checklist

PR Creator - Please cater the checklist to fit the review needed for your code changes.
PR Reviewer - Use the checklist during your review. Each point should be checkmarked or discussed before PR approval.

General

  • Tests are passing locally and on Github
  • Documentation is up to date and changelog has been updated if appropriate
  • You can yarn panic && yarn bootstrap or docker-compose up --build and FEM works as expected
  • FEM works in all major desktop browsers: Firefox, Chrome, Edge, Safari (Use Browserstack account as needed)
  • FEM works in a mobile browser

General UX

Example Staging Project: i-fancy-cats

  • All pages of a FEM project load: Home Page, Classify Page, and About Pages
  • Can submit a classification
  • Can sign-in and sign-out
  • The component is accessible

@eatyourgreens eatyourgreens requested a review from a team October 11, 2022 10:48
@eatyourgreens eatyourgreens force-pushed the react-components-performance branch from a827a95 to 45cfc9d Compare October 11, 2022 10:49
@coveralls
Copy link

coveralls commented Oct 11, 2022

Coverage Status

Coverage decreased (-0.02%) to 83.513% when pulling 4053d9f on react-components-performance into fc698a6 on master.

@eatyourgreens
Copy link
Contributor Author

Grommet Icons has a bell icon (Notifications) and an envelope icon (MailItem.) I’m not sure why we import Font Awesome and Grommet Icons.

@eatyourgreens eatyourgreens force-pushed the react-components-performance branch from 45cfc9d to 8fe1816 Compare October 11, 2022 15:47
@goplayoutside3
Copy link
Contributor

Grommet Icons has a bell icon (Notifications) and an envelope icon (MailItem.) I’m not sure why we import Font Awesome and Grommet Icons.

I assume those are the only two icons that use Font Awesome in lib-react-components. Could we replace them in this PR with Grommet icons to completely remove Font Awesome?

@eatyourgreens
Copy link
Contributor Author

According to #275 this is for parity with the old header, but it seems like a lot of code for two icons.

@goplayoutside3
Copy link
Contributor

Ah I see that makes sense. Agreed that it's not ideal to keep those icons around though.

@eatyourgreens
Copy link
Contributor Author

It's tempting to simply copy the SVG paths for those two icons into the code for the header menu.

I'm pushing up another change, which loads in i18next and react-i18next as external modules. That lowers the build size from ~860k to ~710k. I think the current build might be including those three times: once in this library, once in the classifier, and once in the project app.

The classifier build is also 1.5MB, which leads to very heavy page weights in the project app.

@eatyourgreens eatyourgreens changed the title @zooniverse/react-components: reduce lodash and font-awesome imports @zooniverse/react-components: improvements to the output bundle size Oct 11, 2022
@eatyourgreens eatyourgreens force-pushed the react-components-performance branch from ea83291 to 788fec4 Compare October 11, 2022 17:35
@eatyourgreens
Copy link
Contributor Author

Tests that expect labels like 'Add to favourites' are failing now because the default labels in the output library will be the translation keys. Easy enough to fix.

@eatyourgreens eatyourgreens force-pushed the react-components-performance branch 2 times, most recently from 75cd247 to bdea436 Compare October 11, 2022 18:27
@eatyourgreens
Copy link
Contributor Author

Localised text still works when I build and run the project app locally. Tested with PH-TESS in English and Spanish.

@eatyourgreens eatyourgreens force-pushed the react-components-performance branch 2 times, most recently from 9a68fb9 to 4fa5bf6 Compare October 12, 2022 10:34
@eatyourgreens
Copy link
Contributor Author

Replacing mime-db with mime/lite removes another ~150k of unnecessary code.

@eatyourgreens eatyourgreens force-pushed the react-components-performance branch 5 times, most recently from b4cbcf2 to e9fbd4f Compare October 13, 2022 10:35
@eatyourgreens
Copy link
Contributor Author

I've switched the ZooHeader to use Grommet Icons' Blank for the mail and notifications icons. Removing the Font Awesome packages knocks another 50k off the bunde size. Now down from ~850k to ~500k, which still triggers the webpack build warnings but is a massive improvement in the library size.

Most of that 500k is probably Markdownz, so we could consider splitting that out of the main library for consumers that don't use Zooniverse markdown.

@eatyourgreens eatyourgreens force-pushed the react-components-performance branch from e9fbd4f to c210484 Compare October 13, 2022 10:45
@eatyourgreens eatyourgreens force-pushed the react-components-performance branch 2 times, most recently from 9df5c27 to 0946c55 Compare October 17, 2022 15:43
@eatyourgreens eatyourgreens force-pushed the react-components-performance branch from 0946c55 to eeb5f2a Compare November 2, 2022 11:17
@eatyourgreens eatyourgreens force-pushed the react-components-performance branch 12 times, most recently from c58f2ba to 72ceac6 Compare November 9, 2022 10:46
@eatyourgreens eatyourgreens force-pushed the react-components-performance branch 4 times, most recently from 97e4f24 to f0aa4a9 Compare November 15, 2022 08:03
@eatyourgreens
Copy link
Contributor Author

I think the problem with documenting peer deps in the Readme is versioning. Mapping Viz uses either version 1.0 or 1.1. The version here is 1.2 so changes here won’t be relevant to Mapping Viz at the moment.

Looking at other libraries we use, like Grommet, peer dependencies aren’t explicitly spelled out in their Readmes either.

I’m still not sure whether the i18next packages should be bundled with the standalone library. How does Mapping Viz handle localisation?

@eatyourgreens eatyourgreens force-pushed the react-components-performance branch 4 times, most recently from 5f49469 to 4c7a7c1 Compare November 17, 2022 17:20
- add webpack bundle analyser
- import only the bell and envelope icons from Font Awesome.
- replace `@fortawesome/react-fontawesome` and `@fortawesome/fontawesome-svg-core` with Grommet Icons `Blank`.
- import only the lodash utilities that are used in the code.
- mark `i18next` and `react-18next` as external dependencies in libraries.
- update tests to query elements by their translation keys.
- replace `mime-types` with `mime/lite`.

Should reduce the build size by ~350k.
@eatyourgreens eatyourgreens force-pushed the react-components-performance branch from 4c7a7c1 to 4053d9f Compare November 18, 2022 11:36
@eatyourgreens
Copy link
Contributor Author

I'm going to close this in favour of #3900, which is producing smaller, faster builds.

@eatyourgreens eatyourgreens deleted the react-components-performance branch November 21, 2022 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants