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

Remove underscore from expensify-common and reduce usage of lodash and jQuery #704

Conversation

Skalakid
Copy link
Contributor

@Skalakid Skalakid commented May 24, 2024

The original goal of this PR was to remove underscore, jQuery, and lodash from files that are connected to ExpensiMark so we can workletize these functions and enable the react-native-live-markdown to run parser on UI thread. We wanted to block usage of these libraries in the whole repo, however without knowing the use cases and without being able to test it inside the private Expensify reposthat uses some of these files, we decided to:

  • remove whole underscore from repo, since it's quite easy to do without testing
  • replace more complex underscore fucntions with lodash versions because it doesn;t make. sene to re-write them
  • remove all these 3 libraries from: ExpensiMark, Logger, Src so we can workletize functions from these files and run them on UI thread in react-native-live-markdown

Fixed Issues

Expensify/App#42494

Tests

  1. What unit/integration tests cover your change? What autoQA tests cover your change?
  2. What tests did you perform that validates your changed work?

QA

  1. What does QA need to do to validate your changes?
  2. What areas do they need to test for regressions?

Copy link

github-actions bot commented May 24, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@kosmydel
Copy link
Contributor

I have read the CLA Document and I hereby sign the CLA

@Skalakid Skalakid force-pushed the remove-jQuery-underscore-lodash branch from 6d15818 to 4407b0b Compare May 24, 2024 15:56
@melvin-bot melvin-bot bot requested a review from dangrous June 5, 2024 12:03
Copy link
Contributor

@blazejkustra blazejkustra left a comment

Choose a reason for hiding this comment

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

When migrating code from lodash to native JS you have to watch out for all possible null/undefined values, or places where a variable can be an object/array interchangeably. Left some comments

.eslintrc.js Outdated Show resolved Hide resolved
lib/utils.ts Outdated Show resolved Hide resolved
lib/utils.ts Outdated Show resolved Hide resolved
lib/utils.ts Show resolved Hide resolved
lib/components/form/element/switch.js Outdated Show resolved Hide resolved
lib/ReportHistoryStore.jsx Outdated Show resolved Hide resolved
lib/PubSub.jsx Outdated Show resolved Hide resolved
lib/PubSub.jsx Outdated Show resolved Hide resolved
lib/Func.jsx Outdated Show resolved Hide resolved
lib/ExpensiMark.js Outdated Show resolved Hide resolved
@hungvu193
Copy link
Contributor

I can review this one as C+ @puneetlath

@dangrous
Copy link
Contributor

dangrous commented Jun 6, 2024

@puneetlath I'm happy to do so - either instead or in addition - but let me know if you want to be the official reviewer here since it looks like you have the context!

@hungvu193
Copy link
Contributor

Ah yeah, here's the slack convo:
https://expensify.slack.com/archives/C02NK2DQWUX/p1717682904827949

@puneetlath
Copy link
Contributor

@dangrous yeah I can take this one since I'm assigned to the issue. Though you're welcome to review as well if you like!

@puneetlath puneetlath self-requested a review June 6, 2024 14:46
lib/API.jsx Outdated Show resolved Hide resolved
lib/Network.jsx Outdated Show resolved Hide resolved
lib/PubSub.jsx Outdated Show resolved Hide resolved
lib/ReportHistoryStore.jsx Outdated Show resolved Hide resolved
lib/Log.jsx Outdated Show resolved Hide resolved
@hungvu193
Copy link
Contributor

Linting is failing @Skalakid

@blazejkustra
Copy link
Contributor

blazejkustra commented Jun 11, 2024

@hungvu193 You can continue reviewing it's connected to this (@Skalakid needs to restore the rule and it'll be fine)

Copy link
Contributor

@blazejkustra blazejkustra left a comment

Choose a reason for hiding this comment

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

Looks good to me, @hungvu193 please double check that every lodash/underscore method is replaced correctly + watch out for empty values like null/undefined as these could break the logic.

@Skalakid Should we uninstall underscore nad lodash perhaps?

@hungvu193
Copy link
Contributor

Looks good to me as well!

@Skalakid
Copy link
Contributor Author

@hungvu193 @blazejkustra All lint errors should be fixed now and I uninstalled underscore library. For now we should leave lodash and jQuery because it's hard to remove them without testing and access to the repos that use them.
I migrated the most important files like: ExpensiMark, str etc to not use these libraries, so @tomekzaw can workletize this library

@blazejkustra
Copy link
Contributor

@puneetlath @dangrous What are the next steps here?

Copy link
Contributor

@dangrous dangrous left a comment

Choose a reason for hiding this comment

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

Couple of broader questions here, feel free to ignore me if I don't have the right context. Mainly - it looks like we're not removing lodash or jquery fully, but from the PR title seems like we should be. Let me know!


// Use this deferred lib so we don't have a dependency on jQuery (so we can use this module in mobile)
import {Deferred} from 'simply-deferred';
import {has} from 'lodash';
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe I'm misinterpreting the issue goal but shouldn't we be removing anything from lodash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh sorry, I forgot to update the title of the PR and its description. We decided to remove all these libraries only inside files that we will be using in react-native-live-markdown and execute on the UI thread (ExpensiMark, Src etc). Also, we decided to move more complex underscore functions to lodash, like during migration to TS in E/App, because it doesn't make sense to rewrite them on our own in the utils file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the PR description

'arrow-body-style': 'off',
'es/no-nullish-coalescing-operators': 'off',
'rulesdir/prefer-underscore-method': 'off',
'es/no-optional-chaining': 'off',
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB - why are we turning off these rules?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We turned off some ESlint rules because in some cases we had to use some JS features that were blocked by them, to make functions work the same

@@ -1,6 +1,5 @@
import $ from 'jquery';
Copy link
Contributor

Choose a reason for hiding this comment

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

should we be removing/replacing this too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We decided to not migrate it because we don't have access to repos that are actually using this Network file, and we couldn't test it. Replacing jQuery can introduce many critical regressions and require bigger logic changes

import has from 'lodash/has';
import {once} from 'lodash';
Copy link
Contributor

Choose a reason for hiding this comment

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

same here - aren't we removing lodash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The same answer from above applies to it

@Skalakid Skalakid changed the title Remove lodash/underscore/Jquery from expensify-common Remove underscore from expensify-common and reduce usage of lodash and jQuery Jun 12, 2024
@Skalakid Skalakid closed this Jun 12, 2024
@Skalakid
Copy link
Contributor Author

I am closing this PR since I created a rebased version of it, that has all commits signed. Please continue reviewing/discussions in the new PR

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.

7 participants