Skip to content

@react-stately/[email protected] triggers rerender loopΒ #9420

@chekrd

Description

@chekrd

Provide a general summary of the issue here

CC report once we isolated the root cause to be a package json lock regeneration that installed @react-stately/utils at version 3.11.0:

PR #9331 (merged December 11, 2025) introduced the rerender loop issue.

The Problem Chain

  1. PR feat: Support setState callback in useControlledStateΒ #9041 (Oct 18, 2025) - Added "Support setState callback in useControlledState"
  2. This caused a regression: callbacks failed when controlled values changed externally
  3. PR fix: refactor useControlledState to address state-outdated issuesΒ #9331 (Dec 11, 2025) - Attempted to fix by adding forceUpdate:
  // Added in 3.11.0
  let [, forceUpdate] = useReducer(() => ({}), {});

  let setValue = useCallback((value, ...args) => {
    let newValue = typeof value === 'function' ? value(valueRef.current) : value;
    if (!Object.is(valueRef.current, newValue)) {
      valueRef.current = newValue;
      setStateValue(newValue);
      forceUpdate();  // ← THIS CAUSES THE RERENDER LOOP
      onChange?.(newValue, ...args);
    }
  }, [onChange]);

Why It Causes Loops

The forceUpdate() creates a new object {} on every call via useReducer(() => ({}), {}). This:

  • Forces a rerender even when state hasn't logically changed
  • Combined with certain controlled component patterns, triggers infinite loops
  • The discussion in the PR mentioned that "synchronization approach created infinite loops because the useControlledState parameter could change on each render"

Recommendation

Keep the override pinning @react-stately/utils to 3.10.8 until Adobe releases a fix.

πŸ€” Expected Behavior?

Trigger rerender only on real state change or an event.

😯 Current Behavior

In some scenarios this may lead to rerender loop.

πŸ’ Possible Solution

No response

πŸ”¦ Context

No response

πŸ–₯️ Steps to Reproduce

We have a complex private app built with react-spectrum that I cannot share. Simplistic repro did not fail.

Version

3

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

macOS

🧒 Your Company/Team

No response

πŸ•· Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions