-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Openverse: prevent multiple insertions during upload #65719
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +28 B (0%) Total Size: 1.77 MB
ℹ️ View Unchanged
|
Flaky tests detected in c07f8ce. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/11086310859
|
packages/block-editor/src/components/inserter/media-tab/media-preview.js
Outdated
Show resolved
Hide resolved
Actually I'm not sure this is true. Isn't that different from the behavior of the inserter for blocks and patterns. Personally I expect a new block to be inserted each time I click on the media. Maybe we can save a cache of media elements per external image if needed but I'm not sure we should be changing how the inserter works. |
No, this is not what this PR is about... Let me try to explain differently. When using Media Experiments, the issue is this:
Of course, every time I click on the media, a new upload process should be triggered and a new block should be added. But then this block should only be added once per click, not numerous times. Hope that makes sense. If not, just install Media Experiments and try it yourself. Happy to provide a screencast otherwise... |
Yes, it does, thanks for explaining. Let me test this a bit. |
In my tests in this PR, If I click again on an image after I had added it to the post, it doesn't insert it again. Am I missing something? |
Well then this unintentional, and probably is because of #65719 (comment) where I didn't reset the ref. |
I just removed the ref now in favor of simply using |
packages/block-editor/src/components/inserter/media-tab/media-preview.js
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's very hard to trigger the "updateBlockAttributes" path at the moment. But this looks good to me and tests well.
Yeah right now it's only with the Media Experiments plugin, but eventually also with the client-side media processing experiment flag in Gutenberg (once that is merged) |
Co-authored-by: swissspidy <[email protected]> Co-authored-by: youknowriad <[email protected]>
What?
When adding an Openverse image from the inserter,
mediaUpload()
is called to upload the image to the media library.Inserting the block onto the canvas happens in the
onFileChange
callback.This callback can theoretically be called multiple times, especially in the future.
The block should only be inserted once though, and on subsequent invocations it should just update the existing block.
Why?
I noticed this while working on client-side media processing, see swissspidy/media-experiments#693 and #61447
There, the
onFileChange
callback can be fired dozens of times, which caused the block to be inserted over and over again.How?
Uses a
ref
to check whether the block has already been inserted or not.Testing Instructions
Testing Instructions for Keyboard
N/A
Screenshots or screencast