feat(react): add basic ssr support

This commit is contained in:
moklick
2023-10-04 16:03:23 +02:00
parent 53c04e2546
commit 86c041c2a0
21 changed files with 2915 additions and 606 deletions
@@ -1,9 +1,10 @@
import { useContext, type FC, type PropsWithChildren } from 'react';
import { useContext, type ReactNode } from 'react';
import StoreContext from '../../contexts/RFStoreContext';
import ReactFlowProvider from '../../components/ReactFlowProvider';
import type { Node, Edge } from '../../types';
const Wrapper: FC<PropsWithChildren<unknown>> = ({ children }) => {
function Wrapper({ children, nodes, edges }: { children: ReactNode; nodes?: Node[]; edges?: Edge[] }) {
const isWrapped = useContext(StoreContext);
if (isWrapped) {
@@ -12,8 +13,12 @@ const Wrapper: FC<PropsWithChildren<unknown>> = ({ children }) => {
return <>{children}</>;
}
return <ReactFlowProvider>{children}</ReactFlowProvider>;
};
return (
<ReactFlowProvider nodes={nodes} edges={edges}>
{children}
</ReactFlowProvider>
);
}
Wrapper.displayName = 'ReactFlowWrapper';
@@ -181,7 +181,7 @@ const ReactFlow = forwardRef<ReactFlowRefType, ReactFlowProps>(
data-testid="rf__wrapper"
id={id}
>
<Wrapper>
<Wrapper nodes={nodes} edges={edges}>
<GraphView
onInit={onInit}
onNodeClick={onNodeClick}