Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitefb1cf6

Browse files
committed
(fix): resolve AsyncLocalStorage Illegal Invocation errors
- I (and apparently most mst-persist users) don't use localStorage, so this went undetected for a while until someone reported a bug - and I finally hit upon it myself when adding tests shortly after, which added a solid reproduction as well as a blocker on it- it made localStorage unusable as all of AsyncLocalStorage's calls would give Illegal Invocation errors - seehttps://stackoverflow.com/q/41126149/3431180 for more details on this error - using .call did not work, not on callWithPromise.call(window, ...) nor func.call(window, ...args) - similarly window.localStorage.func.bind(window) did not work - so instead used wrapper functions as an alternative that didn't feel too convoluted - using window.localStorage[funcKey] in callWithPromise did not quite feel right, wrapper functions felt better
1 parent6b1dd3b commitefb1cf6

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

‎src/asyncLocalStorage.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ interface IAsyncLocalStorage {
66
}
77

88
exportconstAsyncLocalStorage:IAsyncLocalStorage={
9+
// must use wrapper functions when passing localStorage functions (https://github.com/agilgur5/mst-persist/issues/18)
910
clear(){
10-
returncallWithPromise(window.localStorage.clear)
11+
returncallWithPromise(()=>window.localStorage.clear())
1112
},
1213
getItem(key){
13-
returncallWithPromise(window.localStorage.getItem,key)
14+
returncallWithPromise(()=>window.localStorage.getItem(key))
1415
},
1516
removeItem(key){
16-
returncallWithPromise(window.localStorage.removeItem,key)
17+
returncallWithPromise(()=>window.localStorage.removeItem(key))
1718
},
1819
setItem(key,value){
19-
returncallWithPromise(window.localStorage.setItem,key,value)
20+
returncallWithPromise(()=>window.localStorage.setItem(key,value))
2021
}
2122
}
2223

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp