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

feat: reduce icon file size #3283

Closed
wants to merge 3 commits into from

Conversation

bradenmacdonald
Copy link
Contributor

@bradenmacdonald bradenmacdonald commented Nov 13, 2024

Description

Currently, the transpiled .js file of each of our icons contains some boilerplate to support extremely old browsers that don't understand the ...spread operator:

function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

This code is not necessary at all, yet it is included in every single icon file, and will be incorporated many times over into the final build. This doesn't actually impact bundle size much in practice because so much redundancy gets heavily compressed by gzip before being sent over the wire. But it's still adding complexity to these files that isn't needed, so I'd like to remove it.

In addition to removing the extends() operator, this PR turns on Babel preset-env's "targets": "defaults" option, which enables other syntax modernization: const instead of var and a fat arrow function instead of a function (which also makes the overall file more compact). These changes are not as important to me but they also clean things up, at the slight cost of changing the indentation of every line in the file.

Before: 3,102,133 bytes for 2,320 items
After: 2,179,463 bytes for 2,320 items

The change to the babel config is isolated in commit dbdf7b8 - the rest is just from running npm run build after making that change. Only the .js files are affected - no changes to .svg nor .jsx.

See also #3284 which makes a similar change for Paragon overall.

Deploy Preview

https://deploy-preview-3283--paragon-openedx.netlify.app/foundations/icons/

No change should be discernable.

Merge Checklist

  • If your update includes visual changes, have they been reviewed by a designer? Send them a link to the Netlify deploy preview, if applicable.
  • Does your change adhere to the documented style conventions?
  • Do any prop types have missing descriptions in the Props API tables in the documentation site (check deploy preview)?
  • Were your changes tested using all available themes (see theme switcher in the header of the deploy preview, under the "Settings" icon)?
  • Were your changes tested in the example app?
  • Is there adequate test coverage for your changes?
  • Consider whether this change needs to reviewed/QA'ed for accessibility (a11y). If so, please request an a11y review for the PR in the #wg-paragon Open edX Slack channel.

Post-merge Checklist

  • Verify your changes were released to NPM at the expected version.
  • If you'd like, share your contribution in #show-and-tell.
  • 🎉 🙌 Celebrate! Thanks for your contribution.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 13, 2024
@openedx-webhooks
Copy link

Thanks for the pull request, @bradenmacdonald!

What's next?

Please work through the following steps to get your changes ready for engineering review:

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

🔘 Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @openedx/paragon-working-group. Tag them in a comment and let them know that your changes are ready for review.

Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

Copy link

netlify bot commented Nov 13, 2024

Deploy Preview for paragon-openedx ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 41b9fcf
🔍 Latest deploy log https://app.netlify.com/sites/paragon-openedx/deploys/6733fbbfcacc1e00077133ac
😎 Deploy Preview https://deploy-preview-3283--paragon-openedx.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Nov 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.31%. Comparing base (fc888d5) to head (41b9fcf).
Report is 20 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3283   +/-   ##
=======================================
  Coverage   93.31%   93.31%           
=======================================
  Files         249      249           
  Lines        4441     4441           
  Branches     1014     1014           
=======================================
  Hits         4144     4144           
  Misses        294      294           
  Partials        3        3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bradenmacdonald
Copy link
Contributor Author

Closing for now in favor of #3284 which has incorporated these same changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants