forked from ant-design/ant-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: react 18 test fixing (ant-design#34787)
* 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
- Loading branch information
Showing
28 changed files
with
825 additions
and
496 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* 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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.