Skip to content

feat: Filter block types with allow list #113

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 4 commits into from
Apr 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/remote.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ async function initalizeRemoteEditor() {
const { themeStyles, hideTitle, siteApiRoot, siteApiNamespace } =
getGBKit();
// TODO: Load editor assets within the host app
const { styles, scripts } = await apiFetch( {
const {
styles,
scripts,
allowed_block_types: allowedBlockTypes,
} = await apiFetch( {
url: `${ siteApiRoot }wpcom/v2/${ siteApiNamespace[ 0 ] }/editor-assets`,
} );
await loadAssets( [ ...styles, ...scripts ].join( '' ) );
Expand Down Expand Up @@ -67,7 +71,16 @@ async function initalizeRemoteEditor() {
const { default: Layout } = await import( './components/layout' );
const { createRoot, createElement, StrictMode } = window.wp.element;
const { registerCoreBlocks } = window.wp.blockLibrary;

registerCoreBlocks();
if ( allowedBlockTypes ) {
window.wp.blocks.getBlockTypes().forEach( ( block ) => {
if ( ! allowedBlockTypes.includes( block.name ) ) {
window.wp.blocks.unregisterBlockType( block.name );
}
} );
}

createRoot( document.getElementById( 'root' ) ).render(
createElement(
StrictMode,
Expand Down