bvaughn / react-resizable-panels

https://react-resizable-panels.vercel.app/
MIT License
3.57k stars 125 forks source link

Losing event listener during client side routing #365

Closed bngarren closed 1 day ago

bngarren commented 1 week ago

Bottom line up front:

It seems that the 'pointermove' listener is being removed when navigating to a different route and not reattaching when navigating back to the route with resizable components. The 'pointerdown' listener remains and will restore the 'pointermove' after a click on the page.

Issue:

I'm using react-resizable-panels version 2.0.19 with @tanstack/react-router 1.34.9. On page refresh, all resizable handles are 'hoverable' and interactive. However, after navigating to a different client side route and back to the route with the resizable components, the resizable handles are not 'hoverable' until the page is clicked. It seems to be an issue with how the event listeners are being created/removed. Or perhaps this is some sort of optimization...

My hacky fix:

I've temporarily restored the behavior by calling some pointer events and this seems to reattach the 'pointermove' listener...

// A parent component of the resizable components   
useEffect(() => {
    const doClick = () => {
      ;['pointerdown', 'pointerup'].forEach((eventType) => {
        window.dispatchEvent(
          new PointerEvent(eventType, {
            bubbles: true,
            cancelable: true,
            view: window,
          }),
        )
      })
    }

    const timeoutId = setTimeout(doClick, 100) // Seemingly only works with a timeout

    return () => clearTimeout(timeoutId)
  }, [])
bvaughn commented 1 week ago

Someone may be willing to take a look at this if you provide a repro (pointer to runnable code that demonstrates the problem you're describing),

bvaughn commented 1 day ago

Not much info to go on here so I'm going to close this