redux-electron-store icon indicating copy to clipboard operation
redux-electron-store copied to clipboard

Fix bug with refreshing internal webviews

Open matt-way opened this issue 6 years ago • 5 comments

In my application I have the ability to reload() an internal webview. When doing this the webcontents id changes (but the webcontents doesnt), so it ends up duplicating the client in the main process. This has the unwanted side effect of duplicating actions through ipc.

My fix is simple, it just checks for duplicated and removes the clients with the incorrect (old) id. The important code is:

// if webviews are reloaded, the contents id changes
// so duplicates need to be removed
Object.keys(clients).forEach(k => {
  if (clients[k].webContents === sender) {
    delete clients[k];
  }
});

The other changes were created by my prettier setup and shouldn't change anything.

I'm not fully aware if this will create other problems, so welcome to feedback.

matt-way avatar Nov 13 '18 08:11 matt-way

Yeah no problems. I use prettier for everything, so hence the style changes. I initially did the PR quickly just to make sure I didn't miss anything with the actual webcontents code. I'll fix it all up when i get the chance soon.

matt-way avatar Nov 18 '18 23:11 matt-way

Excuse me, there are multiple webviews in my project that have been restarted and then expired. How to get out of multiple webviews?

kl-nevermore avatar Jan 25 '19 10:01 kl-nevermore

@NeverMore-KL Not sure exactly what you mean by "get out of multiple webviews", but if you can spin up a repo with a minimal repro of the bug you're hitting I can look at fixing it

samiskin avatar Jan 27 '19 20:01 samiskin

@NeverMore-KL Not sure exactly what you mean by "get out of multiple webviews", but if you can spin up a repo with a minimal repro of the bug you're hitting I can look at fixing it

In my APP, I open 3 webviews for the first time. If I used webContents.reload()

// It is worked
webContents.send(`${globalName}-browser-dispatch`, JSON.stringify(action));

but

//It is not worked,
//But the state of redux has been modified.
/**
I restarted again(use webContents.reload), the app behaved normally, but the problem still exists. After I restarted the first time, every time I call redux in webview, I need to restart and the performance is normal.
*/
ipcRenderer.on(`${globalName}-browser-dispatch`, (event, stringifiedAction) => {
    context.flags.isUpdating = true;
    const action = JSON.parse(stringifiedAction);
    dispatcher(action);
  });

So, I would like to ask how to solve this problem.

kl-nevermore avatar Jan 28 '19 03:01 kl-nevermore

@NeverMore-KL sorry I'm still not fully understanding, is this a general question unrelated to redux-electron-store?

samiskin avatar Jan 31 '19 19:01 samiskin