Skip to main content

Many apps didnt load on all platforms 22052020

Around 1.45 PM GMT+6 https://gitlab.com/powr/powr/-/merge_requests/4904 was launched. This MR contains fixes to prevent unexpected content overriding when users are applying templates. Initially, users cried only on microblog (https://powrteam.slack.com/archives/C0ANLSP0F/p1588676820397800), but formBuilder & multiSlider were affected as well. To fix this, checkContentForChanges & hasUnpublishedContent were introduced to base_model.jsx. We need these to assign a correct value to isChangedFromDefault property after model initialization.

  checkContentForChanges: function() {
const { id, app_type, saved } = META || {};
const unpublishedContent = this.hasUnpublishedContent(id, app_type);
if (saved || unpublishedContent) {
this.setLocals({ isChangedFromDefault: true });
}
};

hasUnpublishedContent: function(id, appType) {
const unpublishedContent = JSON.parse(window.getCookie('unpublished_content')) || {};
return unpublishedContent[appType] && unpublishedContent[appType] === id;
};

  After that, support noticed a lot of tickets coming from Wix users, Sunil notified about that at 3.46 PM GMT+6 in #engineering channel. Sunil, Sergey, Nazir, Valeriy tried to reproduce it without any success for the first time. At 4.10 PM GMT+6 Nazir reverted his MR (https://gitlab.com/powr/powr/-/merge_requests/4960) to see if that helps. Eventually, Timur caught the error in the browser's console at 4.54 PM GMT+6 - https://powrteam.slack.com/archives/C0ANLSP0F/p1590144973289400

Revert went live at 5.24 PM GMT+6.

The issue was in this line:

const unpublishedContent = JSON.parse(window.getCookie('unpublished_content')) || {};

  For new and saved apps there was not an unpublished_content cookie, so

window.getCookie('unpublished_content')

  returned undefined and

JSON.parse(undefined)

  was crashed.

That was the problem to reproduce it by engineers, mostly they had unpublished_content cookie.

The fix is to check a cookie and parse it only if it exists:

  hasUnpublishedContent: function(id, appType) {
const unpublishedCookie = window.getCookie('unpublished_content');
if (!unpublishedCookie) return false;
const unpublishedContent = JSON.parse(unpublishedCookie);
return unpublishedContent[appType] && unpublishedContent[appType] === id;
},

  Another variation we have in our codebase:

   try {
let unpublishedContent = JSON.parse(window.getCookie('unpublished_content'));
} catch (e) {
unpublishedContent = {};
}

  To prevent that in the future:

  • Engineers must be more careful when deploying or reviewing a code that might affect all apps
  • QA should consider adding check with fresh cookies to the checklist
  • Don't forget to try clear cookies while trying to catch an error