Skip to content

useDisabled hook causes infinite loop #40845

@Inwerpsel

Description

@Inwerpsel

Description

Usage of the useDisabled hook can result in infinite loops. I found this on the Post Template block where it disables the inputs of the none selected list items. It has a heavy impact on editor performance.

It seems like the listener here is doing attribute updates that trigger the same listener. See screenshots of the Call Stack below.

If I check the mutation record the function receives, it always has null for the previous tabIndex value. (could be unrelated)

Screenshot from 2022-05-05 13-57-59

Screenshot from 2022-05-05 14-03-17

Screenshot from 2022-05-05 14-46-56

Step-by-step reproduction instructions

I don't know if there's any preconditions about our setup that could trigger this. From a first look it seems like it should happen for anyone.

  1. Add a Query Loop block in the editor, with a block that has focusable elements (for example Post Excerpt).
  2. Set up the Query Loop so that there's more than 1 result.
  3. Run a performance recording with your browser's dev tools. Or put a breakpoint in the listener.
  4. See how the listener is triggering itself continuously.

Screenshots, screen recording, code snippet

No response

Environment info

WordPress: Tested on both 5.9 and 6.0-RC1
Chrome: Version 101.0.4951.54 (Official Build) (64-bit)

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Not yet

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions