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

chore(build): reduce Lodash usage in superset-frontend #32341

Merged
merged 2 commits into from
Feb 21, 2025

Conversation

hainenber
Copy link
Contributor

@hainenber hainenber commented Feb 21, 2025

chore(build): reduce Lodash usage in superset-frontend

SUMMARY

Reduce some Lodash usage for cases modern JS can handle by its own.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Fix Detected
Performance Memoization Missing for Config Builder ▹ view
Files scanned
File Path Reviewed
superset-websocket/eslint.config.js
superset-frontend/plugins/plugin-chart-echarts/src/utils/eventHandlers.ts
superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Screengrid/Screengrid.tsx
superset-frontend/src/dashboard/hooks/useDownloadScreenshot.ts
superset-frontend/src/dashboard/components/menu/DownloadMenuItems/DownloadScreenshot.tsx
superset-frontend/src/features/home/ChartTable.tsx
superset-frontend/src/features/home/DashboardTable.tsx
superset-websocket/src/config.ts
superset-frontend/src/components/Select/AsyncSelect.tsx
superset-frontend/src/components/Select/Select.tsx

Explore our documentation to understand the languages and file types we support and the files we ignore.

Need a new review? Comment /korbit-review on this PR and I'll review your latest changes.

Korbit Guide: Usage and Customization

Interacting with Korbit

  • You can manually ask Korbit to review your PR using the /korbit-review command in a comment at the root of your PR.
  • You can ask Korbit to generate a new PR description using the /korbit-generate-pr-description command in any comment on your PR.
  • Too many Korbit comments? I can resolve all my comment threads if you use the /korbit-resolve command in any comment on your PR.
  • Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
  • Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.

Customizing Korbit

  • Check out our docs on how you can make Korbit work best for you and your team.
  • Customize Korbit for your organization through the Korbit Console.

Current Korbit Configuration

General Settings
Setting Value
Review Schedule Automatic excluding drafts
Max Issue Count 10
Automatic PR Descriptions
Issue Categories
Category Enabled
Documentation
Logging
Error Handling
Readability
Design
Performance
Security
Functionality

Feedback and Support

Note

Korbit Pro is free for open source projects 🎉

Looking to add Korbit to your team? Get started with a free 2 week trial here

@pull-request-size pull-request-size bot added size/L and removed size/M labels Feb 21, 2025
const anchor = useSelector(
(state: RootState) =>
last(state.dashboardState.directPathToChild) || undefined,
const anchor = useSelector((state: RootState) =>
Copy link
Member

Choose a reason for hiding this comment

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

I think that last looks much more readable, especially when we have such long array names. Maybe we should either keep lodash or implement our own last util function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes can, I'll put in our own last impl.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @kgabryje but don't think we should implement our own function. We need to keep in mind that any function that we implement needs to be maintained and in general it's best to depend on libraries that are greatly supported like Lodash.

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

Thank you for the PR @hainenber. I think some of the changes are beneficial like filter changes but others decrease readability and increase our maintenance cost. I left comments on the ones that I think we should preserve. As a general guidance, I think it's always better to rely on greatly supported libraries like Lodash instead of rewriting code which requires testing and support.

@@ -574,7 +574,9 @@ const AsyncSelect = forwardRef(
}
} else {
const token = tokenSeparators.find(token => pastedText.includes(token));
const array = token ? uniq(pastedText.split(token)) : [pastedText];
const array = token
Copy link
Member

Choose a reason for hiding this comment

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

Even though we can implement this using simple Javascript, uniq still offers semantic meaning that helps with readability.

const anchor = useSelector(
(state: RootState) =>
last(state.dashboardState.directPathToChild) || undefined,
const anchor = useSelector((state: RootState) =>
Copy link
Member

Choose a reason for hiding this comment

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

I agree with @kgabryje but don't think we should implement our own function. We need to keep in mind that any function that we implement needs to be maintained and in general it's best to depend on libraries that are greatly supported like Lodash.

@@ -142,6 +140,50 @@ function applyEnvOverrides(config: ConfigType): ConfigType {
}

export function buildConfig(): ConfigType {
const config = _merge(defaultConfig(), configFromFile());
Copy link
Member

Choose a reason for hiding this comment

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

Previous version is way more readable and less error prone.

@@ -76,7 +75,7 @@ function ChartTable({
TableTab.Other,
);

const filteredOtherTabData = filter(otherTabData, obj => 'viz_type' in obj);
const filteredOtherTabData = otherTabData?.filter(obj => 'viz_type' in obj);
Copy link
Member

Choose a reason for hiding this comment

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

👍🏼

@hainenber
Copy link
Contributor Author

hainenber commented Feb 21, 2025

Thanks all for the feedbacks. Looking at this PR retrospectively, I think I optimized too much at the expense of other factors like readability and module maturity. I'll retain the .filter and .noop replacements and discard others.

Edit: Apologies for a force push 🙏

@hainenber hainenber force-pushed the chore/reduce-lodash-dependency branch from 882f03e to 03d7877 Compare February 21, 2025 11:42
@pull-request-size pull-request-size bot added size/S and removed size/L labels Feb 21, 2025
@hainenber hainenber changed the title chore(build): remove Lodash runtime dependency for superset-websocket and reduce Lodash usage in superset-frontend chore(build): reduce Lodash usage in superset-frontend Feb 21, 2025
Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

Thank you for addressing the comments @hainenber. You have been one of the best additions to our committers roster. Keep up the excellent work 👏🏼

@hainenber hainenber merged commit f820f9a into apache:master Feb 21, 2025
48 checks passed
@hainenber hainenber deleted the chore/reduce-lodash-dependency branch February 21, 2025 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change:frontend Requires changing the frontend plugins size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants