chore(components): lazily create root to mount components if needed (#13778)

This commit is contained in:
Andrey Lushnikov 2022-05-03 17:11:45 -06:00 committed by GitHub
parent 13224d1c9f
commit 4b6f53461d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View File

@ -53,6 +53,11 @@ function render(component) {
} }
window.playwrightMount = component => { window.playwrightMount = component => {
if (!document.getElementById('root')) {
const rootElement = document.createElement('div');
rootElement.id = 'root';
document.body.append(rootElement);
}
ReactDOM.render(render(component), document.getElementById('root')); ReactDOM.render(render(component), document.getElementById('root'));
return '#root > *'; return '#root > *';
}; };

View File

@ -26,6 +26,11 @@ export default (components, options) => {
}; };
const playwrightMount = component => { const playwrightMount = component => {
if (!document.getElementById('root')) {
const rootElement = document.createElement('div');
rootElement.id = 'root';
document.body.append(rootElement);
}
let componentCtor = registry.get(component.type); let componentCtor = registry.get(component.type);
if (!componentCtor) { if (!componentCtor) {
// Lookup by shorthand. // Lookup by shorthand.

View File

@ -125,6 +125,11 @@ function createDevTools() {
} }
window.playwrightMount = async component => { window.playwrightMount = async component => {
if (!document.getElementById('root')) {
const rootElement = document.createElement('div');
rootElement.id = 'root';
document.body.append(rootElement);
}
const app = instance.createApp({ const app = instance.createApp({
render: () => render(component) render: () => render(component)
}); });