-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1107 from capricorn86/task/940-cant-render-portal…
…s-sometimes #940@patch: Fixes issue related to ownerDocument being null when exec…
- Loading branch information
Showing
13 changed files
with
7,320 additions
and
15,205 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,49 +1,62 @@ | ||
import GlobalRegistrator from '../../cjs/GlobalRegistrator.cjs'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import ReactDOM from 'react-dom/client'; | ||
import { act } from 'react-dom/test-utils'; | ||
import ReactComponent from './ReactComponent.js'; | ||
|
||
const selfReferringProperties = ['self', 'top', 'parent', 'window']; | ||
async function main(): Promise<void> { | ||
const selfReferringProperties = ['self', 'top', 'parent', 'window']; | ||
|
||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
const originalSetTimeout = global.setTimeout; | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
const originalSetTimeout = global.setTimeout; | ||
|
||
GlobalRegistrator.register(); | ||
GlobalRegistrator.register(); | ||
|
||
const appElement = document.createElement('app'); | ||
document.body.appendChild(appElement); | ||
const appElement = document.createElement('app'); | ||
let root; | ||
document.body.appendChild(appElement); | ||
|
||
function mountReactComponent(): void { | ||
ReactDOM.render(<ReactComponent />, appElement); | ||
async function mountReactComponent(): Promise<void> { | ||
act(() => { | ||
root = ReactDOM.createRoot(appElement); | ||
root.render(<ReactComponent />); | ||
}); | ||
|
||
if (appElement.innerHTML !== '<div>Test</div>') { | ||
throw Error('React not rendered correctly.'); | ||
await new Promise((resolve) => setTimeout(resolve, 2)); | ||
|
||
if (appElement.innerHTML !== '<div>Test</div>') { | ||
throw Error('React not rendered correctly.'); | ||
} | ||
} | ||
} | ||
|
||
function unmountReactComponent(): void { | ||
ReactDOM.unmountComponentAtNode(appElement); | ||
function unmountReactComponent(): void { | ||
act(() => { | ||
root.unmount(); | ||
}); | ||
|
||
if (appElement.innerHTML !== '') { | ||
throw Error('React not unmounted correctly.'); | ||
if (appElement.innerHTML !== '') { | ||
throw Error('React not unmounted correctly.'); | ||
} | ||
} | ||
} | ||
|
||
if (global.setTimeout === originalSetTimeout) { | ||
throw Error('Happy DOM function not registered.'); | ||
} | ||
if (global.setTimeout === originalSetTimeout) { | ||
throw Error('Happy DOM function not registered.'); | ||
} | ||
|
||
for (const property of selfReferringProperties) { | ||
if (global[property] !== global) { | ||
throw Error('Self referring property property was not registered.'); | ||
for (const property of selfReferringProperties) { | ||
if (global[property] !== global) { | ||
throw Error('Self referring property property was not registered.'); | ||
} | ||
} | ||
} | ||
|
||
mountReactComponent(); | ||
unmountReactComponent(); | ||
await mountReactComponent(); | ||
unmountReactComponent(); | ||
|
||
GlobalRegistrator.unregister(); | ||
GlobalRegistrator.unregister(); | ||
|
||
if (global.setTimeout !== originalSetTimeout) { | ||
throw Error('Global property was not restored.'); | ||
if (global.setTimeout !== originalSetTimeout) { | ||
throw Error('Global property was not restored.'); | ||
} | ||
} | ||
|
||
main(); |
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
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
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