From 67cd2c12bca16abd16073d8af6c518e1655dd06f Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Tue, 24 Nov 2026 20:42:02 -0500 Subject: [PATCH 1/9] feat: add placeholder for unsupported VideoPress blocks Shows a read-only preview and an explanation in place of core's missing block warning, so the block's markup is kept as is. Co-Authored-By: Claude Opus 5.5 --- .../videopress-unsupported/index.jsx | 87 +++++++++++++++ .../videopress-unsupported/index.test.jsx | 102 ++++++++++++++++++ .../videopress-unsupported/style.scss | 21 ++++ 3 files changed, 210 insertions(+) create mode 100644 src/components/videopress-unsupported/index.jsx create mode 100644 src/components/videopress-unsupported/index.test.jsx create mode 100644 src/components/videopress-unsupported/style.scss diff --git a/src/components/videopress-unsupported/index.jsx b/src/components/videopress-unsupported/index.jsx new file mode 100644 index 000000000..9228ae6d3 --- /dev/null +++ b/src/components/videopress-unsupported/index.jsx @@ -0,0 +1,87 @@ +import { useBlockProps } from '@wordpress/block-editor'; +import { parse } from '@wordpress/block-serialization-default-parser'; +import { Notice, SandBox, Spinner } from '@wordpress/components'; +import { store as coreStore } from '@wordpress/core-data'; +import { useSelect } from '@wordpress/data'; +import { useMemo } from '@wordpress/element'; +import { __, sprintf } from '@wordpress/i18n'; +import './style.scss'; + +/** + * Placeholder for a `videopress/video` block the editor doesn't allow. + * + * Shows a non-interactive preview of the video and explains that its settings + * can't be edited. The block keeps its original markup. + * + * @param {Object} props Block edit props. + * @param {Object} props.attributes `core/missing` attributes, including the + * block's original markup. + * + * @return {Element} The placeholder. + */ +export default function VideoPressUnsupported( { attributes } ) { + const blockProps = useBlockProps( { + className: 'gutenberg-kit-videopress-unsupported', + } ); + const guid = useMemo( + () => getGuid( attributes.originalContent ), + [ attributes.originalContent ] + ); + const url = guid ? `https://videopress.com/v/${ guid }` : undefined; + + // Core-data fetches `/oembed/1.0/proxy` and caches the result, so moving + // the block or remounting it doesn't fetch again. A failed fetch is `false`. + const preview = useSelect( + ( select ) => + url ? select( coreStore ).getEmbedPreview( url ) : false, + [ url ] + ); + const isLoading = preview === undefined; + + return ( +
+ { preview?.html ? ( +
+ +
+ ) : ( +
+ { isLoading && } +
+ ) } + + { __( + "VideoPress video settings can't be edited in the app yet. This video is kept as is. To change its settings, edit the post on the web.", + 'gutenberg-kit' + ) } + +
+ ); +} + +/** + * Reads the VideoPress guid from the block's original markup. + * + * @param {string} [originalContent] The block's original markup. + * + * @return {string|undefined} The guid, if valid. + */ +function getGuid( originalContent ) { + const [ block ] = parse( originalContent ?? '' ); + const guid = block?.attrs?.guid; + + // Guids are alphanumeric; anything else would alter the embed URL. + return typeof guid === 'string' && /^[a-z0-9]+$/i.test( guid ) + ? guid + : undefined; +} diff --git a/src/components/videopress-unsupported/index.test.jsx b/src/components/videopress-unsupported/index.test.jsx new file mode 100644 index 000000000..cca2e05df --- /dev/null +++ b/src/components/videopress-unsupported/index.test.jsx @@ -0,0 +1,102 @@ +import { describe, it, expect, vi, beforeEach } from 'vitest'; +import { render, screen } from '@testing-library/react'; +import { useSelect } from '@wordpress/data'; +import VideoPressUnsupported from '.'; + +vi.mock( '@wordpress/block-editor', () => ( { + useBlockProps: ( props ) => props, +} ) ); + +vi.mock( '@wordpress/components', () => ( { + Notice: ( { children } ) =>
{ children }
, + SandBox: ( { html } ) =>
{ html }
, + Spinner: () =>
, +} ) ); + +vi.mock( '@wordpress/core-data', () => ( { store: 'core' } ) ); + +vi.mock( '@wordpress/data', () => ( { useSelect: vi.fn() } ) ); + +const ORIGINAL_CONTENT = + ''; + +describe( 'VideoPressUnsupported', () => { + let getEmbedPreview; + + beforeEach( () => { + getEmbedPreview = vi.fn(); + useSelect.mockImplementation( ( callback ) => + callback( () => ( { getEmbedPreview } ) ) + ); + } ); + + it( "requests the preview for the block's guid", () => { + renderPlaceholder(); + + expect( getEmbedPreview ).toHaveBeenCalledWith( + 'https://videopress.com/v/AbC123xy' + ); + } ); + + it( 'shows a spinner while the preview loads', () => { + getEmbedPreview.mockReturnValue( undefined ); + + renderPlaceholder(); + + expect( screen.getByTestId( 'spinner' ) ).toBeInTheDocument(); + expect( screen.queryByTestId( 'sandbox' ) ).not.toBeInTheDocument(); + } ); + + it( 'renders the preview once loaded', () => { + getEmbedPreview.mockReturnValue( { html: '' } ); + + renderPlaceholder(); + + expect( screen.getByTestId( 'sandbox' ) ).toHaveTextContent( + '' + ); + expect( screen.queryByTestId( 'spinner' ) ).not.toBeInTheDocument(); + } ); + + it( 'shows an empty box when the preview fails', () => { + getEmbedPreview.mockReturnValue( false ); + + renderPlaceholder(); + + expect( screen.queryByTestId( 'spinner' ) ).not.toBeInTheDocument(); + expect( screen.queryByTestId( 'sandbox' ) ).not.toBeInTheDocument(); + } ); + + it.each( [ + [ 'no guid', '' ], + [ + 'an invalid guid', + '', + ], + [ 'no markup', null ], + ] )( 'skips the preview request for %s', ( _, originalContent ) => { + renderPlaceholder( originalContent ); + + expect( getEmbedPreview ).not.toHaveBeenCalled(); + expect( screen.queryByTestId( 'spinner' ) ).not.toBeInTheDocument(); + } ); + + it( 'explains that the settings are not editable', () => { + renderPlaceholder(); + + expect( screen.getByTestId( 'notice' ) ).toHaveTextContent( + "VideoPress video settings can't be edited in the app yet." + ); + } ); +} ); + +function renderPlaceholder( originalContent = ORIGINAL_CONTENT ) { + render( + + ); +} diff --git a/src/components/videopress-unsupported/style.scss b/src/components/videopress-unsupported/style.scss new file mode 100644 index 000000000..72a4dd0c6 --- /dev/null +++ b/src/components/videopress-unsupported/style.scss @@ -0,0 +1,21 @@ +.gutenberg-kit-videopress-unsupported { + margin-left: 0; + margin-right: 0; + + // Like core's embed overlay: taps select the block instead of playing. + &__preview { + pointer-events: none; + } + + &__placeholder { + align-items: center; + aspect-ratio: 16 / 9; + background-color: #000; + display: flex; + justify-content: center; + } + + .components-notice { + margin: 8px 0 0; + } +} From 16f7d6d49b4cf26831b8e833a61430bf4ce9c4ab Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Tue, 24 Nov 2026 20:42:07 -0500 Subject: [PATCH 2/9] fix: remove Jetpack's VideoPress to Video block conversion With videopress/video disallowed, Jetpack converts each block to core/video on open, dropping its VideoPress settings and marking the post as changed. Warns if the filter goes missing while Jetpack VideoPress is active, in case it was renamed. Co-Authored-By: Claude Opus 5.5 --- src/utils/videopress-unsupported.js | 88 ++++++++++++++++ src/utils/videopress-unsupported.test.jsx | 122 ++++++++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 src/utils/videopress-unsupported.js create mode 100644 src/utils/videopress-unsupported.test.jsx diff --git a/src/utils/videopress-unsupported.js b/src/utils/videopress-unsupported.js new file mode 100644 index 000000000..84dfa6340 --- /dev/null +++ b/src/utils/videopress-unsupported.js @@ -0,0 +1,88 @@ +import { createHigherOrderComponent } from '@wordpress/compose'; +import { createElement } from '@wordpress/element'; +import { addFilter, hasFilter, removeFilter } from '@wordpress/hooks'; +import VideoPressUnsupported from '../components/videopress-unsupported'; +import { debug, warn } from './logger'; + +/** + * Jetpack's filter that replaces each unsupported `videopress/video` block with + * a `core/video` block on render, dropping the VideoPress-only attributes. + */ +const CONVERSION_FILTER = 'videopress/jetpack-convert-from-v6-to-v5'; + +/** + * Jetpack's `core/video` VideoPress extension, present whenever Jetpack + * VideoPress is active. + */ +const VIDEOPRESS_EXTENSION_FILTER = 'jetpack/videopress'; + +/** + * Keeps `videopress/video` blocks as they are when the editor doesn't allow + * the block type, and shows a placeholder for them. + * + * Without this, Jetpack converts each block to `core/video` as the post opens, + * so an untouched post reports changes and the host saves the conversion. + * + * Must run before the editor's first render: `withFilters` renders once more + * with a removed filter, which is enough to convert the block. + * + * @todo Remove once the `videopress/video` block type is allowed and stable. + * + * @return {void} + */ +export function initializeVideoPressUnsupportedBlock() { + const removedConversion = + removeFilter( 'editor.BlockListBlock', CONVERSION_FILTER ) > 0; + + if ( ! removedConversion ) { + if ( + ! hasFilter( + 'blocks.registerBlockType', + VIDEOPRESS_EXTENSION_FILTER + ) + ) { + // No Jetpack VideoPress on this site. + return; + } + + warn( + `VideoPress: Jetpack's "${ CONVERSION_FILTER }" filter wasn't found. If it was renamed, VideoPress blocks may convert to Video blocks on open.` + ); + } + + addFilter( + 'editor.BlockEdit', + 'gutenberg-kit/videopress-unsupported', + withVideoPressUnsupportedPlaceholder + ); + + debug( 'VideoPress unsupported block placeholder initialized' ); +} + +/** + * Renders the placeholder in place of the default edit UI for unsupported + * `videopress/video` blocks. + */ +const withVideoPressUnsupportedPlaceholder = createHigherOrderComponent( + ( BlockEdit ) => ( props ) => + isUnsupportedVideoPressBlock( props ) + ? createElement( VideoPressUnsupported, props ) + : createElement( BlockEdit, props ), + 'withVideoPressUnsupportedPlaceholder' +); + +/** + * Whether the block is a `videopress/video` block parsed as `core/missing`. + * + * @param {Object} props Block edit props. + * @param {string} props.name Block name. + * @param {Object} props.attributes Block attributes. + * + * @return {boolean} Whether the block is an unsupported VideoPress block. + */ +function isUnsupportedVideoPressBlock( { name, attributes } ) { + return ( + name === 'core/missing' && + attributes?.originalName === 'videopress/video' + ); +} diff --git a/src/utils/videopress-unsupported.test.jsx b/src/utils/videopress-unsupported.test.jsx new file mode 100644 index 000000000..26a1173ae --- /dev/null +++ b/src/utils/videopress-unsupported.test.jsx @@ -0,0 +1,122 @@ +import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'; +import { render, screen } from '@testing-library/react'; +import { + addFilter, + applyFilters, + hasFilter, + removeAllFilters, +} from '@wordpress/hooks'; +import { initializeVideoPressUnsupportedBlock } from './videopress-unsupported'; +import { warn } from './logger'; + +vi.mock( './logger' ); + +vi.mock( '../components/videopress-unsupported', () => ( { + default: () =>
, +} ) ); + +const identity = ( component ) => component; + +describe( 'initializeVideoPressUnsupportedBlock', () => { + beforeEach( () => { + vi.clearAllMocks(); + } ); + + afterEach( () => { + removeAllFilters( 'editor.BlockListBlock' ); + removeAllFilters( 'blocks.registerBlockType' ); + removeAllFilters( 'editor.BlockEdit' ); + } ); + + it( "removes Jetpack's conversion filter", () => { + addJetpackFilters(); + + initializeVideoPressUnsupportedBlock(); + + expect( + hasFilter( + 'editor.BlockListBlock', + 'videopress/jetpack-convert-from-v6-to-v5' + ) + ).toBe( false ); + expect( warn ).not.toHaveBeenCalled(); + } ); + + it( "warns when Jetpack's extension is present but the conversion filter is missing", () => { + addFilter( 'blocks.registerBlockType', 'jetpack/videopress', identity ); + + initializeVideoPressUnsupportedBlock(); + + expect( warn ).toHaveBeenCalledTimes( 1 ); + expect( + hasFilter( + 'editor.BlockEdit', + 'gutenberg-kit/videopress-unsupported' + ) + ).toBe( true ); + } ); + + it( 'does nothing when Jetpack VideoPress is absent', () => { + initializeVideoPressUnsupportedBlock(); + + expect( warn ).not.toHaveBeenCalled(); + expect( + hasFilter( + 'editor.BlockEdit', + 'gutenberg-kit/videopress-unsupported' + ) + ).toBe( false ); + } ); + + it( 'renders the placeholder for unsupported VideoPress blocks', () => { + addJetpackFilters(); + initializeVideoPressUnsupportedBlock(); + + renderBlockEdit( { + name: 'core/missing', + attributes: { originalName: 'videopress/video' }, + } ); + + expect( + screen.getByTestId( 'videopress-unsupported' ) + ).toBeInTheDocument(); + expect( screen.queryByTestId( 'block-edit' ) ).not.toBeInTheDocument(); + } ); + + it.each( [ + [ + 'other missing blocks', + { + name: 'core/missing', + attributes: { originalName: 'some/block' }, + }, + ], + [ 'core/video blocks', { name: 'core/video', attributes: {} } ], + ] )( 'passes %s through unchanged', ( _, props ) => { + addJetpackFilters(); + initializeVideoPressUnsupportedBlock(); + + renderBlockEdit( props ); + + expect( screen.getByTestId( 'block-edit' ) ).toBeInTheDocument(); + expect( + screen.queryByTestId( 'videopress-unsupported' ) + ).not.toBeInTheDocument(); + } ); +} ); + +function addJetpackFilters() { + addFilter( + 'editor.BlockListBlock', + 'videopress/jetpack-convert-from-v6-to-v5', + identity + ); + addFilter( 'blocks.registerBlockType', 'jetpack/videopress', identity ); +} + +function renderBlockEdit( props ) { + const BlockEdit = applyFilters( 'editor.BlockEdit', () => ( +
+ ) ); + render( ); +} From 05697cfd2cff6461d984e4f4d3328596f2cf64c1 Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Tue, 24 Nov 2026 20:42:13 -0500 Subject: [PATCH 3/9] fix: keep VideoPress blocks unchanged when opening a post Runs the initializer after plugin scripts load and before the first render; removing the filter later doesn't stop the conversion. Co-Authored-By: Claude Opus 5.5 --- src/utils/editor-environment.js | 7 +++++++ src/utils/editor-environment.test.js | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/utils/editor-environment.js b/src/utils/editor-environment.js index 0afb27e1c..5331eaad5 100644 --- a/src/utils/editor-environment.js +++ b/src/utils/editor-environment.js @@ -176,6 +176,13 @@ async function initializeEditor( pluginLoadResult = {} ) { // The VideoPress block isn't available, so initialize the bridge to handle // any `core/video` blocks extended to rely upon VideoPress upload services. initializeVideoPressAjaxBridge(); + + // Lazy-loaded, like the editor, so its components see the configured + // locale and globals. Must run before the editor renders. + const { initializeVideoPressUnsupportedBlock } = await import( + './videopress-unsupported' + ); + initializeVideoPressUnsupportedBlock(); } await _initializeEditor( { diff --git a/src/utils/editor-environment.test.js b/src/utils/editor-environment.test.js index a6c103021..218e8ca63 100644 --- a/src/utils/editor-environment.test.js +++ b/src/utils/editor-environment.test.js @@ -14,6 +14,7 @@ import EditorLoadError from '../components/editor-load-error/index.jsx'; import { error } from './logger.js'; import { configureAjax } from './ajax.js'; import { initializeVideoPressAjaxBridge } from './videopress-bridge.js'; +import { initializeVideoPressUnsupportedBlock } from './videopress-unsupported.js'; import { initializeWordPressGlobals } from './wordpress-globals.js'; import { configureLocale } from './localization.js'; import { configureAdminGlobals } from './admin-globals.js'; @@ -33,6 +34,9 @@ vi.mock( './logger.js' ); vi.mock( './editor-styles.js' ); vi.mock( './ajax.js' ); vi.mock( './videopress-bridge.js' ); +vi.mock( './videopress-unsupported.js', () => ( { + initializeVideoPressUnsupportedBlock: vi.fn(), +} ) ); vi.mock( './wordpress-globals.js', () => ( { initializeWordPressGlobals: vi.fn(), @@ -126,6 +130,10 @@ describe( 'setUpEditorEnvironment', () => { callOrder.push( 'initializeVideoPressAjaxBridge' ); } ); + initializeVideoPressUnsupportedBlock.mockImplementation( () => { + callOrder.push( 'initializeVideoPressUnsupportedBlock' ); + } ); + initializeEditor.mockImplementation( () => { callOrder.push( 'initializeEditor' ); } ); @@ -143,6 +151,7 @@ describe( 'setUpEditorEnvironment', () => { 'configureApiFetch', 'configureAjax', 'initializeVideoPressAjaxBridge', + 'initializeVideoPressUnsupportedBlock', 'initializeEditor', ] ); } ); @@ -268,6 +277,9 @@ describe( 'setUpEditorEnvironment', () => { expect( configureAjax ).toHaveBeenCalledTimes( 1 ); expect( initializeVideoPressAjaxBridge ).toHaveBeenCalledTimes( 1 ); + expect( initializeVideoPressUnsupportedBlock ).toHaveBeenCalledTimes( + 1 + ); } ); it( 'skips VideoPress bridge when videopress/video is in allowed block types', async () => { @@ -280,6 +292,7 @@ describe( 'setUpEditorEnvironment', () => { expect( configureAjax ).toHaveBeenCalledTimes( 1 ); expect( initializeVideoPressAjaxBridge ).not.toHaveBeenCalled(); + expect( initializeVideoPressUnsupportedBlock ).not.toHaveBeenCalled(); } ); it( 'initializes VideoPress bridge when allowed block types is undefined', async () => { From 73be7dd48817992cc615fdd32a603d86ddf4a428 Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Tue, 24 Nov 2026 21:02:22 -0500 Subject: [PATCH 4/9] fix: attach the VideoPress notice to the video as a caption The separate notice card read as its own block, apart from the video. A themed caption joined to the video reads as one unit and follows the theme's colors. Co-Authored-By: Claude Opus 5.5 --- .../videopress-unsupported/index.jsx | 18 +++++++++------ .../videopress-unsupported/index.test.jsx | 9 ++++---- .../videopress-unsupported/style.scss | 22 +++++++++++++++++-- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/components/videopress-unsupported/index.jsx b/src/components/videopress-unsupported/index.jsx index 9228ae6d3..f79a28197 100644 --- a/src/components/videopress-unsupported/index.jsx +++ b/src/components/videopress-unsupported/index.jsx @@ -1,10 +1,11 @@ import { useBlockProps } from '@wordpress/block-editor'; import { parse } from '@wordpress/block-serialization-default-parser'; -import { Notice, SandBox, Spinner } from '@wordpress/components'; +import { SandBox, Spinner } from '@wordpress/components'; import { store as coreStore } from '@wordpress/core-data'; import { useSelect } from '@wordpress/data'; import { useMemo } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; +import { Icon, info } from '@wordpress/icons'; import './style.scss'; /** @@ -59,12 +60,15 @@ export default function VideoPressUnsupported( { attributes } ) { { isLoading && }
) } - - { __( - "VideoPress video settings can't be edited in the app yet. This video is kept as is. To change its settings, edit the post on the web.", - 'gutenberg-kit' - ) } - +
+ + + { __( + 'Editing VideoPress settings is not yet supported in the app. To make changes, edit the post on the web.', + 'gutenberg-kit' + ) } + +
); } diff --git a/src/components/videopress-unsupported/index.test.jsx b/src/components/videopress-unsupported/index.test.jsx index cca2e05df..471462029 100644 --- a/src/components/videopress-unsupported/index.test.jsx +++ b/src/components/videopress-unsupported/index.test.jsx @@ -8,7 +8,6 @@ vi.mock( '@wordpress/block-editor', () => ( { } ) ); vi.mock( '@wordpress/components', () => ( { - Notice: ( { children } ) =>
{ children }
, SandBox: ( { html } ) =>
{ html }
, Spinner: () =>
, } ) ); @@ -81,11 +80,13 @@ describe( 'VideoPressUnsupported', () => { expect( screen.queryByTestId( 'spinner' ) ).not.toBeInTheDocument(); } ); - it( 'explains that the settings are not editable', () => { + it( 'captions the video to explain that its settings are not editable', () => { renderPlaceholder(); - expect( screen.getByTestId( 'notice' ) ).toHaveTextContent( - "VideoPress video settings can't be edited in the app yet." + expect( + screen.getByRole( 'figure' ).querySelector( 'figcaption' ) + ).toHaveTextContent( + 'Editing VideoPress settings is not yet supported in the app.' ); } ); } ); diff --git a/src/components/videopress-unsupported/style.scss b/src/components/videopress-unsupported/style.scss index 72a4dd0c6..5639c8be4 100644 --- a/src/components/videopress-unsupported/style.scss +++ b/src/components/videopress-unsupported/style.scss @@ -1,9 +1,15 @@ +// Video and caption form one bordered unit, tinted from the theme's text color +// so it suits light and dark themes. .gutenberg-kit-videopress-unsupported { + border: 1px solid color-mix(in srgb, currentColor 20%, transparent); + border-radius: 4px; margin-left: 0; margin-right: 0; + overflow: hidden; // Like core's embed overlay: taps select the block instead of playing. &__preview { + background-color: #000; pointer-events: none; } @@ -15,7 +21,19 @@ justify-content: center; } - .components-notice { - margin: 8px 0 0; + &__notice { + align-items: flex-start; + background-color: color-mix(in srgb, currentColor 8%, transparent); + display: flex; + font-size: 13px; + gap: 8px; + line-height: 1.5; + margin: 0; + padding: 12px; + + svg { + fill: currentColor; + flex-shrink: 0; + } } } From 7ab89e65a224c3ac8840218231d7ddad62c6092a Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Tue, 24 Nov 2026 22:08:14 -0500 Subject: [PATCH 5/9] fix: size the VideoPress preview by the video's aspect ratio The sandbox sized itself to its content, which ran taller than the player and left a black band under the video. Core embeds size by aspect ratio for the same reason. Co-Authored-By: Claude Opus 5.5 --- .../videopress-unsupported/index.jsx | 22 +++++++++++++++++-- .../videopress-unsupported/index.test.jsx | 20 +++++++++++++++++ .../videopress-unsupported/style.scss | 9 ++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/components/videopress-unsupported/index.jsx b/src/components/videopress-unsupported/index.jsx index f79a28197..4d74acc7a 100644 --- a/src/components/videopress-unsupported/index.jsx +++ b/src/components/videopress-unsupported/index.jsx @@ -42,7 +42,12 @@ export default function VideoPressUnsupported( { attributes } ) { return (
{ preview?.html ? ( -
+ // Like core embeds, size the preview by the video's aspect ratio + // rather than its content height, which can exceed the player. +
) : ( @@ -89,3 +94,16 @@ function getGuid( originalContent ) { ? guid : undefined; } + +/** + * Returns the CSS aspect ratio of an oEmbed preview. + * + * @param {Object} preview oEmbed response. + * @param {number} preview.width Embed width. + * @param {number} preview.height Embed height. + * + * @return {string} The aspect ratio, 16:9 when the size is unknown. + */ +function getAspectRatio( { width, height } ) { + return width > 0 && height > 0 ? `${ width } / ${ height }` : '16 / 9'; +} diff --git a/src/components/videopress-unsupported/index.test.jsx b/src/components/videopress-unsupported/index.test.jsx index 471462029..976ab3f86 100644 --- a/src/components/videopress-unsupported/index.test.jsx +++ b/src/components/videopress-unsupported/index.test.jsx @@ -57,6 +57,26 @@ describe( 'VideoPressUnsupported', () => { expect( screen.queryByTestId( 'spinner' ) ).not.toBeInTheDocument(); } ); + it.each( [ + [ + "the video's aspect ratio", + { width: 600, height: 338 }, + '600 / 338', + ], + [ '16:9 without a size', {}, '16 / 9' ], + ] )( 'sizes the preview by %s', ( _, size, expected ) => { + getEmbedPreview.mockReturnValue( { + html: '', + ...size, + } ); + + renderPlaceholder(); + + expect( + screen.getByTestId( 'sandbox' ).parentElement.style.aspectRatio + ).toBe( expected ); + } ); + it( 'shows an empty box when the preview fails', () => { getEmbedPreview.mockReturnValue( false ); diff --git a/src/components/videopress-unsupported/style.scss b/src/components/videopress-unsupported/style.scss index 5639c8be4..77e1e61fc 100644 --- a/src/components/videopress-unsupported/style.scss +++ b/src/components/videopress-unsupported/style.scss @@ -11,6 +11,15 @@ &__preview { background-color: #000; pointer-events: none; + position: relative; + + // The sandbox fills the aspect-ratio box instead of sizing to its content. + .components-sandbox { + height: 100%; + inset: 0; + position: absolute; + width: 100%; + } } &__placeholder { From 02075a442070d610c85af948890bdd2fdce7b045 Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Tue, 24 Nov 2026 22:08:53 -0500 Subject: [PATCH 6/9] feat: let the VideoPress preview play once its block is selected Users can check which video a block holds. As in core embeds, the first tap selects the block and later taps reach the player. Co-Authored-By: Claude Opus 5.5 --- .../videopress-unsupported/index.jsx | 33 ++++++++++--- .../videopress-unsupported/index.test.jsx | 46 ++++++++++++++++++- .../videopress-unsupported/style.scss | 8 +++- 3 files changed, 76 insertions(+), 11 deletions(-) diff --git a/src/components/videopress-unsupported/index.jsx b/src/components/videopress-unsupported/index.jsx index 4d74acc7a..537ef8390 100644 --- a/src/components/videopress-unsupported/index.jsx +++ b/src/components/videopress-unsupported/index.jsx @@ -3,7 +3,7 @@ import { parse } from '@wordpress/block-serialization-default-parser'; import { SandBox, Spinner } from '@wordpress/components'; import { store as coreStore } from '@wordpress/core-data'; import { useSelect } from '@wordpress/data'; -import { useMemo } from '@wordpress/element'; +import { useMemo, useState } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; import { Icon, info } from '@wordpress/icons'; import './style.scss'; @@ -11,19 +11,28 @@ import './style.scss'; /** * Placeholder for a `videopress/video` block the editor doesn't allow. * - * Shows a non-interactive preview of the video and explains that its settings - * can't be edited. The block keeps its original markup. + * Shows a playable preview of the video and explains that its settings can't + * be edited. The block keeps its original markup. * - * @param {Object} props Block edit props. - * @param {Object} props.attributes `core/missing` attributes, including the - * block's original markup. + * @param {Object} props Block edit props. + * @param {Object} props.attributes `core/missing` attributes, including the + * block's original markup. + * @param {boolean} props.isSelected Whether the block is selected. * * @return {Element} The placeholder. */ -export default function VideoPressUnsupported( { attributes } ) { +export default function VideoPressUnsupported( { attributes, isSelected } ) { const blockProps = useBlockProps( { className: 'gutenberg-kit-videopress-unsupported', } ); + + // Like core embeds, an overlay takes the first tap so it selects the block; + // later taps reach the player until the block is deselected. + const [ isInteractive, setIsInteractive ] = useState( false ); + if ( ! isSelected && isInteractive ) { + setIsInteractive( false ); + } + const guid = useMemo( () => getGuid( attributes.originalContent ), [ attributes.originalContent ] @@ -58,7 +67,17 @@ export default function VideoPressUnsupported( { attributes } ) { 'videopress.com' ) } type="wp-has-aspect-ratio" + onFocus={ () => setIsInteractive( true ) } /> + { ! isInteractive && ( + // Pointer-only, as in core embeds: keyboard users focus + // the player directly, which also removes the overlay. + // eslint-disable-next-line jsx-a11y/no-static-element-interactions +
setIsInteractive( true ) } + /> + ) }
) : (
diff --git a/src/components/videopress-unsupported/index.test.jsx b/src/components/videopress-unsupported/index.test.jsx index 976ab3f86..4fdec50b5 100644 --- a/src/components/videopress-unsupported/index.test.jsx +++ b/src/components/videopress-unsupported/index.test.jsx @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; -import { render, screen } from '@testing-library/react'; +import { fireEvent, render, screen } from '@testing-library/react'; import { useSelect } from '@wordpress/data'; import VideoPressUnsupported from '.'; @@ -109,15 +109,57 @@ describe( 'VideoPressUnsupported', () => { 'Editing VideoPress settings is not yet supported in the app.' ); } ); + + describe( 'playback', () => { + beforeEach( () => { + getEmbedPreview.mockReturnValue( { html: '' } ); + } ); + + it( 'covers the player until the block is tapped', () => { + const { container } = renderPlaceholder(); + + expect( getOverlay( container ) ).toBeInTheDocument(); + } ); + + it( 'uncovers the player after the tap that selects the block', () => { + const { container, rerender } = renderPlaceholder(); + + rerender( placeholder( ORIGINAL_CONTENT, true ) ); + fireEvent.mouseUp( getOverlay( container ) ); + + expect( getOverlay( container ) ).not.toBeInTheDocument(); + } ); + + it( 'covers the player again once the block is deselected', () => { + const { container, rerender } = renderPlaceholder(); + rerender( placeholder( ORIGINAL_CONTENT, true ) ); + fireEvent.mouseUp( getOverlay( container ) ); + + rerender( placeholder( ORIGINAL_CONTENT, false ) ); + + expect( getOverlay( container ) ).toBeInTheDocument(); + } ); + } ); } ); function renderPlaceholder( originalContent = ORIGINAL_CONTENT ) { - render( + return render( placeholder( originalContent, false ) ); +} + +function placeholder( originalContent, isSelected ) { + return ( ); } + +function getOverlay( container ) { + return container.querySelector( + '.gutenberg-kit-videopress-unsupported__overlay' + ); +} diff --git a/src/components/videopress-unsupported/style.scss b/src/components/videopress-unsupported/style.scss index 77e1e61fc..cfb864716 100644 --- a/src/components/videopress-unsupported/style.scss +++ b/src/components/videopress-unsupported/style.scss @@ -7,10 +7,8 @@ margin-right: 0; overflow: hidden; - // Like core's embed overlay: taps select the block instead of playing. &__preview { background-color: #000; - pointer-events: none; position: relative; // The sandbox fills the aspect-ratio box instead of sizing to its content. @@ -22,6 +20,12 @@ } } + // Takes the tap that selects the block, so it doesn't start the player. + &__overlay { + inset: 0; + position: absolute; + } + &__placeholder { align-items: center; aspect-ratio: 16 / 9; From 8b5699ef5f73a799bde74d7402ea8f25be1f12c8 Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Mon, 30 Nov 2026 14:12:36 -0500 Subject: [PATCH 7/9] perf: skip the VideoPress placeholder chunk when plugins are disabled Jetpack's v6-to-v5 conversion can't be present without plugins, so loading the chunk and its stylesheet only delayed first render. Co-Authored-By: Claude Opus 5.5 --- src/utils/editor-environment.js | 15 +++++++++------ src/utils/editor-environment.test.js | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/utils/editor-environment.js b/src/utils/editor-environment.js index 5331eaad5..6fa60f8c7 100644 --- a/src/utils/editor-environment.js +++ b/src/utils/editor-environment.js @@ -177,12 +177,15 @@ async function initializeEditor( pluginLoadResult = {} ) { // any `core/video` blocks extended to rely upon VideoPress upload services. initializeVideoPressAjaxBridge(); - // Lazy-loaded, like the editor, so its components see the configured - // locale and globals. Must run before the editor renders. - const { initializeVideoPressUnsupportedBlock } = await import( - './videopress-unsupported' - ); - initializeVideoPressUnsupportedBlock(); + // Jetpack's conversion can only exist when plugins load, so skip the + // chunk otherwise. Lazy-loaded, like the editor, so its components see + // the configured locale and globals. Must run before the editor renders. + if ( getGBKit().plugins ) { + const { initializeVideoPressUnsupportedBlock } = await import( + './videopress-unsupported' + ); + initializeVideoPressUnsupportedBlock(); + } } await _initializeEditor( { diff --git a/src/utils/editor-environment.test.js b/src/utils/editor-environment.test.js index 218e8ca63..560a86f79 100644 --- a/src/utils/editor-environment.test.js +++ b/src/utils/editor-environment.test.js @@ -87,6 +87,7 @@ describe( 'setUpEditorEnvironment', () => { it( 'executes initialization sequence in correct order', async () => { const callOrder = []; + getGBKit.mockReturnValue( { plugins: true } ); awaitGBKitGlobal.mockImplementation( () => { callOrder.push( 'awaitGBKitGlobal' ); @@ -304,6 +305,25 @@ describe( 'setUpEditorEnvironment', () => { expect( initializeVideoPressAjaxBridge ).toHaveBeenCalledTimes( 1 ); } ); + it( 'skips the VideoPress placeholder when plugins are disabled', async () => { + getGBKit.mockReturnValue( { plugins: false } ); + + await setUpEditorEnvironment(); + + expect( initializeVideoPressUnsupportedBlock ).not.toHaveBeenCalled(); + } ); + + it( 'installs the VideoPress placeholder when plugin loading fails', async () => { + getGBKit.mockReturnValue( { plugins: true } ); + loadEditorAssets.mockRejectedValue( new Error( 'Network error' ) ); + + await setUpEditorEnvironment(); + + expect( initializeVideoPressUnsupportedBlock ).toHaveBeenCalledTimes( + 1 + ); + } ); + it( 'returns a promise that resolves when initialization completes', async () => { const result = setUpEditorEnvironment(); From 0313646d4cf427be87be2710479b6fb6921fdb3d Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Mon, 30 Nov 2026 14:16:03 -0500 Subject: [PATCH 8/9] fix: explain failed VideoPress previews and offer a retry Core-data caches a failed oEmbed fetch, so a flaky connection left an empty box until the editor reloaded. Mirrors core embeds' message and Try again button, reusing their translated strings. Co-Authored-By: Claude Opus 5.5 --- .../videopress-unsupported/index.jsx | 63 ++++++++++++++++--- .../videopress-unsupported/index.test.jsx | 48 ++++++++++++-- .../videopress-unsupported/style.scss | 16 +++++ 3 files changed, 113 insertions(+), 14 deletions(-) diff --git a/src/components/videopress-unsupported/index.jsx b/src/components/videopress-unsupported/index.jsx index 537ef8390..aea92e107 100644 --- a/src/components/videopress-unsupported/index.jsx +++ b/src/components/videopress-unsupported/index.jsx @@ -1,10 +1,11 @@ +import clsx from 'clsx'; import { useBlockProps } from '@wordpress/block-editor'; import { parse } from '@wordpress/block-serialization-default-parser'; -import { SandBox, Spinner } from '@wordpress/components'; +import { Button, SandBox, Spinner } from '@wordpress/components'; import { store as coreStore } from '@wordpress/core-data'; -import { useSelect } from '@wordpress/data'; +import { useDispatch, useSelect } from '@wordpress/data'; import { useMemo, useState } from '@wordpress/element'; -import { __, sprintf } from '@wordpress/i18n'; +import { __, _x, sprintf } from '@wordpress/i18n'; import { Icon, info } from '@wordpress/icons'; import './style.scss'; @@ -40,13 +41,25 @@ export default function VideoPressUnsupported( { attributes, isSelected } ) { const url = guid ? `https://videopress.com/v/${ guid }` : undefined; // Core-data fetches `/oembed/1.0/proxy` and caches the result, so moving - // the block or remounting it doesn't fetch again. A failed fetch is `false`. - const preview = useSelect( - ( select ) => - url ? select( coreStore ).getEmbedPreview( url ) : false, + // the block or remounting it doesn't fetch again. A failed fetch is `false` + // and stays cached until invalidated, so failures offer a retry. + const { preview, isLoading } = useSelect( + ( select ) => { + if ( ! url ) { + return { preview: false, isLoading: false }; + } + const { getEmbedPreview, isResolving } = select( coreStore ); + const result = getEmbedPreview( url ); + return { + preview: result, + isLoading: + result === undefined || + isResolving( 'getEmbedPreview', [ url ] ), + }; + }, [ url ] ); - const isLoading = preview === undefined; + const { invalidateResolution } = useDispatch( coreStore ); return (
@@ -80,8 +93,38 @@ export default function VideoPressUnsupported( { attributes, isSelected } ) { ) }
) : ( -
- { isLoading && } +
+ { isLoading ? ( + + ) : ( + <> + { /* Core embed strings, so existing translations apply. */ } +

+ { __( + 'Sorry, this content could not be embedded.' + ) } +

+ { url && ( + + ) } + + ) }
) }
diff --git a/src/components/videopress-unsupported/index.test.jsx b/src/components/videopress-unsupported/index.test.jsx index 4fdec50b5..051dac4f8 100644 --- a/src/components/videopress-unsupported/index.test.jsx +++ b/src/components/videopress-unsupported/index.test.jsx @@ -1,6 +1,6 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; import { fireEvent, render, screen } from '@testing-library/react'; -import { useSelect } from '@wordpress/data'; +import { useDispatch, useSelect } from '@wordpress/data'; import VideoPressUnsupported from '.'; vi.mock( '@wordpress/block-editor', () => ( { @@ -8,25 +8,36 @@ vi.mock( '@wordpress/block-editor', () => ( { } ) ); vi.mock( '@wordpress/components', () => ( { + Button: ( { children, onClick } ) => ( + + ), SandBox: ( { html } ) =>
{ html }
, Spinner: () =>
, } ) ); vi.mock( '@wordpress/core-data', () => ( { store: 'core' } ) ); -vi.mock( '@wordpress/data', () => ( { useSelect: vi.fn() } ) ); +vi.mock( '@wordpress/data', () => ( { + useDispatch: vi.fn(), + useSelect: vi.fn(), +} ) ); const ORIGINAL_CONTENT = ''; describe( 'VideoPressUnsupported', () => { let getEmbedPreview; + let isResolving; + let invalidateResolution; beforeEach( () => { getEmbedPreview = vi.fn(); + isResolving = vi.fn().mockReturnValue( false ); + invalidateResolution = vi.fn(); useSelect.mockImplementation( ( callback ) => - callback( () => ( { getEmbedPreview } ) ) + callback( () => ( { getEmbedPreview, isResolving } ) ) ); + useDispatch.mockReturnValue( { invalidateResolution } ); } ); it( "requests the preview for the block's guid", () => { @@ -77,13 +88,35 @@ describe( 'VideoPressUnsupported', () => { ).toBe( expected ); } ); - it( 'shows an empty box when the preview fails', () => { + it( 'explains a failed preview and offers a retry', () => { getEmbedPreview.mockReturnValue( false ); renderPlaceholder(); expect( screen.queryByTestId( 'spinner' ) ).not.toBeInTheDocument(); expect( screen.queryByTestId( 'sandbox' ) ).not.toBeInTheDocument(); + expect( + screen.getByText( 'Sorry, this content could not be embedded.' ) + ).toBeInTheDocument(); + + fireEvent.click( screen.getByRole( 'button', { name: 'Try again' } ) ); + + expect( invalidateResolution ).toHaveBeenCalledWith( + 'getEmbedPreview', + [ 'https://videopress.com/v/AbC123xy' ] + ); + } ); + + it( 'shows a spinner while retrying a failed preview', () => { + getEmbedPreview.mockReturnValue( false ); + isResolving.mockReturnValue( true ); + + renderPlaceholder(); + + expect( screen.getByTestId( 'spinner' ) ).toBeInTheDocument(); + expect( + screen.queryByRole( 'button', { name: 'Try again' } ) + ).not.toBeInTheDocument(); } ); it.each( [ @@ -98,6 +131,13 @@ describe( 'VideoPressUnsupported', () => { expect( getEmbedPreview ).not.toHaveBeenCalled(); expect( screen.queryByTestId( 'spinner' ) ).not.toBeInTheDocument(); + expect( + screen.getByText( 'Sorry, this content could not be embedded.' ) + ).toBeInTheDocument(); + // Without a guid there is nothing to fetch, so a retry can't help. + expect( + screen.queryByRole( 'button', { name: 'Try again' } ) + ).not.toBeInTheDocument(); } ); it( 'captions the video to explain that its settings are not editable', () => { diff --git a/src/components/videopress-unsupported/style.scss b/src/components/videopress-unsupported/style.scss index cfb864716..40412459a 100644 --- a/src/components/videopress-unsupported/style.scss +++ b/src/components/videopress-unsupported/style.scss @@ -32,6 +32,22 @@ background-color: #000; display: flex; justify-content: center; + + // Drops the black video frame so the message and the theme-colored + // retry button stay legible. + &.is-error { + aspect-ratio: auto; + background-color: transparent; + flex-direction: column; + font-size: 13px; + gap: 12px; + padding: 24px 16px; + text-align: center; + + p { + margin: 0; + } + } } &__notice { From 79d5eba4f1afd5e2acbb439042b07c4ac171b47b Mon Sep 17 00:00:00 2001 From: David Calhoun Date: Mon, 30 Nov 2026 14:56:14 -0500 Subject: [PATCH 9/9] fix: keep the VideoPress notice left-aligned under centering themes Themes such as Twenty Twenty-One center figcaptions, which split the notice text from its icon. Colors and fonts still follow the theme. Co-Authored-By: Claude Opus 5.5 --- src/components/videopress-unsupported/style.scss | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/videopress-unsupported/style.scss b/src/components/videopress-unsupported/style.scss index 40412459a..bffa01438 100644 --- a/src/components/videopress-unsupported/style.scss +++ b/src/components/videopress-unsupported/style.scss @@ -59,6 +59,9 @@ line-height: 1.5; margin: 0; padding: 12px; + // Themes may center figcaptions, which would split the text from its + // left-aligned icon. Colors and fonts still follow the theme. + text-align: start; svg { fill: currentColor;