diff --git a/packages/zarm/src/utils/dom/render.ts b/packages/zarm/src/utils/dom/render.ts index 39f3d931f..2171c6555 100644 --- a/packages/zarm/src/utils/dom/render.ts +++ b/packages/zarm/src/utils/dom/render.ts @@ -18,10 +18,12 @@ const fullClone = { const { version, render: reactRender, unmountComponentAtNode } = fullClone; let createRoot: CreateRoot; +let flushSync; try { const mainVersion = Number((version || '').split('.')[0]); if (mainVersion >= 18 && fullClone.createRoot) { createRoot = fullClone.createRoot; + flushSync = fullClone.flushSync; } } catch { // Do nothing; @@ -53,7 +55,9 @@ function modernRender(node: React.ReactElement, container: ContainerType) { toggleWarning(true); const root = container[MARK] || createRoot(container); toggleWarning(false); - root.render(node); + flushSync(() => { + root.render(node); + }) container[MARK] = root; }