Ensure compatibility with WordPress 7.1 - #1222
Draft
utkarshcloudinary wants to merge 4 commits into
Draft
Conversation
WordPress 7.1 enforces the iframed post editor and ships React 19. Update the Cloudinary Gallery block accordingly: - Bump the block to Block API v2 (compatible with the plugin's declared minimum of WP 5.6) and wrap the edit output with useBlockProps so it renders correctly inside the enforced iframed editor. - Keep the save output unchanged (bare container div) so existing published galleries remain valid without a deprecation/migration. The front-end render only depends on the inner container class, not a block wrapper, so no markup change is needed. - Move the block editor stylesheet to enqueue_block_assets so WP injects it into the iframe correctly (avoids the "added to the iframe incorrectly" 7.1 warning). - Move the render-time setAttributes calls into effects to resolve the React 19 "Cannot update a component while rendering a different component" warning. - Fix the generated container id, which produced "undefined<id>" now that className is no longer passed to Edit under API v2. Verified against WordPress 7.1-beta3: fresh insert/save/reload and the upgrade path (loading legacy v1 content) both validate with no console errors or block validation warnings.
The Cloudinary inspector controls added to core/image and core/video blocks had two WordPress 7.1 issues: - setAttributes was called during render when the attachment had transformations, which triggers the React 19 "Cannot update a component while rendering a different component" warning. Moved into an effect. - The controls read InspectorControls from the deprecated wp.editor alias. Switched to wp.blockEditor and declared the script dependencies explicitly, since the block editor globals were previously relied on without being registered.
The gallery settings page enqueued js/gallery.js under two handles: 'gallery_config' in enqueue_admin_scripts() and 'gallery-widget' via the React UI component's script param. The bundle executed twice, calling createRoot() twice on the same container, which React 19 (WordPress 7.1) reports as an error on every settings page load. Drop the script param from the React panel definition and keep the single enqueue that already carries the generated asset dependencies.
src/js/blocks.js and its components accessed @WordPress packages through the wp.* globals (wp.hooks, wp.blockEditor), which the dependency extraction plugin cannot detect, so js/block-editor.asset.php was missing wp-block-editor and wp-hooks. The hand-written dependency list in class-video.php compensated for those but omitted wp-api-fetch, which blocks.js genuinely imports and only worked because other editor scripts loaded it first. Convert the wp.hooks/wp.blockEditor global usages to @wordpress/hooks and @wordpress/block-editor imports so the generated asset file is complete, and consume it in enqueue_block_assets() instead of the static list.
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.
Approach
WordPress 7.1 (scheduled 19 Aug 2026) enforces the iframed block editor for block themes and ships React 19. Tested against 7.1-beta3 and fixed the incompatibilities found:
Gallery block
editoutput inuseBlockProps()so it renders inside the enforced iframe.enqueue_block_editor_assetstoenqueue_block_assetsso WP injects it into the editor iframe correctly.setAttributes()calls intouseEffect(React 19 warns on state updates during render).undefined<id>under API v2, sinceclassNameis no longer passed toEdit.wp-editor(deprecated) dependency list forgallery-block.jswith the webpack-generatedgallery-block.asset.phpdependencies.Core image/video inspector
setAttributes()intouseEffect.InspectorControlsfrom the deprecatedwp.editoralias towp.blockEditor, then converted thewp.hooks/wp.blockEditorglobal usages to proper@wordpress/hooks/@wordpress/block-editorimports so the dependency extraction plugin detects them.class-video.phpnow consumes the generatedblock-editor.asset.phpinstead of a hand-written dependency list. The previous static list compensated for the globals the extraction plugin couldn't see, but omittedwp-api-fetch(a real import inblocks.js) which only worked because other editor scripts loaded it first.Gallery settings page
js/gallery.js(loaded under both thegallery_configandgallery-widgethandles), which executed the bundle twice and calledcreateRoot()twice on the same container — reported as a console error by React 19 on every settings page load. Pre-existing issue surfaced by the React 19 testing.Design decisions
Why block API v2 and not v3?
readme.txtdeclaresRequires at least: 5.6. API v2 is supported since WP 5.6 and is iframe-compatible, so it satisfies 7.1 without dropping supported versions. API v3 requires WP 6.3+ and would break 5.6–6.2. WP 6.9+ logs a console deprecation nudging blocks to v3; that's cosmetic and can be revisited when the plugin's minimum WP version is raised.Why no shims for React 19 vs React 17 (WP 5.6)? React ships with core and is consumed only via
@wordpress/element.useEffectanduseBlockPropsboth exist in 5.6, so one codebase covers 5.6 → 7.1. The single standalone React root (settings-gallery.js) already had acreateRoot-with-renderfallback.Why no block deprecation entry? The save markup is unchanged (bare container div, no
useBlockProps.save()wrapper). The front-end render only mounts the widget into'.' + attributes.containerand never depends on a block wrapper class. With identical save output, old content stays valid by definition — verified by loading legacy v1 markup under the new code (isValid: true, zero validation warnings).Known follow-up:
editor.MediaUploadfilter infeatured-image.jsextends core's class component. Core still ships it as a class (kept deliberately for plugin compat) but has deprecated the pattern; migrating to composition is future work, not a 7.1 blocker.QA notes
Environment: wp-env with
core: https://wordpress.org/wordpress-7.1-beta3.zip, PHP 8.2,WP_DEBUG+SCRIPT_DEBUG, twentytwentyfive (block theme, so the editor iframe is enforced).undefinedprefix.isValid: trueand zero validation warnings.overwrite_transformationsattributes exist on both block types and theeditor.MediaUploadfeatured-image filter is registered....was added to the iframe incorrectlywarning forcloudinary-gallery-block-css.js/gallery.jsloads only once, and there is nocreateRoot()console error.