fix(desktop): prevent webview from swallowing mosaic drag events#2772
Conversation
Electron <webview> tags create separate compositor layers that capture drag events before they reach react-mosaic drop targets. This made it impossible to drag panes onto browser pane tabs. Set pointer-events:none directly on the <webview> element during any HTML5 drag operation so the compositor stops routing events to the guest process, allowing mosaic drop zones to work normally.
📝 WalkthroughWalkthroughAdded drag lifecycle handling to persistent webview elements by toggling their Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/BrowserPane/hooks/usePersistentWebview/usePersistentWebview.ts (1)
47-49: Consider guarding against abnormal drag termination.If the browser window loses focus during a drag (e.g., user Alt+Tabs away), or the drag is terminated abnormally, there's a small risk that webviews remain in
pointer-events: nonestate. Whiledragendshould fire in most cancellation scenarios (including Escape key), some edge cases in Electron/Chromium may not trigger it.A defensive approach would be to also listen for
bluronwindowto reset the state:🔧 Optional: Add blur listener as additional safeguard
window.addEventListener("dragstart", () => setWebviewsDragPassthrough(true), true); window.addEventListener("dragend", () => setWebviewsDragPassthrough(false), true); window.addEventListener("drop", () => setWebviewsDragPassthrough(false), true); +window.addEventListener("blur", () => setWebviewsDragPassthrough(false));🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/BrowserPane/hooks/usePersistentWebview/usePersistentWebview.ts` around lines 47 - 49, The drag listeners in usePersistentWebview currently set webviews to passthrough on dragstart and reset on dragend/drop but can leave webviews stuck if the window loses focus; add a window 'blur' event listener that calls setWebviewsDragPassthrough(false) as an additional safeguard, register it alongside the existing "dragstart"/"dragend"/"drop" listeners, and ensure you remove the 'blur' listener in the same cleanup/unsubscribe logic so the handler is detached when the hook/component unmounts.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/BrowserPane/hooks/usePersistentWebview/usePersistentWebview.ts`:
- Around line 47-49: The drag listeners in usePersistentWebview currently set
webviews to passthrough on dragstart and reset on dragend/drop but can leave
webviews stuck if the window loses focus; add a window 'blur' event listener
that calls setWebviewsDragPassthrough(false) as an additional safeguard,
register it alongside the existing "dragstart"/"dragend"/"drop" listeners, and
ensure you remove the 'blur' listener in the same cleanup/unsubscribe logic so
the handler is detached when the hook/component unmounts.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 0862fada-0e02-4900-be36-c2fc1105525c
📒 Files selected for processing (1)
apps/desktop/src/renderer/screens/main/components/WorkspaceView/ContentView/TabsContent/TabView/BrowserPane/hooks/usePersistentWebview/usePersistentWebview.ts
Summary
Dragging top level tabs into an active browser tab is currently broken. This fixes it.
Broken Demo (before)

Fixed Demo (after)

<webview>tags create separate compositor layers that capture drag events before they reach react-mosaic drop targetspointer-events: nonedirectly on the<webview>element during any HTML5 drag operation so the compositor stops routing events to the guest processHow it works
Native
dragstart/dragend/dropevent listeners (capture phase) togglepointer-eventson all registered webview elements. This is done at the module level inusePersistentWebviewso it covers all drag sources (tab bar drags, mosaic pane drags, etc.).The webview remains fully visible during drag — only event routing is disabled.
Test plan
Summary by cubic
Fixes pane/tab drag-and-drop onto browser tabs by stopping Electron webviews from capturing drag events so
react-mosaicdrop targets receive them.pointer-events: noneon all<webview>elements during any HTML5 drag (dragstart,dragend,drop) to bypass the guest compositor.usePersistentWebviewso it covers tab-bar and pane drags; interaction returns to normal after drag ends.Written for commit b397f44. Summary will update on new commits.
Summary by CodeRabbit