Skip to content

[Bug] useResizable recreates callbacks when snaps are omitted #5275

Description

@nynexman4464

Problem

useResizable defaults snaps with an array literal during render:

const {snaps = []} = config;

When callers omit snaps, that produces a new array on every render. Because expand, resize, and onResizeMove depend on snaps, those callbacks are recreated too. The private _snaps value passed to ResizeHandle also changes identity even though the configuration did not change.

Proposed fix

Keep one empty snaps array per hook instance with useRef, and use it only when config.snaps is absent. Explicit caller-provided arrays keep their existing behavior.

Regression coverage

A hook test rerenders the same omitted-snaps configuration and verifies that:

  • expand remains stable
  • resize remains stable
  • props._snaps remains stable

The test fails on current main and passes with the patch. Existing ResizeHandle behavior remains green.

This change intentionally does not memoize the entire useResizable return object; that broader optimization is not needed to fix the confirmed default-array defect.

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