Skip to content

fix(445): render default block on empty editor #494

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion packages/core/editor/src/components/Editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Props = {
const getEditorStyles = (styles: CSSProperties) => ({
...styles,
width: styles.width || 400,
paddingBottom: typeof styles.paddingBottom === 'number' ? styles.paddingBottom : 100,
paddingBottom: styles.paddingBottom ?? 100,
});

const Editor = ({
Expand Down Expand Up @@ -59,6 +59,13 @@ const Editor = ({
return () => document.removeEventListener('keydown', onKeyDown);
}, [editor.path, isReadOnly]);

useEffect(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it's good idea to manage the editor value inside the core package.
I think the manipulation of the value should be completely on the user's side

Copy link
Contributor Author

@gloaysa gloaysa Apr 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point and makes sense. On the other hand, the user might not be aware of the tooling needed to build an empty block and just expect that when the editor is empty, it will display the placeholder (currently it only displays a blank space).

My current solution is also flawed, now that I think about it, since buildBlockData uses a Paragraph, and maybe the current editor doesn't have the Paragraph plugin installed.

Maybe add documentation explaining this is the expected behaviour and how to solve it? (is the reason behind #494 )

if (isReadOnly || Object.keys(editor.children).length) return;
// when editor is empty, add default empty block to display placeholder
const defaultBlock = buildBlockData({ id: generateId() });
editor.insertBlock(defaultBlock.type, { at: 0, focus: false });
}, []);

const handleEmptyZoneClick = (e: React.MouseEvent) => {
const editorEl = editor.refElement;
if (!editorEl) return;
Expand Down