[v2] fix: Files DragAndDrop bugs with OnDomReady and DisableWebViewDrop
Summary
Fixes #3563
This PR addresses two critical issues with file drag-and-drop functionality:
-
OnDomReady triggering on every drag-and-drop: When
EnableFileDrop: true, dropping files would triggerOnDomReadymultiple times because the browser's default behavior (navigating to the dropped file) wasn't prevented early enough. -
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 calledruntime.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 indraganddrop.jsthat registers drag/drop handlers immediately - Called from
main.jsduring runtime initialization (beforeruntime: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
AllowExternalDragwhenDisableWebViewDrop: trueANDEnableFileDrop: 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: trueandDisableWebViewDrop: trueon Windows - [ ] Test on Linux and macOS to ensure no regressions
- [ ] Verify file drop callbacks still work correctly
🤖 Generated with Claude Code
[!IMPORTANT]
Review skipped
Draft detected.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein 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.
Comment @coderabbitai help to get the list of available commands and usage tips.
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
Deploying wails with
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 |