Skip to content

Implement workaround for infinite recursion with the chrome storage change listener#65

Draft
ckiee wants to merge 1 commit into
MacFJA:mainfrom
ckiee:fix-chrome-listenExternalChanges
Draft

Implement workaround for infinite recursion with the chrome storage change listener#65
ckiee wants to merge 1 commit into
MacFJA:mainfrom
ckiee:fix-chrome-listenExternalChanges

Conversation

@ckiee

@ckiee ckiee commented Jun 28, 2025

Copy link
Copy Markdown
Contributor

Fixes #64, albeit in a rather fragile manner. Ideally we'd be able to pass another argument through the Svelte store API
or have the concept of a thread local variable but we have neither as things are dispatched over multiple JS ticks

…hange listener

Fixes MacFJA#64, albeit in a rather fragile manner. Ideally we'd be able to pass another argument through the Svelte store API
or have the concept of a thread local variable but we have neither as things are dispatched over multiple JS ticks
@ckiee ckiee marked this pull request as draft June 28, 2025 15:31
@ckiee

ckiee commented Jun 28, 2025

Copy link
Copy Markdown
Contributor Author

Converting to draft as it doesn't work if you make multiple updates in a tick

@MacFJA

MacFJA commented Jun 29, 2025

Copy link
Copy Markdown
Owner

I think it would be better to add a control to prevent saving the same data again and again.

It can be done on the storage itself or in the persist function.

But we have to watch for the performance, I fear that reading the storage every time can be a bit costly. (and we need to read the storage not the store, because the storage can be changed outside the application)

@ckiee

ckiee commented Jul 2, 2025

Copy link
Copy Markdown
Contributor Author

I ended up abandoning the current patch because if you have this setup it loops when there is more than one edit per tick:

  • tick 0
    • set store.a = 5
    • set store.b = 2
  • tick 1
    • event onChanged a=5
    • => store a=5, infinite loop.
    • event onChanged b=2
    • => noop

I realized all I need is one way updates so I use the extension messaging now from the options page to the background script, this could be added to this library too by making the argument type boolean | "push" | "pull".

https://github.com/ckiee/distract-o-window/blob/9aa101699b37f28c72d7d7028ea1753ed899d31a/src/background/main.ts#L7-L11

https://github.com/ckiee/distract-o-window/blob/9aa101699b37f28c72d7d7028ea1753ed899d31a/src/options/main.ts#L9-L13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ChromeStorage's listenExternalChanges is broken

2 participants