Skip to content

[v2] fix: Files DragAndDrop bugs with OnDomReady and DisableWebViewDrop - #4743

Closed
leaanthony wants to merge 2 commits into
masterfrom
claude/investigate-fix-issue-01Er6YmLxZvbLYhZSQkJvjg7
Closed

[v2] fix: Files DragAndDrop bugs with OnDomReady and DisableWebViewDrop#4743
leaanthony wants to merge 2 commits into
masterfrom
claude/investigate-fix-issue-01Er6YmLxZvbLYhZSQkJvjg7

Conversation

@leaanthony

Copy link
Copy Markdown
Member

Summary

Fixes #3563

This PR addresses two critical issues with file drag-and-drop functionality:

  1. OnDomReady triggering on every drag-and-drop: When EnableFileDrop: true, dropping files would trigger OnDomReady multiple times because the browser's default behavior (navigating to the dropped file) wasn't prevented early enough.

  2. EnableFileDrop + DisableWebViewDrop conflict: When both options were enabled together on Windows, file dropping stopped working entirely.

Root Cause

  • JavaScript drag/drop event handlers that call e.preventDefault() were only registered when the user called runtime.OnFileDrop()
  • There's a timing gap between page load and when OnFileDrop() is called (typically in the OnDomReady handler)
  • During this gap, if a file is dropped, the browser's default behavior kicks in - navigating to the dropped file (file:///path/to/file.txt)
  • This navigation triggers OnDomReady again

The Fix

1. Early handler registration (JavaScript)

  • Added setup() function in draganddrop.js that registers drag/drop handlers immediately
  • Called from main.js during runtime initialization (before runtime:ready)
  • Handlers prevent default for file drops even before the user registers a callback
  • Runs on every DOM load to ensure handlers are always registered

2. Windows AllowExternalDrag fix

  • Only disable AllowExternalDrag when DisableWebViewDrop: true AND EnableFileDrop: false
  • When both are true, drag events need to flow to JavaScript

Test plan

  • Test drag-and-drop with EnableFileDrop: true - verify OnDomReady only fires once
  • Test with both EnableFileDrop: true and DisableWebViewDrop: true on Windows
  • Test on Linux and macOS to ensure no regressions
  • Verify file drop callbacks still work correctly

🤖 Generated with Claude Code

claude and others added 2 commits December 1, 2025 08:40
This commit fixes the issues reported in #3563:

1. OnDomReady triggering multiple times during drag-and-drop:
   - Root cause: When files are dropped without proper event handling, the
     browser navigates to the dropped file, triggering navigation completion
     callbacks and thus OnDomReady again.
   - Fix: Register drag/drop event handlers early in the runtime JavaScript
     (main.js) before the user has a chance to drop files. These handlers
     call e.preventDefault() for file drops, preventing browser navigation.
   - Added setup() function in draganddrop.js that's called from main.js.
   - Additionally added OnDomReady single-fire guards on all platforms as
     a safety measure.

2. DisableWebViewDrop + EnableFileDrop conflict on Windows:
   - When both options were enabled, AllowExternalDrag(false) was called,
     which blocked ALL drag events including the ones needed for file drops.
   - Now only calls AllowExternalDrag(false) when DisableWebViewDrop is true
     AND EnableFileDrop is false.

Platform-specific changes:
- Windows: Fixed navigationCompleted to only call OnDomReady once
- Linux: Added domReadySent flag to prevent multiple DomReady messages
- macOS: Added domReadySent property to track if DomReady was sent

Fixes #3563
The previous fix was over-engineered. It suppressed OnDomReady events
on all platforms to prevent multiple calls during file drops. However,
users may have legitimate use cases for OnDomReady being called on
navigation/reload.

This simplified fix:
- Keeps the JavaScript setup() that runs on each DOM load to register
  drag handlers early (preventing browser navigation on file drops)
- Keeps the Windows AllowExternalDrag fix for EnableFileDrop+DisableWebViewDrop
- Removes the OnDomReady suppression on macOS, Linux, and Windows

The core insight is that by preventing browser navigation on file drops
via JavaScript, the page won't reload, so OnDomReady won't fire extra
times in the problematic scenario anyway.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 1, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/investigate-fix-issue-01Er6YmLxZvbLYhZSQkJvjg7

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

sonarqubecloud Bot commented Dec 1, 2025

Copy link
Copy Markdown

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying wails with  Cloudflare Pages  Cloudflare Pages

Latest commit: ae04fea
Status: ✅  Deploy successful!
Preview URL: https://2d7db912.wails.pages.dev
Branch Preview URL: https://claude-investigate-fix-issue.wails.pages.dev

View logs

@leaanthony

Copy link
Copy Markdown
Member Author

Thanks for the drag-and-drop implementation. Some of this overlaps with newer platform-specific work, and the test plan is not yet complete, so I’m closing this draft to avoid duplicate paths. Any remaining gaps can be addressed in a focused follow-up PR.

@leaanthony leaanthony closed this Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v2] Files DragAndDrop bugs

2 participants