Feedly-Notifier icon indicating copy to clipboard operation
Feedly-Notifier copied to clipboard

"Mark as read" and "Mark all as read" fail if popup is closed (Firefox)

Open AlexNk opened this issue 8 years ago • 7 comments

  1. Open popup with some unread items
  2. Click "Mark as read" or "Mark all as read" - popup will show the progress indicator
  3. Quickly close the popup by clicking outside of it
  4. Icon will show the old number; popup will show the same list of unread items

Firefox 54.0, Ubuntu Zesty

AlexNk avatar Jul 17 '17 17:07 AlexNk

Hi @AlexNk It seems like FF disposes feedIds and the function fails with can’t access dead object https://github.com/olsh/Feedly-Notifier/blob/master/src/scripts/core.js#L787

The disposing of objects is a feature https://blog.mozilla.org/addons/2012/09/12/what-does-cant-access-dead-object-mean/

Simple array copying doesn't solve the problem.

olsh avatar Jul 26 '17 16:07 olsh

Hi Oleg

I'm not familiar with WebExtensions API but is that possible to perform such operations not in context of popup?

AlexNk avatar Jul 27 '17 17:07 AlexNk

Well, this is not webextension specific bug. The aggressive GC behaves the same for all types of FF add-ons. For now, I don't have a solution for the issue.

olsh avatar Jul 27 '17 18:07 olsh

Sorry if my question is stupid but F.N. icon somehow performs requests to show the number of new feeds. Therefore there's an instance which isn't affected by this GC behavior and can safely perform "mark as read" requests.

AlexNk avatar Jul 27 '17 18:07 AlexNk

Yes, of course, the addon works even if the popup is closed. The problem is that the feedIds is created in the popup.js and passed to the core.js (background page).

olsh avatar Jul 27 '17 18:07 olsh

Yes, you are right, now I understand the issue.

I tried to debug it on Firefox and found that copying the contents of the array helps in this case )I don't know if there's any API for cloning objects in JS, but this approach works for me):

function markAsRead(feedIds, callback) {

  • let ids = []; for (let i = 0; i < feedIds.length; i++) ids.push(feedIds[i]);*
apiRequestWrapper("markers", {
    body: {
        action: "markAsRead",
        type: "entries",
        entryIds: ids
    },
    method: "POST"
}).then(function () {
  •    for (let i = 0; i < ids.length; i++) {*
          removeFeedFromCache(ids[i]);
      }
      chrome.browserAction.getBadgeText({}, function (feedsCount) {
          feedsCount = +feedsCount;
          if (feedsCount > 0) {
              *feedsCount -= ids.length;*
              setBadgeCounter(feedsCount);
          }
      });
      if (typeof callback === "function") {
          callback(true);
      }
    
    }, function () { if (typeof callback === "function") { callback(false); } }); }

With this change after execution of the call, "ids" with its content is still alive even when "callback" is dead.

AlexNk avatar Jul 27 '17 20:07 AlexNk

Hi @AlexNk ,

Thanks for the investigation 👍 I used splice function for the array copying, and this didn't work. Will try your code.

olsh avatar Jul 28 '17 08:07 olsh