Repository navigation
Fix the Cloudinary Gallery block preview in the iframed editor - #1368
Open
gabrielcld2 wants to merge 4 commits into
Open
gabrielcld2 wants to merge 4 commits into
gabrielcld2 wants to merge 4 commits into
Conversation
The Product Gallery library was only loaded in the outer admin document, while the block container lives in the editor canvas iframe, so the widget never found it and the preview stayed blank. Load the library in the editor canvas through enqueue_block_assets and render with the widget of the window that holds the container, with the config rebuilt in that frame so it passes the widget's validation. Also parse the block's Custom Settings JSON before merging it over the config, as the front end does, so the preview matches the published gallery.
The front end always renders a gallery with the connected cloud name and custom domain settings. The editor preview only got them on new blocks, so blocks with no or a stale cloud name showed broken images, and existing blocks ignored the custom domain.
gabrielcld2
marked this pull request as ready for review
November 11, 2026 11:56
This branch has not been deployed
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.
Fixes two issues with the Cloudinary Gallery block preview in the block editor.
The issues
The preview stays blank in the iframed editor. With the editor canvas rendered in an iframe (always the case as of WordPress 7.1), images picked for a Cloudinary Gallery block are saved and the published page shows the gallery, but the block in the editor stays on the empty Upload / Media Library placeholder, with no console error.
cld-gallery) was only enqueued in the outer admin document.editor-canvasiframe, so the widget looked the selector up in the wrong document and silently drew nothing.The preview ignores the block's Custom Settings. Custom Settings applied on the published page but never in the editor preview.
customSettingsis stored as JSON text, and the editor spread that string into the config, adding one numbered key per character.The solution
Gallery::block_editor_styles()already runs onenqueue_block_assets, which WordPress uses to collect the editor canvas assets. It now also enqueues the gallery library there, using the existingmaybe_enqueue_scripts()check andcloudinary_enqueue_gallery_scriptfilter.Edittakes a ref on the container and renders with thegalleryWidgetof the window that holds it. When that is another frame, the config is rebuilt with that frame'sJSON.parseso it passes the widget's validation. The container stays a CSS selector, resolved in the widget's own document. If the library is still loading in the canvas, rendering waits for the frame'sloadevent.CLD_GALLERY_CONFIG, as the front end does inprepare_block_render(). Before, they were only set on new blocks: a block with no or a stalecloudName(e.g. created outside the editor) previewed broken images, and existing blocks ignored the custom domain. This only affects what is rendered; the saved block is unchanged.parseCustomSettings()util decodes Custom Settings (invalid JSON, or JSON that isn't an object, is ignored). They are merged one level deep over the config, matchingwp_parse_args()on the front end: atransformationin Custom Settings replaces the block's own crop and background, as on the page.Behaviour changes
QA notes
{"transformation":{"effect":"grayscale"}}.e_grayscale).A new e2e test in
cloudinary-gallery-delivery.spec.jsopens a gallery post in the editor and checks the preview renders inside the editor canvas, with every image carrying the Custom Settings transformation. Its block markup has nocloudName, so it also covers the delivery settings fallback. It fails ondevelopon each of the two issues.