Skip to content

Comments

Fix options page crash: reference chrome.storage[area] reactively and await storage.get() in storage-usage.svelte#8999

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-options-load-error
Draft

Fix options page crash: reference chrome.storage[area] reactively and await storage.get() in storage-usage.svelte#8999
Copilot wants to merge 3 commits intomainfrom
copilot/fix-options-load-error

Conversation

Copy link
Contributor

Copilot AI commented Feb 21, 2026

On Firefox, the options page crashes with Error: An unexpected error occurred undefined due to two bugs in storage-usage.svelte:

  1. Stale prop capture: chrome.storage[area] was evaluated once at module scope — before the custom element's area attribute is applied — leaving storage as undefined. Svelte 5 warns about this exact pattern (state_referenced_locally).

  2. Unawaited Promise: chrome.storage[area].get(item) returns a Promise, which was being passed synchronously to getTrueSizeOfObject instead of being awaited.

Changes:

  • Removed the top-level const storage = chrome.storage[area] assignment
  • $derived.by() now reads chrome.storage[area] inside the callback with a local storage variable, respecting Svelte 5's reactive prop lifecycle
  • Replaced the broken $effect body (which passed an unawaited Promise to getTrueSizeOfObject) with void getStorageUsage(), which correctly awaits the storage read via getStoredItemSize

Test URLs

https://github.com/settings/profile (options page — chrome-extension://.../options.html)

Screenshot

Original prompt

This section details on the original issue you should resolve

<issue_title>Options fail to load</issue_title>
<issue_description>### Description

When trying to open the refine github options Im running into a Javascript error:

Image

These are the errors in the console:

Uncaught (in promise) Error: An unexpected error occurred undefined
    getStorageUsage moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/storage-usage.js:38
    AsyncFunctionThrow self-hosted:784
    (Async: async)
    Storage_usage moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/storage-usage.js:60
    untrack moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-internal-client-runtime.js:366
    onMount moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-index-client.js:14
    update_reaction moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-internal-client-runtime.js:130
    update_effect moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-internal-client-runtime.js:257
    flush_queued_effects moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-internal-client-reactivity-batch.js:309
    process moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-internal-client-reactivity-batch.js:59
    flush_effects moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-internal-client-reactivity-batch.js:284
    flush moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-internal-client-reactivity-batch.js:131
    ensure moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-internal-client-reactivity-batch.js:242
    run_all moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-internal-shared-utils.js:14
    run_micro_tasks moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-internal-client-dom-task.js:8
    queue_micro_task moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-internal-client-dom-task.js:14
    (Async: VoidFunction)
    queue_micro_task moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-internal-client-dom-task.js:13
    ensure moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-internal-client-reactivity-batch.js:238
    component_root moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-internal-client-reactivity-effects.js:125
    _mount moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-internal-client-render.js:93
    mount moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-internal-client-render.js:24
    Svelte4Component moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-legacy-legacy-client.js:38
    createClassComponent moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-legacy-legacy-client.js:9
    connectedCallback moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/svelte-internal-client-dom-elements-custom-element.js:84
    AsyncFunctionNext self-hosted:780
    (Async: async)
    <anonymous> moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/storage-usage.js:104

Uncaught (in promise) Error: An unexpected error occurred
    get moz-extension://116a3ca0-a6d6-4954-ba18-35983604f6d0/assets/npm/webext-polyfill-kinda.js:14

How to replicate the issue + URL

It happens in the refined-github options page.

Extension version

26.2.2

Browser(s) used

firefox 147.0.3

Token ⚠️

  • I set a token in the options page. I understand that some features require a token to work.</issue_description>

<agent_instructions>Fix svelte issue</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@fregante Are you using Firefox normally? Is it the developer version? Are you loading it in a special way? Are you logged into Firefox Accounts?

The file appears to be Firefox' own JS code; "area" is sync, which Firefox has historically being annoying with. I'm not sure why it's suddenly breaking for you since as far as I know we didn't make any changes in that area recently.

Are you a new Refined GitHub user or did it stop working in the latest version?</comment_new>
<comment_new>@fregante
Partially never mind: the error appears to be in Svelte's code, producing undefined where it shouldn't be. It's generated code so I thought it was Firefox' and not ours 😅 </comment_new>
<comment_new>@SunsetTechuila

(!) [plugin svelte] source/options/storage-usage.svelte: This reference only captures the initial value of `area`. Did you mean to reference it inside a closure instead?
https://svelte.dev/e/state_referenced_locally
E:\Repos\refined-github\source\opti...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes refined-github/refined-github#8950

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

…pture on Firefox

Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix options failing to load due to JavaScript error Fix options page crash: reference chrome.storage[area] reactively in storage-usage.svelte Feb 21, 2026
Copilot AI requested a review from fregante February 21, 2026 11:32
if (item) {
used = getTrueSizeOfObject(storage.get(item));
used = getTrueSizeOfObject(chrome.storage[area].get(item));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot I think this was a bug too: get() returns a promise that needs to be awaited

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in f9a3e1b. chrome.storage[area].get(item) returns a Promise, so passing it to getTrueSizeOfObject was a bug. Replaced the $effect body with void getStorageUsage(), which already properly awaits storage.get(item) via getStoredItemSize.

Co-authored-by: fregante <1402241+fregante@users.noreply.github.com>
Copilot AI changed the title Fix options page crash: reference chrome.storage[area] reactively in storage-usage.svelte Fix options page crash: reference chrome.storage[area] reactively and await storage.get() in storage-usage.svelte Feb 21, 2026
Copilot AI requested a review from fregante February 21, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants