Skip to content

NumberField disabled state conflicts with onBlur flushSync #10044

@ce2kettu

Description

@ce2kettu

Provide a general summary of the issue here

Due to disabling the NumberField when the controlled value is changed but onBlur has not yet triggered, react throws an error: flushSync was called from inside a lifecycle method. React cannot flush when React is already rendering. Consider moving this call to a scheduler task or micro task.

🤔 Expected Behavior?

The value should change and then the NumberField should be disabled.

😯 Current Behavior

Value does not change and throws a react error: flushSync was called from inside a lifecycle method. React cannot flush when React is already rendering. Consider moving this call to a scheduler task or micro task.

Image

💁 Possible Solution

Commit the value immediately when the field becomes disabled?

🔦 Context

Disabling the field if certain conditions are met after the value has changed

🖥️ Steps to Reproduce

https://stackblitz.com/edit/1lmsiyxb

Try to increase the value. It will not change and throw an error in the console.

import { useState } from 'react';

export default function Example() {
  let [value, setValue] = useState(25);
  let [disabled, setDisabled] = useState(false);

  const onChange = (val) => {
    if (disabled) return;
    setValue(val);
    setDisabled(true);
  };

  return (
    <div>
      <NumberField
        label="Cookies to buy"
        value={value}
        onChange={onChange}
        isDisabled={disabled}
      />
      <p>Current value: {value}</p>
    </div>
  );
}

Version

1.17.0

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions