fix(react): respect custom default node type when falling back from unknown node type

This commit is contained in:
Ze-Zheng Wu
2025-07-05 18:11:27 +08:00
parent 549ec62d6d
commit 18514e118f
4 changed files with 53 additions and 1 deletions

View File

@@ -9,6 +9,7 @@ import ControlledViewport from '../examples/ControlledViewport';
import CustomConnectionLine from '../examples/CustomConnectionLine';
import CustomMiniMapNode from '../examples/CustomMiniMapNode';
import CustomNode from '../examples/CustomNode';
import DefaultNodeOverwrite from '../examples/DefaultNodeOverwrite';
import DefaultNodes from '../examples/DefaultNodes';
import DragHandle from '../examples/DragHandle';
import DragNDrop from '../examples/DragNDrop';
@@ -129,6 +130,11 @@ const routes: IRoute[] = [
path: 'custom-node',
component: CustomNode,
},
{
name: 'Default Node Overwrite',
path: 'default-node-overwrite',
component: DefaultNodeOverwrite,
},
{
name: 'Default Nodes',
path: 'default-nodes',

View File

@@ -0,0 +1,41 @@
import { ReactFlow, Node, ReactFlowProvider, Background, BackgroundVariant, NodeProps } from '@xyflow/react';
const initialNodes: Node[] = [
{
id: '1',
data: { label: 'Node 1' },
position: { x: 250, y: 5 },
className: 'light',
},
{
id: '2',
data: { label: 'Node 2' },
type: 'unregistered',
position: { x: 100, y: 100 },
className: 'light',
},
];
const CustomNode = (_: NodeProps) => {
return <div>Custom node</div>;
};
const nodeTypes = {
default: CustomNode,
};
const DefaultNodes = () => {
return (
<ReactFlow defaultNodes={initialNodes} nodeTypes={nodeTypes} fitView>
<Background variant={BackgroundVariant.Lines} />
</ReactFlow>
);
};
export default function App() {
return (
<ReactFlowProvider>
<DefaultNodes />
</ReactFlowProvider>
);
}