Closed gxr404 closed 5 months ago
Infinite loop unexpectedly fixed by await storageInterface.getItem(key) in the previous PR
await storageInterface.getItem(key)
This approach is unreasonable. Relevant discussion
A better approach would be to pause the watch when the localstroage listen is triggered
watch
localstroage listen
View the commit history, the current code for useWebExtensionStorage is based on reference useStorageAsync
useWebExtensionStorage
useStorageAsync here also did not use pausableWatch because browser mechanism is different from extension
useStorageAsync
pausableWatch
browser
extension
// Event not triggered window.addEventListener('storage', e=>{console.log(e)}) localStorage.setItem('test', 111) // Event triggered chrome.storage.onChanged.addListener(function() {console.log('trigger')}) chrome.storage.local.set({'test': 123})
Why does extension need to customize useStorageAsync
Why use pausableWatch to replace watchWithFilter
watchWithFilter
Description
Infinite loop unexpectedly fixed by
await storageInterface.getItem(key)
in the previous PRThis approach is unreasonable. Relevant discussion
A better approach would be to pause the
watch
when thelocalstroage listen
is triggeredView the commit history, the current code for
useWebExtensionStorage
is based on reference useStorageAsyncuseStorageAsync
here also did not usepausableWatch
becausebrowser
mechanism is different fromextension
Linked Issues
Why does
extension
need to customizeuseStorageAsync
Why use
pausableWatch
to replacewatchWithFilter