FG
๐ŸŒ Web & Full-Stack

The minor release of 16.4 causes BREAKING changes in getDerivedStateFromProps

Freshabout 21 hours ago
Mar 14, 20260 views
Confidence Score87%
87%

Problem

According to semver, only non-breaking changes are supposed to go into minor and patch version releases. With the release of 16.4, you have made breaking changes to `getDerivedStateFromProps`. Our entire codebase, running perfectly on 16.3.2 is a dumpster fire as soon as we raise that dependency to 16.4. The only thing in your CHANGELOG about this breaking change is: > Properly call getDerivedStateFromProps() regardless of the reason for re-rendering. (@acdlite in #12600 and #12802) Please revert this change and save it for 17.0.0, or provide proper documentation to what this change actually entails so that its use can be adjusted by those who have already implemented `getDerivedStateFromProps`.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Revert Breaking Changes in getDerivedStateFromProps for 16.4

Medium Risk

The changes made in version 16.4 of React to the `getDerivedStateFromProps` lifecycle method inadvertently altered its behavior, leading to breaking changes that affect existing implementations. This violates semantic versioning principles, as minor releases should not introduce breaking changes.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Identify Affected Components

    Review your codebase to identify all components that utilize `getDerivedStateFromProps`. This will help you understand the scope of the changes needed.

    bash
    grep -r 'getDerivedStateFromProps' ./src
  2. 2

    Update to Version 16.3.2

    Revert your React dependency in your package.json file to version 16.3.2 to restore the previous behavior of `getDerivedStateFromProps`.

    bash
    npm install react@16.3.2 react-dom@16.3.2
  3. 3

    Review Documentation for 16.4 Changes

    Check the React 16.4 release notes and documentation for any changes related to `getDerivedStateFromProps`. This will help you understand how to adjust your implementation for future upgrades.

    markdown
    https://reactjs.org/blog/2018/03/27/react-v16.4.html
  4. 4

    Implement Adjustments for Future Compatibility

    If you plan to upgrade to 16.4 or later, refactor your components to accommodate the new behavior of `getDerivedStateFromProps`. Ensure that your logic correctly handles the new calling conventions.

    javascript
    static getDerivedStateFromProps(nextProps, prevState) {
      // Adjust your logic here based on new behavior
    }
  5. 5

    Test Your Application

    Run your application and execute all relevant tests to ensure that reverting to 16.3.2 resolves the issues and that your components function as expected.

    bash
    npm test

Validation

Confirm that your application runs without errors and that the components using `getDerivedStateFromProps` behave as expected after reverting to version 16.3.2. Additionally, ensure all tests pass successfully.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

reactjavascript