最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

block editor - Unable to override MediaPlaceholder component

programmeradmin1浏览0评论

I'm trying to override the MediaPlaceholder component from wp.blockEditor.MediaPlaceholder using the available filter editor.MediaPlaceholder. Below is my code snippet:

// plugin.js
import MyMediaPlaceholder from './media-placeholder';

wp.hooks.addFilter(
    'editor.MediaPlaceholder',
    'my/plugin/replace-media-placeholder',
    () => MyMediaPlaceholder
);
// media-placeholder.js

const {
    blockEditor: { MediaPlaceholder },
    element: { Fragment }
} = wp;

class MyMediaPlaceholder extends MediaPlaceholder {
    // Basically, I want to disable the Drag'n'Drop feature of MediaPlaceholder component.
    renderDropZone() {
        return ( <Fragment /> );
    }
}

export default MyMediaPlaceholder;

But above code goes into infinite loading of block editor page in the browser. The page never stops loading. The loading spinner in the tab keeps spinning and spinning.

My hunch is, it's going into some kind of infinite loop here. But I'm not able to figure out what's wrong with it. Can someone help here?

I'm trying to override the MediaPlaceholder component from wp.blockEditor.MediaPlaceholder using the available filter editor.MediaPlaceholder. Below is my code snippet:

// plugin.js
import MyMediaPlaceholder from './media-placeholder';

wp.hooks.addFilter(
    'editor.MediaPlaceholder',
    'my/plugin/replace-media-placeholder',
    () => MyMediaPlaceholder
);
// media-placeholder.js

const {
    blockEditor: { MediaPlaceholder },
    element: { Fragment }
} = wp;

class MyMediaPlaceholder extends MediaPlaceholder {
    // Basically, I want to disable the Drag'n'Drop feature of MediaPlaceholder component.
    renderDropZone() {
        return ( <Fragment /> );
    }
}

export default MyMediaPlaceholder;

But above code goes into infinite loading of block editor page in the browser. The page never stops loading. The loading spinner in the tab keeps spinning and spinning.

My hunch is, it's going into some kind of infinite loop here. But I'm not able to figure out what's wrong with it. Can someone help here?

Share Improve this question asked Aug 13, 2019 at 13:16 Udit DesaiUdit Desai 1637 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

wp.blockEditor.MediaPlaceholder is not the class, it's the following code in the Gutenberg/Block Editor's media-placeholder file:

export default compose(
    applyWithSelect,
    withFilters( 'editor.MediaPlaceholder' ),
)( MediaPlaceholder );

Thus an infinite loop as the filter is applied constantly.

发布评论

评论列表(0)

  1. 暂无评论