Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions packages/overlay/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { Component } from 'vue'
import type { Component, App as VueAppType } from 'vue'
import { createApp, h } from 'vue'

import App from './App.vue'

let app: VueAppType | null = null
function createDevToolsContainer(App: Component) {
const CONTAINER_ID = '__vue-devtools-container__'
const el = document.createElement('div')
el.setAttribute('id', CONTAINER_ID)
el.setAttribute('data-v-inspector-ignore', 'true')
document.getElementsByTagName('body')[0].appendChild(el)
const app = createApp({
app = createApp({
render: () => h(App),
devtools: {
hide: true,
Expand All @@ -19,3 +19,22 @@ function createDevToolsContainer(App: Component) {
}

createDevToolsContainer(App)

const targetNode = document.body
const config = { childList: true, attributes: false }
const observer = new MutationObserver(callback)
observer.observe(targetNode, config)

let isInitialized = false
function callback(mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.type === 'childList' && isInitialized === false) {
if (app) {
app.unmount()
}
Comment on lines +32 to +34

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with createDevToolsContainer (line 21) appending the devtool app in the DOM, wouldn't this systematically trigger ? making the callback unmount and re-mount the app for nothing ?

createDevToolsContainer(App)
isInitialized = true
observer.disconnect()
}
}
}
Loading