UNPKG

1.94 kBJavaScriptView Raw
1import { __awaiter } from "tslib";
2import * as ReactDOM from 'react-dom';
3// Let compiler not to search module usage
4const fullClone = Object.assign({}, ReactDOM);
5const {
6 version,
7 render: reactRender,
8 unmountComponentAtNode
9} = fullClone;
10let createRoot;
11try {
12 const mainVersion = Number((version || '').split('.')[0]);
13 if (mainVersion >= 18 && fullClone.createRoot) {
14 // eslint-disable-next-line @typescript-eslint/no-var-requires
15 createRoot = fullClone.createRoot;
16 }
17} catch (e) {
18 // Do nothing;
19}
20function toggleWarning(skip) {
21 const {
22 __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
23 } = fullClone;
24 if (__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED && typeof __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED === 'object') {
25 __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint = skip;
26 }
27}
28const MARK = '__antd_mobile_root__';
29function legacyRender(node, container) {
30 reactRender(node, container);
31}
32function concurrentRender(node, container) {
33 toggleWarning(true);
34 const root = container[MARK] || createRoot(container);
35 toggleWarning(false);
36 root.render(node);
37 container[MARK] = root;
38}
39export function render(node, container) {
40 if (createRoot) {
41 concurrentRender(node, container);
42 return;
43 }
44 legacyRender(node, container);
45}
46// ========================== Unmount =========================
47function legacyUnmount(container) {
48 return unmountComponentAtNode(container);
49}
50function concurrentUnmount(container) {
51 return __awaiter(this, void 0, void 0, function* () {
52 // Delay to unmount to avoid React 18 sync warning
53 return Promise.resolve().then(() => {
54 var _a;
55 (_a = container[MARK]) === null || _a === void 0 ? void 0 : _a.unmount();
56 delete container[MARK];
57 });
58 });
59}
60export function unmount(container) {
61 if (createRoot) {
62 return concurrentUnmount(container);
63 }
64 return legacyUnmount(container);
65}
\No newline at end of file