Fix plugin .zip drop routing to Media Library uploader#256
Merged
Conversation
The OS-file-drop manager (added in 0.30.0) listens at the window level. When a user drops a .zip onto the Plugins → Upload Plugin dropzone, the inner handler called preventDefault but the event still bubbled, so the manager processed the file too and opened the Media Library uploader on top of the install dialog. Two fixes: - The drop manager now bails out of onDrop / onDragOver when ev.defaultPrevented is true. defaultPrevented is the standard signal that a closer handler has taken ownership of the file, so the manager yields. Generalises to any nested drop zone. - The plugin upload dialog's dropzone calls stopPropagation on drag/drop, and the dialog's modal overlay swallows stray drops outside the dropzone. Without this, a drop on the dropzone also fires the browse-view body handler and opens a second install dialog underneath.
Contributor
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Dropping a
.ziponto the Plugins → Upload Plugin dropzone opened the Media Library uploader on top of the install dialog instead of installing the plugin. The OS-file-drop manager (added in 0.30.0) listens at the window level; the dropzone'spreventDefaultcall wasn't enough to stop the event from bubbling and being re-processed as a media upload.What changed
src/os-file-drop/manager.ts—onDropandonDragOverbail out whenev.defaultPreventedis true. That's the standard signal that a closer handler has taken ownership of the file, so the window-level manager yields. This generalises to any nested drop zone, current or future.src/plugins-window/upload-dialog.ts— the dropzone's drag/drop listeners callstopPropagation()so the drop doesn't bubble to the Plugins browse-view body handler (which would otherwise open a second install dialog under the modal). The dialog's overlay also swallows stray drops outside the dropzone, matching modal semantics.tests/vitest/os-file-drop-manager.test.ts— new test for thedefaultPreventedskip path;afterEachnow disposes any mounted manager so the window-level sentinel doesn't leak across tests.Test plan
npm run buildcleannpm run lintclean./node_modules/.bin/tsc --noEmitcleannpm run test:js— 1465 tests pass (one new).ziponto the Upload Plugin dropzone → installs the plugin, no Media Library dialog.ziponto the dimmed overlay area outside the dropzone → nothing happens (modal swallows it)