Skip to content
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

Fix conflict with Openverse #693

Closed
swissspidy opened this issue Sep 25, 2024 · 1 comment
Closed

Fix conflict with Openverse #693

swissspidy opened this issue Sep 25, 2024 · 1 comment
Labels
bug Something isn't working p1

Comments

@swissspidy
Copy link
Owner

swissspidy commented Sep 25, 2024

I just tried uploading an image from Openverse and it inserted the same image like dozens of times. There must be some infinite loop somewhere. Interestingly, it was only uploaded once though.

Also, the image is named undefined.jpeg, so there must be something wrong going on there too.

@swissspidy swissspidy added bug Something isn't working p1 labels Sep 25, 2024
swissspidy added a commit that referenced this issue Sep 27, 2024
@swissspidy
Copy link
Owner Author

Also, the image is named undefined.jpeg, so there must be something wrong going on there too.

This should be resolved by WordPress/gutenberg#65693 and e419aa9

I just tried uploading an image from Openverse and it inserted the same image like dozens of times.

OK the issue is basically this:

When you insert an Openverse image, it calls settings.mediaUpload to upload the image here:

https://github.com/WordPress/gutenberg/blob/ebb58c858addf8268d1c171b9ac85f4b55e0553b/packages/block-editor/src/components/inserter/media-tab/media-preview.js#L170-L199

In the onFileChange callback it calls onClick / onInsert which eventually calls the insertBlocks action from the block-editor store:

https://github.com/WordPress/gutenberg/blob/ebb58c858addf8268d1c171b9ac85f4b55e0553b/packages/block-editor/src/components/inserter/menu.js#L90-L114

In other words, every time onFileChange is called, a new block is inserted (but with the same client ID*)

In Gutenberg right now the callback is only fired once. But in media experiments with client-side thumbnail generation, it can be fired numerous times.

Proposed fix: adding the Openverse image should only insert it once, and subsequent onFileChange calls would just update the existing block. Maybe the insertion needs to be moved out of onFileChange?

This is something that needs to be figured out as part of the migration to Gutenberg (see also #561)

@ntsekouras @youknowriad Any thoughts on how this can be best fixed in Gutenberg?


* This leads to some fun UI quirks btw 😄

Screenshot 2024-09-27 at 11 17 53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working p1
Projects
None yet
Development

No branches or pull requests

1 participant