Skip to content

Commit 6bf699d

Browse files
committed
fix: deduplicate app ids
1 parent cda14ce commit 6bf699d

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

Diff for: packages/app-backend-core/src/app.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,24 @@ export function mapAppRecord (record: AppRecord): SimpleAppRecord {
125125
}
126126
}
127127

128+
const appIds = new Set()
129+
128130
export function getAppRecordId (app, defaultId?: string): string {
129131
if (app.__VUE_DEVTOOLS_APP_RECORD_ID__ != null) {
130132
return app.__VUE_DEVTOOLS_APP_RECORD_ID__
131133
}
132-
const id = defaultId ?? (recordId++).toString()
134+
let id = defaultId ?? (recordId++).toString()
135+
136+
if (defaultId && appIds.has(id)) {
137+
let count = 1
138+
while (appIds.has(`${defaultId}:${count}`)) {
139+
count++
140+
}
141+
id = `${defaultId}:${count}`
142+
}
143+
144+
appIds.add(id)
145+
133146
app.__VUE_DEVTOOLS_APP_RECORD_ID__ = id
134147
return id
135148
}
@@ -181,6 +194,7 @@ export async function removeApp (app: App, ctx: BackendContext) {
181194
try {
182195
const appRecord = await getAppRecord(app, ctx)
183196
if (appRecord) {
197+
appIds.delete(appRecord.id)
184198
const index = ctx.appRecords.indexOf(appRecord)
185199
if (index !== -1) ctx.appRecords.splice(index, 1)
186200
removeLayersForApp(app, ctx)

Diff for: packages/shell-dev-vue3/public/target.html

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<body>
1313
<div id="app"></div>
1414
<div id="app2"></div>
15+
<div id="app2bis"></div>
1516
<div id="app3"></div>
1617
<div id="delay-app"></div>
1718
<div id="ghost-app"></div>

Diff for: packages/shell-dev-vue3/src/main.js

+6
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ const app2 = createApp({
3939
})
4040
app2.mount('#app2')
4141

42+
const app2bis = createApp({
43+
name: 'App2',
44+
render: () => h('h1', 'App 2 Bis')
45+
})
46+
app2bis.mount('#app2bis')
47+
4248
createApp(App3).mount('#app3')
4349

4450
createApp({

0 commit comments

Comments
 (0)