tiptap: fix render flow

This commit is contained in:
fantasticit 2022-05-19 15:17:47 +08:00
parent 35ca6cba61
commit 36102b9c82
1 changed files with 13 additions and 20 deletions

View File

@ -23,9 +23,8 @@ export const FlowWrapper = ({ editor, node, updateAttributes }) => {
const { theme } = useTheme(); const { theme } = useTheme();
const $viewer = useRef(null); const $viewer = useRef(null);
const $container = useRef<HTMLElement>(); const $container = useRef<HTMLElement>();
const doRenderRef = useRef<() => void>();
const isEditorReady = useEditorReady(editor, () => { const isEditorReady = useEditorReady(editor, () => {
doRenderRef.current && doRenderRef.current(); render($container.current);
}); });
const [bgColor, setBgColor] = useState('var(--semi-color-fill-0)'); const [bgColor, setBgColor] = useState('var(--semi-color-fill-0)');
const bgColorOpacity = useMemo(() => { const bgColorOpacity = useMemo(() => {
@ -79,7 +78,10 @@ export const FlowWrapper = ({ editor, node, updateAttributes }) => {
const render = useCallback( const render = useCallback(
(div) => { (div) => {
const doRender = (div) => { if (!isEditorReady) {
return;
}
if (!div) return; if (!div) return;
// @ts-ignore // @ts-ignore
const DrawioViewer = window.GraphViewer; const DrawioViewer = window.GraphViewer;
@ -91,15 +93,6 @@ export const FlowWrapper = ({ editor, node, updateAttributes }) => {
background && setBgColor(background); background && setBgColor(background);
}); });
} }
doRenderRef.current = null;
};
if (!isEditorReady) {
doRenderRef.current = () => doRender(div);
return;
} else {
doRender(div);
}
}, },
[isEditorReady] [isEditorReady]
); );