Skip to content

Bug: React 18 vs 19 callback refs #34071

@telam

Description

@telam

I'm not entirely sure if this is a bug with React or expected behavior in React 18 vs 19. However, this is something I noticed while I was implementing a custom hook for an IntersectionObserver, and my useEffect was called twice, but my callback ref wasn't in StrictMode. I have created minimal code examples in codesandbox that reproduce the issue I'm seeing. I have viewed the following React documentation pages:

Note, there is no mention of callback refs and how they behave in strict mode in React 18's docs that I could find, but perhaps I missed it.

React version: 18.3.1 and 19.1.1

Steps To Reproduce

  1. Reload the page
  2. View the console and see the difference in what's logged in 18 vs 19

Link to code examples:

Note: I used the default TypeScript sandboxes from codesandbox

The current behavior

The callback ref used in React 18 is not called three times in StrictMode.

The expected behavior

It should display the same output as React 19, where the node is a HTMLDivElement, null, and then HTMLDivElement again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions