Skip to content

fix: stop resetInputValue writing a stale state snapshot on blur - #6329

Open
Kirylka wants to merge 1 commit into
Hacker0x01:mainfrom
Kirylka:fix/reset-input-value-stale-state
Open

Kirylka wants to merge 1 commit into
Hacker0x01:mainfrom
Kirylka:fix/reset-input-value-stale-state

Conversation

@Kirylka

@Kirylka Kirylka commented Sep 14, 2026

Copy link
Copy Markdown

Description

Linked issue: #6328

Problem

resetInputValue writes a full snapshot of this.state back through setState:

resetInputValue = () => {
  this.setState({
    ...this.state,
    inputValue: null,
  });
};

handleBlur calls it. When the user clicks away from an open calendar, two things happen in one task:

  1. The document mousedown listener in ClickOutsideWrapper runs handleCalendarClickOutside, which calls setOpen(false).
  2. Focus leaves the input, so handleBlur runs.

That listener is a plain addEventListener, so React has not committed the open: false update by the time step 2 runs. this.state still holds open: true, and the snapshot spread writes it back. The calendar closes and immediately reopens, then sits over whatever is below it.

Changes

Set only the field the method is named for:

resetInputValue = () => {
  this.setState({ inputValue: null });
};

Added src/test/reset_input_value.test.tsx, which fails on main with Expected length: 0, Received length: 1 and passes with this change.

To reviewers

The spread was introduced in 58f4afc (released in 8.5.0). No other state field is meant to change here, so dropping the spread restores the intent of that commit while keeping its behaviour: inputValue is still reset on blur when the popup is closed.

The test dispatches the outside mousedown and the input focusout inside a single act(). That ordering matters — userEvent.click awaits between pointer events, which lets React commit open: false before the blur handler reads this.state, and the bug does not appear.

Contribution checklist

  • I have followed the contributing guidelines.
  • I have added sufficient test coverage for my changes.
  • I have formatted my code with Prettier and checked for linting issues with ESLint for code readability.

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.

1 participant