Skip to content

Commit

Permalink
fix: don't render node if it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
prevwong committed May 31, 2024
1 parent dc5befb commit d564810
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/nodes/NodeElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const NodeElement: React.FC<React.PropsWithChildren<
>> = ({ id, render }) => {
return (
<NodeProvider id={id}>
<RenderNodeToElement render={render} />
<RenderNodeToElement id={id} render={render} />
</NodeProvider>
);
};
15 changes: 7 additions & 8 deletions packages/core/src/render/RenderNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@ import React from 'react';
import { DefaultRender } from './DefaultRender';

import { useInternalEditor } from '../editor/useInternalEditor';
import { useInternalNode } from '../nodes/useInternalNode';

type RenderNodeToElementType = {
id: string;
render?: React.ReactElement;
};

export const RenderNodeToElement: React.FC<React.PropsWithChildren<
RenderNodeToElementType
>> = ({ render }) => {
const { hidden } = useInternalNode((node) => ({
hidden: node.data.hidden,
}));

const { onRender } = useInternalEditor((state) => ({
>> = ({ id, render }) => {
const { onRender, exists, isNodeHidden } = useInternalEditor((state) => ({
onRender: state.options.onRender,
exists: !!state.nodes[id],
isNodeHidden: state.nodes[id]?.data.hidden ?? false,
}));

// don't display the node since it's hidden
if (hidden) {
if (!exists || isNodeHidden) {
return null;
}

Expand Down

0 comments on commit d564810

Please sign in to comment.