From c76192ffafe7a106b72207f9291256e2984a8d2b Mon Sep 17 00:00:00 2001 From: wanhose Date: Sat, 5 Oct 2024 18:30:25 +0200 Subject: [PATCH] fix(browser-extension): off/on performance --- packages/browser-extension/src/scripts/background.js | 4 ++-- packages/browser-extension/src/scripts/content.js | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/browser-extension/src/scripts/background.js b/packages/browser-extension/src/scripts/background.js index 362111d..a68ddf5 100644 --- a/packages/browser-extension/src/scripts/background.js +++ b/packages/browser-extension/src/scripts/background.js @@ -7,7 +7,7 @@ /** * @typedef {Object} ExtensionState - * @property {ExtensionIssue} issue + * @property {ExtensionIssue} [issue] * @property {boolean} on */ @@ -146,7 +146,7 @@ async function getState(hostname) { state.issue = await refreshIssue(hostname); } - return state; + return { ...stateByDefault, ...state }; } /** diff --git a/packages/browser-extension/src/scripts/content.js b/packages/browser-extension/src/scripts/content.js index 582a4c0..55f00de 100644 --- a/packages/browser-extension/src/scripts/content.js +++ b/packages/browser-extension/src/scripts/content.js @@ -7,9 +7,8 @@ */ /** - * @typedef {Object} ExtensionState + * @typedef {Object} ContentState * @property {boolean} on - * @property {ExtensionIssue} [issue] */ /** @@ -97,7 +96,7 @@ const seen = new Set(); /** * @description Extension state - * @type {ExtensionState} + * @type {ContentState} */ let state = { on: true }; @@ -415,7 +414,7 @@ function run(params = {}) { * @param {SetUpParams} [params] */ async function setUp(params = {}) { - state = (await dispatch({ hostname, type: 'GET_STATE' })) ?? state; + state = await dispatch({ hostname, type: 'GET_STATE' }); dispatch({ type: 'ENABLE_POPUP' }); if (state.on) {