lukasbach / react-complex-tree

Unopinionated Accessible Tree Component with Multi-Select and Drag-And-Drop
https://rct.lukasbach.com
MIT License
952 stars 77 forks source link

Drag and drop crash #203

Closed juliancavallon closed 1 year ago

juliancavallon commented 1 year ago

Describe the bug Drag and drop node in tree above top most node will make runtime crash:

429.38ab39ad.iframe.bundle.js:2 Uncaught TypeError: Cannot read properties of undefined (reading 'item')
    at getHoveringPosition (main.61823e9c.iframe.bundle.js:2:352027)
    at Object.current (main.61823e9c.iframe.bundle.js:2:352284)
    at Object.onDragOverTreeHandler (main.61823e9c.iframe.bundle.js:2:546327)
    at onDragOver (main.61823e9c.iframe.bundle.js:2:451668)
    at Object.Nb (429.38ab39ad.iframe.bundle.js:2:1710399)
    at Tb (429.38ab39ad.iframe.bundle.js:2:1710553)
    at Ub (429.38ab39ad.iframe.bundle.js:2:1730480)
    at nf (429.38ab39ad.iframe.bundle.js:2:1730574)
    at se (429.38ab39ad.iframe.bundle.js:2:1730988)
    at 429.38ab39ad.iframe.bundle.js:2:1736474

To Reproduce Single Tree Example . Easy to reproduce when click Zoom Out once time in Storybook then drag and drop node in tree above top most node and move around mouse. Sometime Zoom Out not needed.

Expected behavior No crash

Desktop (please complete the following information):

Additional context Crash happen in getHoveringPosition()

hoveringPosition can be negative when clientY less then treeTop, it make linearIndex negative and make crash on line 38.

Maybe fix on line 26? const linearIndex = Math.max(0, Math.floor(hoveringPosition));

juliancavallon commented 1 year ago

Thanks for fix, no more crash.