Skip to content

Disable immutable check in production#6619

Merged
ckifer merged 3 commits intorecharts:mainfrom
tngwoerleij:disable-immutable-check-in-production
Nov 18, 2025
Merged

Disable immutable check in production#6619
ckifer merged 3 commits intorecharts:mainfrom
tngwoerleij:disable-immutable-check-in-production

Conversation

@tngwoerleij
Copy link
Contributor

@tngwoerleij tngwoerleij commented Nov 13, 2025

Description

Make sure redux-tookit's immutableCheck is only active during testing and not in production build to avoid other modules using this module having warnings emitted by redux-toolkit during their testing.

This was harder to implement than initially thought as the babel build was still lacking to define process.env.NODE_ENV properly. I aligned this with the existing implementation for the webpack build.

Related Issue

Fixes #6617

Motivation and Context

Fix #6617

How Has This Been Tested?

Built production artifacts and checked that immutableCheck is disabled. Ran tests and checked that immutableCheck is enabled.

Types of changes

  • 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 change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have added a storybook story or VR test, or extended an existing story or VR test to show my changes

Summary by CodeRabbit

  • Chores

    • Modernized build configuration to inline environment variables and refine transpilation behavior.
    • Added tooling to support the updated build setup.
  • Tests

    • Enabled stricter state immutability checks in non-production builds to catch issues earlier.

to make sure that process.env.NODE_ENV is properly defined also in babel
builds.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 13, 2025

Walkthrough

Replaced JSON Babel config with a programmatic .babelrc.js (adds transform-define and babel-plugin-dev-expression), added babel-plugin-transform-define to devDependencies, and changed Redux store middleware to add an immutableCheck option conditioned on process.env.NODE_ENV (enabled except for commonjs, es6, and production).

Changes

Cohort / File(s) Summary
Babel configuration
\.babelrc`, `.babelrc.js``
Deleted .babelrc; added .babelrc.js exporting equivalent config in JavaScript, registering babel-plugin-dev-expression and transform-define, and preserving @babel/preset-env, @babel/preset-react, @babel/preset-typescript plus env.commonjs transform
Build dependencies
\package.json``
Added devDependency babel-plugin-transform-define@^2.1.4
Redux middleware
\src/state/store.ts``
Added immutableCheck option to the Redux Toolkit default middleware config; it is enabled when NODE_ENV is not one of ['commonjs','es6','production']; serializableCheck remains disabled

Sequence Diagram(s)

sequenceDiagram
  participant App as App init
  participant Store as store.ts
  participant Middleware as getDefaultMiddleware

  rect rgb(235,245,255)
    App->>Store: initialize store
    Store->>Store: read process.env.NODE_ENV
    alt NODE_ENV in ['commonjs','es6','production']
      Store->>Middleware: immutableCheck: false
    else
      Store->>Middleware: immutableCheck: true
    end
    Store->>Middleware: serializableCheck: false
    Store->>App: return configured store
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review parity between removed .babelrc and new .babelrc.js for equivalent presets/plugins and env.commonjs behavior.
  • Confirm transform-define usage correctly inlines process.env.NODE_ENV and that the new devDependency version is appropriate.
  • Verify the immutableCheck condition in src/state/store.ts matches intended environments (ensure test CI uses one of the excluded values if tests should skip the check).

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly reflects the main change: disabling the immutable check in production builds, which is the core objective of this PR.
Description check ✅ Passed The PR description covers all required template sections: description, related issue, motivation/context, testing approach, and change type selection. All key information is present.
Linked Issues check ✅ Passed The code changes fully address issue #6617: immutableCheck is now disabled in production builds and enabled for testing, preventing redux-toolkit warnings in downstream tests.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the objective: Babel config migration to support process.env.NODE_ENV inlining, and immutableCheck conditional logic in the Redux store.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 50857d5 and 94fa7d8.

📒 Files selected for processing (1)
  • src/state/store.ts (1 hunks)
🔇 Additional comments (1)
src/state/store.ts (1)

52-52: Logic looks correct per past review discussion.

The negation ensures immutableCheck is disabled for the CommonJS, ES6, and production builds (preventing warnings in downstream tests) while remaining enabled during Recharts' own development and testing.

Consider adding a brief inline comment explaining the non-standard NODE_ENV values, since 'commonjs' and 'es6' are unusual and future maintainers may wonder about them:

+        // Disable immutableCheck for all build targets (commonjs, es6, production) to prevent warnings in downstream tests.
+        // During Recharts development/testing, NODE_ENV is typically 'development' or 'test', keeping the check enabled.
         immutableCheck: !['commonjs', 'es6', 'production'].includes(process.env.NODE_ENV ?? ''),

Verify that babel-plugin-transform-define is correctly configured to inline process.env.NODE_ENV for each build target:

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@tngwoerleij tngwoerleij marked this pull request as ready for review November 13, 2025 08:40
@PavelVanecek
Copy link
Collaborator

Do we run babel? I thought that's for umd build only.

@PavelVanecek
Copy link
Collaborator

Nvm it's the opposite. Babel everywhere except umd.

@codecov
Copy link

codecov bot commented Nov 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.15%. Comparing base (154ce28) to head (94fa7d8).
⚠️ Report is 20 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6619   +/-   ##
=======================================
  Coverage   94.14%   94.15%           
=======================================
  Files         493      493           
  Lines       41080    41105   +25     
  Branches     4777     4784    +7     
=======================================
+ Hits        38676    38701   +25     
  Misses       2399     2399           
  Partials        5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codecov
Copy link

codecov bot commented Nov 13, 2025

Bundle Report

Changes will increase total bundle size by 1.58kB (0.06%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.12MB 1.58kB (0.14%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
cartesian/Line.js 5 bytes 24.46kB 0.02%
component/Label.js 113 bytes 20.27kB 0.56%
state/tooltipSlice.js 780 bytes 8.79kB 9.74% ⚠️
util/BarUtils.js -33 bytes 5.6kB -0.59%
state/store.js 240 bytes 4.6kB 5.5% ⚠️
state/SetTooltipEntrySettings.js 506 bytes 1.46kB 53.21% ⚠️
util/LogUtils.js -33 bytes 875 bytes -3.63%

middleware: getDefaultMiddleware =>
getDefaultMiddleware({
serializableCheck: false,
immutableCheck: process.env.NODE_ENV === 'test',
Copy link
Member

Choose a reason for hiding this comment

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

Can we do !== prod instead? Pretty sure this doesn't get set to test when running things locally (besides tests)

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 also thought about this in the first place, but the build scripts for CommonJS and ES6 builds use NODE_ENV "commonjs" and "es6" respectively which would lead to the immutableCheck not being disabled for them. At least vitest sets "test" as NODE_ENV which is why I chose it here. To be correct, we would have to change it to

        immutableCheck: ['commonjs', 'es6', 'production'].includes(process.env.NODE_ENV ?? ''),

to my understanding. Do you agree?

Copy link
Member

Choose a reason for hiding this comment

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

thats fine but I think you would need to negate that so that the check would be off for those values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Certainly! My bad 😞 I will push a new commit shortly

@ckifer ckifer merged commit 7e7a975 into recharts:main Nov 18, 2025
23 checks passed
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.

Recharts emits console warnings that ImmutableStateInvariantMiddleware took too long when running tests on slow machines

3 participants