mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-08 01:53:34 +08:00

* fix: try fix * chore: ci * test: recover * test: more test case * test: more and mote * test: btn test * fix: react 18 compitable * chore: more test * test: all confirm test * chore: tmp * chore: test lib * chore: tmp * chore: tmp * test: back of part * test: back of menu index test * test: more test * test: form test * test: rm IE11 test case * chore: fix compatible * chore: clean up * chore: back of all test case * test: ignore 18 lines * chore: remove render test of enzyme in upload * test: back of IE11 test case to fit 100% coverage * chore: fix pkg deps
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
/* eslint-disable import/prefer-default-export */
|
|
import * as React from 'react';
|
|
import { render, unmountComponentAtNode } from 'react-dom';
|
|
import type { Root } from 'react-dom/client';
|
|
// import * as reactDomClient from 'react-dom/client';
|
|
|
|
let createRoot: (container: ContainerType) => Root;
|
|
try {
|
|
// eslint-disable-next-line global-require, import/no-unresolved
|
|
createRoot = require('react-dom/client').createRoot;
|
|
} catch (e) {
|
|
// Do nothing;
|
|
}
|
|
|
|
const MARK = '__antd_react_root__';
|
|
|
|
type ContainerType = (Element | DocumentFragment) & {
|
|
[MARK]?: Root;
|
|
};
|
|
|
|
export function reactRender(node: React.ReactElement, container: ContainerType) {
|
|
// React 17 test will not reach here
|
|
/* istanbul ignore next */
|
|
if (createRoot !== undefined) {
|
|
const root = container[MARK] || createRoot(container);
|
|
root.render(node);
|
|
|
|
container[MARK] = root;
|
|
return;
|
|
}
|
|
|
|
render(node, container);
|
|
}
|
|
|
|
export function reactUnmount(container: ContainerType) {
|
|
// React 17 test will not reach here
|
|
/* istanbul ignore next */
|
|
if (createRoot !== undefined) {
|
|
// Delay to unmount to avoid React 18 sync warning
|
|
Promise.resolve().then(() => {
|
|
container[MARK]?.unmount();
|
|
|
|
delete container[MARK];
|
|
});
|
|
|
|
return;
|
|
}
|
|
|
|
unmountComponentAtNode(container);
|
|
}
|