From 6b5bd3b6ceb9457b091171bbde40700be71c66dd Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Mon, 15 May 2017 08:57:23 -0300 Subject: [PATCH] Fix how rpc-server releases references after page reload In addition to listening for "render-view-deleted", listen for "ELECTRON_BROWSER_CONTEXT_RELEASE" synchronous message, which is sent by the remote module when the page is about to be navigated. This is required to allow child windows running in the same renderer to correctly manage remote object references, since `render-view-deleted` is only called when the renderer exits. Close #9387 --- lib/browser/rpc-server.js | 5 +++++ lib/renderer/api/remote.js | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/lib/browser/rpc-server.js b/lib/browser/rpc-server.js index 8d543f2d7d30..815298d3d9de 100644 --- a/lib/browser/rpc-server.js +++ b/lib/browser/rpc-server.js @@ -394,6 +394,11 @@ ipcMain.on('ELECTRON_BROWSER_DEREFERENCE', function (event, id) { objectsRegistry.remove(event.sender.getId(), id) }) +ipcMain.on('ELECTRON_BROWSER_CONTEXT_RELEASE', (e) => { + objectsRegistry.clear(e.sender.getId()) + e.returnValue = null +}) + ipcMain.on('ELECTRON_BROWSER_GUEST_WEB_CONTENTS', function (event, guestInstanceId) { try { let guestViewManager = require('./guest-view-manager') diff --git a/lib/renderer/api/remote.js b/lib/renderer/api/remote.js index 5e790133d383..fdc95cdb5cdd 100644 --- a/lib/renderer/api/remote.js +++ b/lib/renderer/api/remote.js @@ -304,6 +304,10 @@ ipcRenderer.on('ELECTRON_RENDERER_RELEASE_CALLBACK', function (event, id) { callbacksRegistry.remove(id) }) +process.on('exit', () => { + ipcRenderer.sendSync('ELECTRON_BROWSER_CONTEXT_RELEASE') +}) + // Get remote module. exports.require = function (module) { return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_REQUIRE', module))