Skip to content

Migrate from lodash to es-toolkit#596

Open
AaravMalani wants to merge 11 commits intomasterfrom
migrate-es-toolkit
Open

Migrate from lodash to es-toolkit#596
AaravMalani wants to merge 11 commits intomasterfrom
migrate-es-toolkit

Conversation

@AaravMalani
Copy link

@AaravMalani AaravMalani commented Feb 12, 2026

Description

Migrate from lodash to es-toolkit

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Note: A couple of Github Actions tests fail, hence I'm making a draft PR till it gets resolved Fixed, making it a normal PR

Copy link
Contributor

@leeyi45 leeyi45 left a comment

Choose a reason for hiding this comment

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

Left some comments. Also please address some of the linting errors. Otherwise, thanks for doing the migration work

@leeyi45
Copy link
Contributor

leeyi45 commented Feb 12, 2026

Will close #557

@leeyi45
Copy link
Contributor

leeyi45 commented Feb 13, 2026

Btw, was there any particular reason why you're performing this migration? @AaravMalani

@AaravMalani
Copy link
Author

Btw, was there any particular reason why you're performing this migration? @AaravMalani

I wanted to increase build times for py-slang. With the current setup, py-slang provides the entire lodash to the modules which it loads, so Rollup has to bundle it at build-time. It'd be more efficient for the modules to contain the functions they require, especially since most modules use one or two functions at max, and es-toolkit functions have a significantly tinier footprint than lodash functions (I think lodash-es bundled more than 10 different functions with just merge)

@RichDom2185 RichDom2185 marked this pull request as ready for review February 18, 2026 17:05
Copy link
Member

@RichDom2185 RichDom2185 left a comment

Choose a reason for hiding this comment

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

If @leeyi45 has further comments please do comment

'prefer-const': ['warn', { destructuring: 'all' }],

'@sourceacademy/default-import-name': ['warn', { path: 'pathlib' }],
'@sourceacademy/no-barrel-imports': ['error', ['lodash']],
Copy link
Member

Choose a reason for hiding this comment

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

Revert

Comment on lines +77 to +78
"react": "^18.3.1",
"react-dom": "^18.3.1",
Copy link
Member

Choose a reason for hiding this comment

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

Revert

Suggested change
"react": "^18.3.1",
"react-dom": "^18.3.1",

Copy link
Author

Choose a reason for hiding this comment

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

I think the tests were failing without react in package.json for some reason

Comment on lines +15 to +16
expect(utils.extractPackageName('es-toolkit@npm:^1.44.0'))
.toEqual('es-toolkit');
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to update these?

Copy link
Member

Choose a reason for hiding this comment

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

Same here

Copy link
Author

Choose a reason for hiding this comment

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

I wasn't sure what the purpose of the file was, considering I can't find any uses for it in the repo

Copy link
Member

Choose a reason for hiding this comment

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

Same here

AaravMalani and others added 2 commits March 2, 2026 15:35
Co-authored-by: Richard Dominick <34370238+RichDom2185@users.noreply.github.com>
Co-authored-by: Richard Dominick <34370238+RichDom2185@users.noreply.github.com>
return defaultConfig;
}
return _.merge({ ...defaultConfig }, userConfig);
return merge({ ...defaultConfig }, userConfig);
Copy link

Choose a reason for hiding this comment

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

Bug: The mergeConfig function uses a shallow copy, which allows the merge utility to mutate nested objects within the original defaultConfig.
Severity: MEDIUM

Suggested Fix

To prevent unintended mutations, perform a deep copy of the defaultConfig object before passing it to the merge function. This ensures that nested objects are also duplicated, breaking the reference to the original configuration and preserving its integrity.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/bundles/robot_simulation/src/controllers/utils/mergeConfig.ts#L8

Potential issue: The `mergeConfig` function uses a shallow copy (`{ ...defaultConfig }`)
to protect the default configuration from being modified. However, this protection is
insufficient for nested objects. When a configuration object contains nested objects
(e.g., a `THREE.Color` instance), the shallow copy shares references to these nested
objects. The `merge` function, which modifies its target object in place, will then
mutate these shared nested objects, leading to unintended mutation of the original
`defaultConfig`. The existing unit test for mutation only covers flat objects and does
not detect this issue with nested structures.

Did we get this right? 👍 / 👎 to inform future reviews.

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.

3 participants