Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

refactor: add fallback component for missing components #570

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
28 changes: 28 additions & 0 deletions packages/test-app/src/eb-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,32 @@ defineComponents([
},
},
},
{
component: CustomImageComponent,
definition: {
id: 'custom-image',
name: 'Custom Image',
category: 'Custom Components',
variables: {
src: {
displayName: 'SRC',
type: 'Media',
},
},
},
},
// {
// component: CustomImageComponent,
// definition: {
// id: 'gonna-be-removed',
// name: 'Gonna be removed',
// category: 'Custom Components',
// variables: {
// src: {
// displayName: 'SRC',
// type: 'Media',
// },
// },
// },
// },
]);
13 changes: 13 additions & 0 deletions packages/visual-editor/src/components/Dropzone/Dropzone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ASSEMBLY_NODE_TYPES, CONTENTFUL_COMPONENTS } from '@contentful/experien
import { RenderDropzoneFunction } from './Dropzone.types';
import { EditorBlockClone } from './EditorBlockClone';
import { DropzoneClone } from './DropzoneClone';
import { componentRegistry } from '@/store/registries';

type DropzoneProps = {
zoneId: string;
Expand Down Expand Up @@ -159,6 +160,18 @@ export function Dropzone({
content.map((item, i) => {
const componentId = item.data.id;

const registration = componentRegistry.get(item.data.blockId!);

if (!registration) {
return (
<div
key={componentId}
style={{ background: 'red', padding: '12px', color: 'white' }}>
Component registration not found: {item.data.blockId}
</div>
);
}

return (
<EditorBlock
placeholder={{
Expand Down