fix(runtime): file drop not working with @wailsio/runtime npm module#4953
Conversation
The Go backend was calling window.wails.Window.HandlePlatformFileDrop() for native file drops on macOS/Linux. This only worked with the bundled runtime which sets window.wails = Runtime. When using the @wailsio/runtime npm module, window.wails is an empty object because the npm module only exports via ES modules and registers the handler at window._wails.handlePlatformFileDrop. Changed the Go code to call the internal path that both runtime distributions set up: window._wails.handlePlatformFileDrop() Also added a test case that uses the npm module to verify the fix. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
|
Caution Review failedThe pull request is closed. WalkthroughChanged the JS bridge call used by the Go backend for native file drops from Changes
Sequence Diagram(s)sequenceDiagram
participant Go as Go backend
participant Webview as WebView/Eval
participant Runtime as window._wails
participant Frontend as App frontend
rect rgba(60,130,200,0.5)
Go->>Webview: Eval JS -> call window._wails.handlePlatformFileDrop(filesJSON, x, y)
end
rect rgba(80,160,80,0.5)
Webview->>Runtime: invoke handlePlatformFileDrop(...)
Runtime->>Frontend: emit "files-dropped" (files + details)
Frontend->>Frontend: categorize files and update UI
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
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 |
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes native file drag-and-drop failures when apps use the @wailsio/runtime npm package (instead of the bundled /wails/runtime.js) by switching the backend’s JS invocation to the runtime hook that exists in both distributions.
Changes:
- Updated the drop-processing JS call to use
window._wails.handlePlatformFileDrop(...)instead ofwindow.wails.Window.HandlePlatformFileDrop(...). - Added a new manual test app under
v3/test/dnd-npm-runtime/that bundles a small Vite frontend using@wailsio/runtime. - Documented how to build/run the new test case.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
v3/pkg/application/webview_window.go |
Switches the JS call used for native file drops to window._wails.handlePlatformFileDrop for compatibility with both runtime distributions. |
v3/test/dnd-npm-runtime/main.go |
New test harness app that enables file drop and forwards drop info to the frontend. |
v3/test/dnd-npm-runtime/README.md |
Instructions/background for reproducing and validating the fix using the npm runtime. |
v3/test/dnd-npm-runtime/frontend/package.json |
Frontend dependencies including @wailsio/runtime and Vite. |
v3/test/dnd-npm-runtime/frontend/vite.config.js |
Vite build output configuration (dist). |
v3/test/dnd-npm-runtime/frontend/index.html |
UI for the drop target and display buckets. |
v3/test/dnd-npm-runtime/frontend/main.js |
Uses @wailsio/runtime Events to display dropped files and drop target details. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Required for go:embed to work in CI. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
|
…ailsapp#4953) * fix(runtime): use internal path for HandlePlatformFileDrop The Go backend was calling window.wails.Window.HandlePlatformFileDrop() for native file drops on macOS/Linux. This only worked with the bundled runtime which sets window.wails = Runtime. When using the @wailsio/runtime npm module, window.wails is an empty object because the npm module only exports via ES modules and registers the handler at window._wails.handlePlatformFileDrop. Changed the Go code to call the internal path that both runtime distributions set up: window._wails.handlePlatformFileDrop() Also added a test case that uses the npm module to verify the fix. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * docs: add changelog entry for npm runtime DND fix Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * chore: add built frontend dist for dnd-npm-runtime test Required for go:embed to work in CI. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * docs: update README to reflect pre-built frontend Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>


Problem
When using the
@wailsio/runtimenpm module (instead of the bundled/wails/runtime.js), native file drag-and-drop on macOS/Linux fails with:Root Cause
The Go backend calls
window.wails.Window.HandlePlatformFileDrop()for native file drops, but:window.wails.Window.HandlePlatformFileDropwindow._wails.handlePlatformFileDrop/wails/runtime.js)@wailsio/runtime)The bundled runtime sets
window.wails = Runtime, so both paths work. The npm module only exports via ES modules and registers the handler at the internalwindow._wailspath.Solution
Changed the Go code to call the internal path that both runtime distributions set up:
This is consistent with other drag handlers (
handleDragEnter,handleDragLeave,handleDragOver) which already use thewindow._wailspath.Testing
Added
v3/test/dnd-npm-runtime/- a test case that uses the npm module to verify the fix works:Notes
Summary by CodeRabbit
Bug Fixes
Tests
Documentation