Description
In React 19 development with StrictMode enabled, DragDropProvider can retain a manager instance after that instance has been destroyed during React’s development-only Effect replay.
useStableInstance creates the manager once and stores it in a ref, but its cleanup currently destroys ref.current from useInsertionEffect. The replayed lifecycle can therefore leave the mounted provider holding a destroyed manager.
Reproduction
- Use React 19 in development mode with
StrictMode enabled.
- Render a
DragDropProvider containing a draggable element.
- Interact with the draggable element after the initial mount.
<StrictMode>
<DragDropProvider>
<Draggable />
</DragDropProvider>
</StrictMode>
Expected behavior
The manager should remain usable for as long as its DragDropProvider remains mounted.
Actual behavior
The provider can retain a manager that has already been destroyed, so later drag interactions may fail.
Proposed direction
Move manager disposal out of useInsertionEffect and defer cleanup enough to distinguish the development-only Strict Mode replay from a real unmount.
I have a focused patch with a Storybook regression story and Playwright coverage ready to link in a pull request.
Description
In React 19 development with
StrictModeenabled,DragDropProvidercan retain a manager instance after that instance has been destroyed during React’s development-only Effect replay.useStableInstancecreates the manager once and stores it in a ref, but its cleanup currently destroysref.currentfromuseInsertionEffect. The replayed lifecycle can therefore leave the mounted provider holding a destroyed manager.Reproduction
StrictModeenabled.DragDropProvidercontaining a draggable element.Expected behavior
The manager should remain usable for as long as its
DragDropProviderremains mounted.Actual behavior
The provider can retain a manager that has already been destroyed, so later drag interactions may fail.
Proposed direction
Move manager disposal out of
useInsertionEffectand defer cleanup enough to distinguish the development-only Strict Mode replay from a real unmount.I have a focused patch with a Storybook regression story and Playwright coverage ready to link in a pull request.