Skip to content

Commit c9f354d

Browse files
authored
Reader: Fix embeds on Quick Post (#108422)
- Use Verbum Editor API middleware to forward all Quick Post embed requests to verbum API instead of looking for `wp-json/oembed/1.0/proxy` endpoint. - Fix Quick Post editor which limits the max height to `800px`.
1 parent 000b595 commit c9f354d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

client/reader/components/quick-post/index.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import {
33
Editor,
44
loadBlocksWithCustomizations,
55
loadTextFormatting,
6+
addApiMiddleware,
67
} from '@automattic/verbum-block-editor';
8+
import { EmbedRequestParams } from '@automattic/verbum-block-editor/src/api';
79
import { useMutation } from '@tanstack/react-query';
810
// @ts-expect-error - No declaration file for heading block.
911
import * as heading from '@wordpress/block-library/build-module/heading';
10-
import { createBlock, parse, serialize, unregisterBlockType } from '@wordpress/blocks';
12+
import { createBlock, parse, serialize } from '@wordpress/blocks';
1113
import { Button, __experimentalHStack as HStack } from '@wordpress/components';
1214
import { addQueryArgs } from '@wordpress/url';
1315
import { useTranslate } from 'i18n-calypso';
@@ -29,7 +31,17 @@ import './style.scss';
2931
// Initialize the editor blocks and text formatting.
3032
loadBlocksWithCustomizations( [ heading ] );
3133
loadTextFormatting( [ heading.name ] );
32-
unregisterBlockType( 'core/embed' );
34+
35+
// Add API middleware for embeds.
36+
// This redirects `/wp-json/oembed/1.0/proxy` requests to the WordPress.com embed API.
37+
// Because we are not using verbum editor in site context.
38+
addApiMiddleware(
39+
( embedURL: string ): EmbedRequestParams => ( {
40+
path: '/verbum/embed',
41+
query: `embed_url=${ encodeURIComponent( embedURL ) }`,
42+
apiNamespace: 'wpcom/v2',
43+
} )
44+
);
3345

3446
export default function QuickPost(): JSX.Element | null {
3547
const translate = useTranslate();

client/reader/components/quick-post/test/index.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jest.mock( '@automattic/verbum-block-editor', () => {
4747
),
4848
loadBlocksWithCustomizations: jest.fn(),
4949
loadTextFormatting: jest.fn(),
50+
addApiMiddleware: jest.fn(),
5051
};
5152
} );
5253

0 commit comments

Comments
 (0)