Skip to content

Commit 0a3686e

Browse files
author
Guillaume Chau
committed
fix(ui): IPC API memory leak
1 parent d5a3b1f commit 0a3686e

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

packages/@vue/cli-ui/src/graphql-api/api/PluginApi.js

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class PluginApi {
2525
this.clientAddons = []
2626
this.views = []
2727
this.actions = new Map()
28+
this.ipcHandlers = []
2829
}
2930

3031
/**
@@ -194,6 +195,7 @@ class PluginApi {
194195
* @param {function} cb Callback with 'data' param
195196
*/
196197
ipcOn (cb) {
198+
this.ipcHandlers.push(cb)
197199
return ipc.on(cb)
198200
}
199201

@@ -203,6 +205,8 @@ class PluginApi {
203205
* @param {any} cb Callback to be removed
204206
*/
205207
ipcOff (cb) {
208+
const index = this.ipcHandlers.indexOf(cb)
209+
if (index !== -1) this.ipcHandlers.splice(index, 1)
206210
ipc.off(cb)
207211
}
208212

packages/@vue/cli-ui/src/graphql-api/connectors/plugins.js

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const PluginApi = require('../api/PluginApi')
3232
// Utils
3333
const { getCommand } = require('../utils/command')
3434
const { getBasePath } = require('../utils/serve')
35+
const ipc = require('../utils/ipc')
3536

3637
const PROGRESS_ID = 'plugin-installation'
3738

@@ -83,6 +84,7 @@ function resetPluginApi (context) {
8384
// Clean up
8485
if (pluginApi) {
8586
pluginApi.views.forEach(r => views.remove(r.id, context))
87+
pluginApi.ipcHandlers.forEach(fn => ipc.off(fn))
8688
}
8789

8890
pluginApi = new PluginApi(context)

0 commit comments

Comments
 (0)