Skip to content

Commit

Permalink
fix: render-imperative (#1076)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicleo committed Mar 27, 2023
1 parent ed1e876 commit e6cabda
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 2 additions & 5 deletions packages/zarm/src/utils/dom/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ 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;
Expand Down Expand Up @@ -55,9 +54,7 @@ function modernRender(node: React.ReactElement, container: ContainerType) {
toggleWarning(true);
const root = container[MARK] || createRoot(container);
toggleWarning(false);
flushSync(() => {
root.render(node);
})
root.render(node);
container[MARK] = root;
}

Expand Down
6 changes: 5 additions & 1 deletion packages/zarm/src/utils/dom/renderImperatively.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ export const renderImperatively = (element: TargetElement) => {

return {
close: () => {
wrapperRef.current?.close();
if (wrapperRef.current) {
wrapperRef.current?.close();
} else {
unmount();
}
},
replace: (replacedElement) => {
wrapperRef.current?.replace(replacedElement);
Expand Down

0 comments on commit e6cabda

Please sign in to comment.