Skip to content

MultiField: undefined value triggers infinite re-render via default-param array #11

Description

@mejta

Found while building the JS unit test layer (mount-sweep).

MultiField.js uses a default parameter value = []. When value is undefined, a fresh [] is created on every render; useMulti's useEffect(..., [value]) then sees a new reference each time and calls setCollapsed([]), producing an infinite re-render loop.

Production never hits this today because prepare_items_for_js() always passes a concrete array, and the unit tests seed a stable value to match that contract — but any future caller mounting a multi_* field without a value (e.g. a custom integration or a Gutenberg block with no attribute default) will loop.

Suggested fix: hoist a module-level const EMPTY = [] as the default (or memoize), keeping the effect's dependency stable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageMaintainer needs to evaluate this issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions