react-mosaic icon indicating copy to clipboard operation
react-mosaic copied to clipboard

React 19 deprecation warning: `InternalMosaicWindow2` accesses `element.ref`

Open printfn opened this issue 11 months ago • 10 comments

I'm seeing this deprecation warning when using React 19:

Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release. Component Stack: 
    InternalMosaicWindow2 MosaicWindow.tsx:64
    ConnectedInternalMosaicWindow MosaicWindow.tsx:260
    MosaicWindow2 react-mosaic-component.js:8857
    div unknown:0
    div unknown:0
    MosaicRoot2 MosaicRoot.tsx:15
    div unknown:0
    MosaicWithoutDragDropContext2 react-mosaic-component.js:7861
    DndProvider2 DndProvider.tsx:28
    Mosaic2 react-mosaic-component.js:7994

It would probably make sense to access element.props.ref and fall back to element.ref if that doesn't exist.

printfn avatar Feb 12 '25 21:02 printfn

Wondering if anyone is looking at this ? It flows through to the App errors screen in browser tools

pbower avatar Mar 06 '25 10:03 pbower

I think the issue is in react-dnd, on this line:

https://github.com/react-dnd/react-dnd/blob/1dd1bcdd39d9545fdbb319e34ddbeecf0fb9d89c/packages/react-dnd/src/internals/wrapConnectorHooks.ts#L70

Unfortunately it looks like that library is unmaintained.

printfn avatar Apr 23 '25 23:04 printfn

You should change your code https://github.com/react-dnd/react-dnd/issues/3655#issuecomment-2562092314

Lonli-Lokli avatar Jun 20 '25 07:06 Lonli-Lokli

We currently use this library but as it's more time consuming to rewrite into dockview.dev or golden-layout, decided to work on fork with support for

  • cjs/esm build
  • tree structure
  • tab support
  • no react 19 warnings

If somebody would like to try alpha, here is it https://lonli-lokli.github.io/react-mosaic/

Lonli-Lokli avatar Jun 24 '25 22:06 Lonli-Lokli

I revert my project's react version, use react v18 "react": "^18.2.0", "react-dom": "^18.2.0", and type library "@types/react": "^18.2.7", "@types/react-dom": "^18.2.4", seems not have this element.ref error

CharlesSpace avatar Aug 01 '25 10:08 CharlesSpace

Would use this but i get this warning all the time:

Console Error: Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.

Also @Lonli-Lokli s fork doesnt fix it for me; also it uses window which is not available in server components.

finnmglas avatar Aug 24 '25 10:08 finnmglas

Well, well

// you can suppress errors to feel better using the mosaic lib w/react19 :)
if (typeof window !== 'undefined') {
  const originalError = console.error;
  console.error = (...args) => {
    const msg = args[0];
    if (
      (typeof msg === 'string' &&
        msg.includes('Accessing element.ref was removed in React 19')) ||
      msg.includes('Each child in a list should have a unique "key" prop')
    ) {
      return;
    }
    originalError(...args);
  };
}

finnmglas avatar Aug 24 '25 11:08 finnmglas

Downgrade react 19 to react 18, and there will be no such error

CharlesSpace avatar Aug 24 '25 12:08 CharlesSpace

I will check React 19 next week

Lonli-Lokli avatar Aug 24 '25 14:08 Lonli-Lokli

@finnmglas can you try latest version?

Lonli-Lokli avatar Sep 04 '25 17:09 Lonli-Lokli