Skip to content

Tooltip callback ref resets on unchanged rerenders #5949

Closed

Description

@freddymeta

Problem

useTooltip() returns a new callback ref after an otherwise unchanged rerender. When a consumer passes that callback to a trigger, React calls the old ref with null and the new ref with the element, causing Tooltip to remove and re-add its pointer, mouse, and focus listeners and repeat its anchor wiring.

Reproduction

const {result, rerender} = renderHook(() => useTooltip());
const firstRef = result.current.ref;
rerender();
expect(result.current.ref).toBe(firstRef); // fails on current main

Cause

Tooltip callbacks depend on the object returned by useTouchTrigger and on the complete useLayer result. Those objects can change while the callback members Tooltip uses remain unchanged, invalidating interactionRef and the combined ref.

Expected

Tooltip callback refs remain stable when the behavior that their listeners capture has not changed.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions