Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: render-imperative #1076

Merged
merged 1 commit into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 { 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 @@
toggleWarning(true);
const root = container[MARK] || createRoot(container);
toggleWarning(false);
flushSync(() => {
root.render(node);
})
root.render(node);

Check warning on line 57 in packages/zarm/src/utils/dom/render.ts

View check run for this annotation

Codecov / codecov/patch

packages/zarm/src/utils/dom/render.ts#L57

Added line #L57 was not covered by tests
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 @@

return {
close: () => {
wrapperRef.current?.close();
if (wrapperRef.current) {
wrapperRef.current?.close();
} else {
unmount();

Check warning on line 78 in packages/zarm/src/utils/dom/renderImperatively.tsx

View check run for this annotation

Codecov / codecov/patch

packages/zarm/src/utils/dom/renderImperatively.tsx#L78

Added line #L78 was not covered by tests
}
},
replace: (replacedElement) => {
wrapperRef.current?.replace(replacedElement);
Expand Down