Skip to content

nodeRef solution for React 19 does not work due to incorrect build output #779

Closed

Description

@rhyek

The recommended solution for the React 19 findDOMNode removal is to provide a DOM element reference via nodeRef. This does not work due to how react-draggable is being built.

The check being done for provided nodeRef here falls back to using ReactDOM.findDOMNode when nodeRef is an empty ref ({ current: null }), which is always the initial value for DOM refs.

The source code appears to be doing the correct thing and should not result in this behavior, but the compiled code changes the behavior:

findDOMNode() {
  var _this$props$nodeRef$c, _this$props;
  return (_this$props$nodeRef$c = (_this$props = this.props) === null || _this$props === void 0 || (_this$props = _this$props.nodeRef) === null || _this$props === void 0 ? void 0 : _this$props.current) !== null && _this$props$nodeRef$c !== void 0 ? _this$props$nodeRef$c : _reactDom.default.findDOMNode(this);
}

I have some tests proving this here.

Image

Activity

  1. rhyek commented on Apr 27, 2025

    @rhyek
    Author

    Setting an initial value works:

    const nodeRef = useRef<HTMLElement>({} as any);
  2. STRML commented on Sep 27, 2026

    @STRML
    Collaborator

    This was generated by AI during triage.

    Fixed as of 4.6.0. findDOMNode() now checks whether the nodeRef prop exists, not whether nodeRef.current is set, so a {current: null} ref no longer falls through to ReactDOM.findDOMNode. Your useRef({}) workaround is no longer needed.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions