|
1 | 1 | /* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
|
2 |
| -import type { FC, ReactElement } from 'react'; |
| 2 | +import type { ReactElement } from 'react'; |
3 | 3 | import * as React from 'react';
|
4 | 4 | import type { Root as ReactRoot, RootOptions } from 'react-dom/client';
|
5 | 5 | import * as ReactDOM from 'react-dom/client';
|
6 | 6 |
|
7 |
| -import { preventActChecks } from './preventActChecks'; |
8 |
| - |
9 | 7 | // A map of all rendered React 18 nodes
|
10 | 8 | const nodes = new Map<Element, ReactRoot>();
|
11 | 9 |
|
12 |
| -const WithCallback: FC<{ callback: () => void; children: ReactElement }> = ({ |
| 10 | +declare const globalThis: { |
| 11 | + IS_REACT_ACT_ENVIRONMENT: boolean; |
| 12 | +}; |
| 13 | + |
| 14 | +function getIsReactActEnvironment() { |
| 15 | + return globalThis.IS_REACT_ACT_ENVIRONMENT; |
| 16 | +} |
| 17 | + |
| 18 | +const WithCallback: React.FC<{ callback: () => void; children: ReactElement }> = ({ |
13 | 19 | callback,
|
14 | 20 | children,
|
15 | 21 | }) => {
|
@@ -43,16 +49,21 @@ export const renderElement = async (node: ReactElement, el: Element, rootOptions
|
43 | 49 | // Create Root Element conditionally for new React 18 Root Api
|
44 | 50 | const root = await getReactRoot(el, rootOptions);
|
45 | 51 |
|
| 52 | + if (getIsReactActEnvironment()) { |
| 53 | + root.render(node); |
| 54 | + return; |
| 55 | + } |
| 56 | + |
46 | 57 | const { promise, resolve } = Promise.withResolvers<void>();
|
47 |
| - preventActChecks(() => root.render(<WithCallback callback={resolve}>{node}</WithCallback>)); |
| 58 | + root.render(<WithCallback callback={resolve}>{node}</WithCallback>); |
48 | 59 | return promise;
|
49 | 60 | };
|
50 | 61 |
|
51 | 62 | export const unmountElement = (el: Element, shouldUseNewRootApi?: boolean) => {
|
52 | 63 | const root = nodes.get(el);
|
53 | 64 |
|
54 | 65 | if (root) {
|
55 |
| - preventActChecks(() => root.unmount()); |
| 66 | + root.unmount(); |
56 | 67 | nodes.delete(el);
|
57 | 68 | }
|
58 | 69 | };
|
|
0 commit comments