Skip to content

Conversation

@jaskfla
Copy link
Contributor

@jaskfla jaskfla commented Sep 29, 2025

RN-1764

Tip

Review this PR commit-by-commit

  • Replaces imports from lodash with es-toolkit
  • Replaces getUniqueEntries with uniq from es-toolkit (identical behaviour)

Fixes:


Note

Replaces Lodash (and submodules) with es-toolkit equivalents across the monorepo, updating imports, utilities, and dependencies.

  • Dependencies:
    • Add es-toolkit and remove Lodash packages across many package.json files and yarn.lock.
  • Codebase migration:
    • Replace Lodash imports (e.g., keyBy, groupBy, debounce, throttle, cloneDeep, isEqual, merge, pick, get, flatten*, orderBy, sortBy, uniq, startCase) with es-toolkit/es-toolkit/compat across backend, frontend, and shared packages.
    • Update logic to use uniq from es-toolkit instead of custom sets or getUniqueEntries; remove @tupaia/utils getUniqueEntries export.
    • Minor refactors for formatting/line wrapping and small type adjustments where needed.
  • Utilities/Types:
    • Adjust helper functions and validators to use es-toolkit methods; update type definitions (Transform, AliasTransform) and context builders accordingly.
  • Build/Config:
    • Remove Lodash-specific bundling in vite.config.js.
  • Tests/E2E:
    • Update tests and scripts to use es-toolkit equivalents (e.g., groupBy, pick, flatten).

Written by Cursor Bugbot for commit 650d9fe. This will update automatically on new commits. Configure here.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jaskfla, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request undertakes a significant refactoring effort to replace the lodash utility library with es-toolkit across the entire codebase. The primary motivation for this change is to optimize application performance by reducing bundle sizes and enhancing tree-shaking efficiency. This involved updating package dependencies, refactoring import statements for numerous utility functions, and standardizing array deduplication using es-toolkit's uniq function.

Highlights

  • Dependency Migration: Replaced the lodash library and its individual module packages (e.g., lodash.keyby, lodash.debounce) with es-toolkit across numerous package.json files in various packages.
  • Import Refactoring: Updated import statements in over 100 files to utilize es-toolkit/compat for common utility functions such as keyBy, groupBy, debounce, isEqual, pick, flatten, cloneDeep, get, isPlainObject, sumBy, has, setWith, find, isNumber, isString, some, zipObject, partition, and startCase.
  • uniq Function Adoption: Replaced manual array deduplication patterns like [...new Set(array)] with the more concise uniq function from es-toolkit. This also led to the removal of the custom getUniqueEntries utility from @tupaia/utils.
  • Bundle Optimization: This comprehensive migration aims to reduce the overall application bundle size and improve tree-shaking capabilities by leveraging es-toolkit's modular design, ensuring only necessary utility functions are included.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request successfully replaces the lodash library with es-toolkit across the entire monorepo. The changes are extensive, touching many packages and files, but have been executed consistently and correctly. Key changes include updating dependencies in package.json files, replacing lodash imports with es-toolkit (often using the compat module for drop-in replacements), and refactoring code to use es-toolkit's uniq function instead of [...new Set()] or the now-removed getUniqueEntries utility. The author also took the opportunity to make some minor but beneficial refactorings, such as using partition for better efficiency and improving TypeScript type definitions for clarity. The migration appears to be thorough and well-executed, with no issues found during the review.

@jaskfla jaskfla changed the title tweak: RN-1764: replace Lodash with es-toolkit refactor: RN-1764: replace Lodash with es-toolkit Sep 30, 2025
return uniq(
isEventResponse(data) ? data.map(d => d.orgUnit) : data.map(d => d.organisationUnit),
);
) as string[];
Copy link

Choose a reason for hiding this comment

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

Bug: Type Assertion Masks Potential Errors

The getOrgUnitCodesFromData function uses an unsafe as string[] type assertion after calling uniq(). This cast can mask potential type errors if the mapped data contains non-string values, leading to hidden runtime issues that TypeScript would normally prevent.

Fix in Cursor Fix in Web

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tip

Review this PR commit-by-commit

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.

1 participant