logux/client

Limit LocalStorage.setItem Attempts

vrizo opened this issue · 5 comments

vrizo commented

Hi, @ai!

We faced NS_ERROR_OUT_OF_MEMORY error in Firefox. It might be the incognito mode or some plugin. Unfortunately, I don't know how to reproduce the problem. It still works, but there is an issue. As I can see Logux retries to write the data all the time. I think we should limit attempts of writing to LocalStorage.

Stack trace:

 function sendToTabs (client, event, data) {
   if (!client.isLocalStorage) return
>  localStorage.setItem(storageKey(client, event), JSON.stringify(data))
 }

NS_ERROR_OUT_OF_MEMORY: No error message
  at sendToTabs(./node_modules/@logux/client/cross-tab-client.js:11:16)
  at leaderPing(./node_modules/@logux/client/cross-tab-client.js:22:3)
  at apply(./node_modules/@logux/client/cross-tab-client.js:52:32)
  at r(./node_modules/@sentry/browser/esm/helpers.js:71:23)

Firefox 72.0, Windows 10.

The error occurs every two seconds. Please let me know if I can help with the issue.

Thanks!

ai commented

Seems like they were able to write to localStorage initially (isLocalStorage is a result for initial check), but then memory was ended.

Can I ask you to help me a little with a fix here? You need to fix a few small things:

  1. Add try-catch where you will set isLocalStorage = false and change the role to leader on the error.
  2. Add a test for the case.

I think this PR will help you to be familiar with Logux internals.

vrizo commented

It would be great. Thank you! I'm quite busy this week, but I will try to send a PR on the weekend.

ai commented

Fixed 0eca711

Can you use this version on Amplifr and check will it solve error? Do not forget to clean Yarn cache since you will use version from GitHub (Yarn have a problem with cache invalidation).

vrizo commented

Thank you, @ai !

Sure! This error occurs no more than once a month. It will take some time to check.

ai commented

Release in 0.6