Skip to content

Additional property disappears when renaming two properties in quick succession #5021

@restareaByWeezy

Description

@restareaByWeezy

Prerequisites

  • I have searched the existing issues
  • I understand that providing a SSCCE example is tremendously useful to the maintainers.
  • I have read the documentation

What theme are you using?

core

Version

6.4.2

Current Behavior

When two additional property keys are renamed in quick succession (before React re-renders between them), the first rename's result is silently dropped and the property disappears from the form.

Expected Behavior

Both renamed properties should remain visible in the form after sequential renames.

Steps To Reproduce

  1. Open the playground and select the "Additional Properties" example
  2. Click "Add Item" (creates a newKey property)
  3. Rename newKey to second, press Tab
  4. Immediately click the assKickCount key input, type renamed, press Tab
  5. The second property disappears from the form

Environment

  • OS: macOS
  • Node: 22
  • npm: 10

Anything else?

handleKeyRename in ObjectField.tsx captures formData via useCallback and computes the entire new formData object from that snapshot. When two renames fire before React flushes the batched state update from the first rename, the second rename reads stale formData that doesn't include the first rename's result.

The pendingChanges queue in Form.tsx serializes the application of changes, but the payload is already computed from stale data before being enqueued — so the queue can't recover the lost property.

A possible fix is to use a ref to always read the latest formData inside the callback:

const formDataRef = useRef(formData);
formDataRef.current = formData;

Then read formDataRef.current inside handleKeyRename instead of the closure variable.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions