wails/v3/test/dnd-npm-runtime
Lea Anthony c0d2c1e237
fix(runtime): file drop not working with @wailsio/runtime npm module (#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>
2026-02-04 07:25:09 +11:00
..
frontend fix(runtime): file drop not working with @wailsio/runtime npm module (#4953) 2026-02-04 07:25:09 +11:00
main.go fix(runtime): file drop not working with @wailsio/runtime npm module (#4953) 2026-02-04 07:25:09 +11:00
README.md fix(runtime): file drop not working with @wailsio/runtime npm module (#4953) 2026-02-04 07:25:09 +11:00

DND NPM Runtime Test

This test verifies that drag-and-drop functionality works correctly when using the @wailsio/runtime npm module instead of the bundled /wails/runtime.js.

Background

There was a bug where the Go backend called window.wails.Window.HandlePlatformFileDrop() for native file drops (macOS/Linux), but the npm module only registers the handler at window._wails.handlePlatformFileDrop.

The bundled runtime sets window.wails = Runtime, so the call worked. But with the npm module, window.wails is an empty object.

The Fix

Changed v3/pkg/application/webview_window.go to call the internal path that both runtimes set up:

// Before (only worked with bundled runtime):
"window.wails.Window.HandlePlatformFileDrop(%s, %d, %d);"

// After (works with both):
"window._wails.handlePlatformFileDrop(%s, %d, %d);"

Running the Test

The frontend is pre-built, so you can run directly:

go run .

Then drag files from Finder/Explorer onto the drop zone. Files should be categorized and displayed.

Rebuilding the Frontend (optional)

Only needed if you modify the frontend code:

cd frontend
npm install
npm run build

What This Tests

  1. @wailsio/runtime npm module initialization
  2. Event system (Events.On('files-dropped', ...))
  3. Native file drop handling on macOS/Linux via window._wails.handlePlatformFileDrop
  4. Drop target detection with data-file-drop-target attribute
  5. Visual feedback with .file-drop-target-active class