diff --git a/packages/block-library/src/embed/edit.js b/packages/block-library/src/embed/edit.js index 2945fb0fbe888..0b166ebd1e9c7 100644 --- a/packages/block-library/src/embed/edit.js +++ b/packages/block-library/src/embed/edit.js @@ -127,16 +127,17 @@ const EmbedEdit = ( props ) => { }; useEffect( () => { - if ( ! preview?.html || ! cannotEmbed || fetching ) { + if ( preview?.html || ! cannotEmbed || fetching ) { return; } + // At this stage, we're not fetching the preview and know it can't be embedded, // so try removing any trailing slash, and resubmit. const newURL = attributesUrl.replace( /\/$/, '' ); setURL( newURL ); setIsEditingURL( false ); setAttributes( { url: newURL } ); - }, [ preview?.html, attributesUrl, cannotEmbed, fetching ] ); + }, [ preview?.html, attributesUrl, cannotEmbed, fetching, setAttributes ] ); // Try a different provider in case the embed url is not supported. useEffect( () => { diff --git a/test/e2e/specs/editor/various/embedding.spec.js b/test/e2e/specs/editor/various/embedding.spec.js index 2fa963f66685d..3e04960e7fbf8 100644 --- a/test/e2e/specs/editor/various/embedding.spec.js +++ b/test/e2e/specs/editor/various/embedding.spec.js @@ -122,7 +122,7 @@ test.describe( 'Embedding content', () => { await expect( currenEmbedBlock.getByRole( 'textbox', { name: 'Embed URL' } ), 'WordPress invalid content. Should render failed, edit state.' - ).toHaveValue( 'https://wordpress.org/gutenberg/handbook/' ); + ).toHaveValue( 'https://wordpress.org/gutenberg/handbook' ); await embedUtils.insertEmbed( 'https://twitter.com/thatbunty' ); await expect( @@ -189,7 +189,7 @@ test.describe( 'Embedding content', () => { } ); // Reason: A possible regression of https://github.com/WordPress/gutenberg/pull/14705. - test.skip( 'should retry embeds that could not be embedded with trailing slashes, without the trailing slashes', async ( { + test( 'should retry embeds that could not be embedded with trailing slashes, without the trailing slashes', async ( { editor, embedUtils, } ) => {