Skip to content

[Bug]: Tree - TreeItem creates new handleActionsRef and cause children re-render #28879

Description

@YuanboXue-Amber

Library

React Components / v9 (@fluentui/react-components)

System Info

react-tree-preview: https://github.com/microsoft/fluentui/blob/f14628ac44d2cea2301452829d9775e49f70b824/packages/react-components/react-tree-preview/src/components/TreeItem/useTreeItem.tsx#L33C1-L35C5

Are you reporting Accessibility issue?

None

Bug Description

Actual Behavior

useTreeItem creates new handleActionsRef on each render which can cause its children TreeItemLayout to re-render.

For a simple example where clicking on a button moves item-6 to top, profiler shows two renders:
Screenshot 2023-08-16 at 13 12 24
hook 13 here is the const actionsRef = useTreeItemContext_unstable(ctx => ctx.actionsRef); call in useTreeItemLayout.

Expected Behavior

When handleActionsRef is wrapped in useEventCallback, profiler shows one render as expected:
Screenshot 2023-08-16 at 13 11 45

Logs

No response

Requested priority

Low

Products/sites affected

No response

Are you willing to submit a PR to fix?

yes

Validations

  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • The provided reproduction is a minimal reproducible example of the bug.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    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