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

fix: changed from lodash to es-toolkit #18162

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

guidari
Copy link
Contributor

@guidari guidari commented Nov 26, 2024

Closes #17731

We are moving from lodash to es-toolkit which is a modern library. That change will solve security issues we were having in lodash and also it will lead to a smaller final bundle and better performance.

Replaced a few lodash code to use pure JavaScript. Here it is a Stackblitz with the code changes examples to show that it works.

Changelog

New

  • Added es-toolkit dependency

Changed

  • Removed lodash.findlast to use pure Javascript code
  • Removed lodash.omit to use pure Javascript code

Removed

  • Removed lodash dependencies

Testing / Reviewing

  • Build should work
  • CI should pass

Copy link

netlify bot commented Nov 26, 2024

Deploy Preview for v11-carbon-web-components ready!

Name Link
🔨 Latest commit 240cb7c
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-web-components/deploys/67486c6aa81b44000883286b
😎 Deploy Preview https://deploy-preview-18162--v11-carbon-web-components.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

netlify bot commented Nov 26, 2024

Deploy Preview for carbon-elements ready!

Name Link
🔨 Latest commit 240cb7c
🔍 Latest deploy log https://app.netlify.com/sites/carbon-elements/deploys/67486c6af95fae000859a132
😎 Deploy Preview https://deploy-preview-18162--carbon-elements.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

netlify bot commented Nov 26, 2024

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 240cb7c
🔍 Latest deploy log https://app.netlify.com/sites/v11-carbon-react/deploys/67486c6afb515200081b3417
😎 Deploy Preview https://deploy-preview-18162--v11-carbon-react.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.

@guidari guidari changed the title fix: changed from lodash to lodash-es fix: changed from lodash to es-toolkit Nov 28, 2024
@@ -13,7 +13,7 @@ import React, {
import PropTypes from 'prop-types';

import classNames from 'classnames';
import throttle from 'lodash.throttle';
import { throttle } from 'es-toolkit/compat';
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey Gui, Thanks for the changes, its Awesome!

I tried to read about throttle from es-toolkit and found that it will accept only 2 parameters like throttle(func, wait) while for lodash it's like throttle(func, wait, options)

In this file Slider.tsx we were using throttle from lodash as

onDrag = throttle(this._onDrag, EVENT_THROTTLE, {
   leading: true,
   trailing: false,
 });

Which means the function this._onDrag is executed immediately when the event is triggered , but it will not be executed again at the end of the throttling interval.

Can you please make sure to change the code as well as per es-toolkit to achieve the same functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey Preeti!
I tested with lodash and es-toolkit and the behaviour is the same. We are using the es-toolkit/compat that has full compatibility with lodash, so we don't have to change the code. All es-toolkit functions have a "compat" version to ensure we don’t need to change anything in our code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh yes, the link is saying it supports leading and trailing options as well. Thanks!

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

Successfully merging this pull request may close these issues.

[Feature Request]: Drop per-method lodash dependencies
2 participants