adobe / adobe/react-spectrum

NumberField disabled state conflicts with onBlur flushSync

Open
#10,044 5 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
15.9k
Forks
1.6k
Avg merge
3d 9m
Merged PRs (30d)
59

Description

### 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](https://stackblitz.com/edit/1lmsiyxb)

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

```import { NumberField } from './NumberField';
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 (



Current value: {value}



);
}
```

### 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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.