samiskin / redux-electron-store

⎋ A redux store enhancer that allows automatic synchronization between electron processes
MIT License
375 stars 32 forks source link

Fix bug with refreshing internal webviews #57

Open matt-way opened 5 years ago

matt-way commented 5 years ago

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 commented 5 years ago

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.

kl-nevermore commented 5 years ago

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

samiskin commented 5 years ago

@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

kl-nevermore commented 5 years ago

@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.

samiskin commented 5 years ago

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