@livestore/livestore 0.0.48-dev.4 → 0.0.48-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react/useLocalId.js
CHANGED
|
@@ -5,13 +5,11 @@ export const getLocalId = (opts) => {
|
|
|
5
5
|
// TODO find a better way to handle this
|
|
6
6
|
// Currently `getLocalId` gets imported and called in some worker-side code
|
|
7
7
|
// during development where Vite isn't tree-shaking yet.
|
|
8
|
-
if (typeof window === 'undefined')
|
|
8
|
+
if (typeof window === 'undefined' || window.localStorage === undefined || window.sessionStorage === undefined) {
|
|
9
9
|
return '';
|
|
10
|
+
}
|
|
10
11
|
const { key = '', storageType = 'session', storageKeyPrefix = 'livestore:localid:', makeId = cuid } = opts ?? {};
|
|
11
12
|
const storage = storageType === 'session' ? window.sessionStorage : window.localStorage;
|
|
12
|
-
// This also seems to be a code path that gets hit in SSR
|
|
13
|
-
if (storage === undefined)
|
|
14
|
-
return '';
|
|
15
13
|
const fullKey = `${storageKeyPrefix}:${key}`;
|
|
16
14
|
const storedKey = storage.getItem(fullKey);
|
|
17
15
|
if (storedKey)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalId.js","sourceRoot":"","sources":["../../src/react/useLocalId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC5C,OAAO,KAAK,MAAM,OAAO,CAAA;AASzB,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAA8B,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAA;AAE3G,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAA8B,EAAE,EAAE;IAC3D,wCAAwC;IACxC,2EAA2E;IAC3E,wDAAwD;IACxD,IAAI,OAAO,MAAM,KAAK,WAAW;
|
|
1
|
+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1
|
{
|
|
2
2
|
"name": "@livestore/livestore",
|
|
3
|
-
"version": "0.0.48-dev.
|
|
3
|
+
"version": "0.0.48-dev.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"@graphql-typed-document-node/core": "^3.2.0",
|
|
39
39
|
"@opentelemetry/api": "^1.9.0",
|
|
40
40
|
"lodash-es": "^4.17.21",
|
|
41
|
-
"
|
|
42
|
-
"@livestore/
|
|
43
|
-
"
|
|
41
|
+
"@livestore/common": "0.0.48-dev.5",
|
|
42
|
+
"@livestore/utils": "0.0.48-dev.5",
|
|
43
|
+
"effect-db-schema": "0.0.48-dev.5"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@opentelemetry/sdk-trace-base": "1.25.0",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"typescript": "5.4.5",
|
|
56
56
|
"vite": "5.2.13",
|
|
57
57
|
"vitest": "^1.6.0",
|
|
58
|
-
"@livestore/web": "0.0.48-dev.
|
|
58
|
+
"@livestore/web": "0.0.48-dev.5"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@tauri-apps/api": "^1.4.0",
|
package/src/react/useLocalId.ts
CHANGED
|
@@ -14,14 +14,13 @@ export const getLocalId = (opts?: Partial<LocalIdOptions>) => {
|
|
|
14
14
|
// TODO find a better way to handle this
|
|
15
15
|
// Currently `getLocalId` gets imported and called in some worker-side code
|
|
16
16
|
// during development where Vite isn't tree-shaking yet.
|
|
17
|
-
if (typeof window === 'undefined')
|
|
17
|
+
if (typeof window === 'undefined' || window.localStorage === undefined || window.sessionStorage === undefined) {
|
|
18
|
+
return ''
|
|
19
|
+
}
|
|
18
20
|
|
|
19
21
|
const { key = '', storageType = 'session', storageKeyPrefix = 'livestore:localid:', makeId = cuid } = opts ?? {}
|
|
20
22
|
|
|
21
23
|
const storage = storageType === 'session' ? window.sessionStorage : window.localStorage
|
|
22
|
-
// This also seems to be a code path that gets hit in SSR
|
|
23
|
-
if (storage === undefined) return ''
|
|
24
|
-
|
|
25
24
|
const fullKey = `${storageKeyPrefix}:${key}`
|
|
26
25
|
const storedKey = storage.getItem(fullKey)
|
|
27
26
|
|
|
@@ -29,5 +28,6 @@ export const getLocalId = (opts?: Partial<LocalIdOptions>) => {
|
|
|
29
28
|
|
|
30
29
|
const newKey = makeId()
|
|
31
30
|
storage.setItem(fullKey, newKey)
|
|
31
|
+
|
|
32
32
|
return newKey
|
|
33
33
|
}
|