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

Invalidate getMedia resolution on success #648

Closed
swissspidy opened this issue Aug 31, 2024 · 2 comments · Fixed by #649
Closed

Invalidate getMedia resolution on success #648

swissspidy opened this issue Aug 31, 2024 · 2 comments · Fixed by #649
Labels
blocked enhancement New feature or request p2

Comments

@swissspidy
Copy link
Owner

The image block fetches the current attachment here:

https://github.com/WordPress/gutenberg/blob/e0a413d213a2a829ece52c6728515b10b0154d8d/packages/block-library/src/image/image.js#L113-L116

Which is used to render this component (<ImageSizeControl>)

Screenshot 2024-08-31 at 23 02 35

With client-side thumbnail generation, the sub-sizes aren't available yet the first time the attachment is fetched, so the component won't be rendered until the resolution is invalidated (or the page reloaded).

Something like this in should suffice:

dispatch( coreStore ).invalidateResolution( 'getMedia', [ id ] );

The right place is probably the onFileChange within editorUploadMedia

@swissspidy swissspidy added enhancement New feature or request p2 labels Aug 31, 2024
@swissspidy
Copy link
Owner Author

Actually, blockEditorUploadMedia would be better as editorUploadMedia just uploads a file, it doesn't have an onSuccess callback. Maybe need a wrapper around that in editor? 🤔 Just so it can access the coreStore

@swissspidy
Copy link
Owner Author

This might be better solved in the image component itself in an effect, so that it re-fetches the attachment when uploading is finished. Or maybe both (invalidate in onSuccess, re-fetch in effect)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked enhancement New feature or request p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant