@zauru-sdk/redux 2.32.3 → 2.33.0
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/esm/store.js +46 -6
- package/dist/store.d.ts +14 -1
- package/package.json +2 -2
package/dist/esm/store.js
CHANGED
|
@@ -15,12 +15,47 @@ const templates_slice_js_1 = __importDefault(require("./slices/templates.slice.j
|
|
|
15
15
|
const automaticNumbers_slice_js_1 = __importDefault(require("./slices/automaticNumbers.slice.js"));
|
|
16
16
|
const tables_slice_js_1 = __importDefault(require("./slices/tables.slice.js"));
|
|
17
17
|
const formsSavedData_slice_js_1 = __importDefault(require("./slices/formsSavedData.slice.js"));
|
|
18
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Full Redux snapshot key in `localStorage`. Written by
|
|
20
|
+
* `persistanceLocalStorageMiddleware` after every action.
|
|
21
|
+
*
|
|
22
|
+
* **QuotaExceededError:** Browsers cap `localStorage` per origin (often ~5MiB,
|
|
23
|
+
* not standardized). `setItem` throws `QuotaExceededError` when the new value
|
|
24
|
+
* plus existing data for that origin exceeds the cap.
|
|
25
|
+
*
|
|
26
|
+
* **Why only some tenants/devices:** Serialized state grows with cached
|
|
27
|
+
* catalogs (items, invoices, forms, etc.). Heavy tenants hit the limit sooner;
|
|
28
|
+
* private mode, Safari, or nearly full disks can lower the effective cap. Other
|
|
29
|
+
* apps on the same origin share the same quota.
|
|
30
|
+
*/
|
|
31
|
+
exports.LOCAL_STORAGE_REDUX_NAME = "___redux__state__v7.0";
|
|
32
|
+
function isQuotaExceededError(error) {
|
|
33
|
+
if (error instanceof DOMException && error.name === "QuotaExceededError") {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return (typeof error === "object" &&
|
|
37
|
+
error !== null &&
|
|
38
|
+
"name" in error &&
|
|
39
|
+
error.name === "QuotaExceededError");
|
|
40
|
+
}
|
|
41
|
+
function persistReduxStateToLocalStorage(state) {
|
|
42
|
+
if (typeof document === "undefined") {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
localStorage.setItem(exports.LOCAL_STORAGE_REDUX_NAME, JSON.stringify(state));
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (isQuotaExceededError(error)) {
|
|
50
|
+
console.warn("[@zauru-sdk/redux] localStorage quota exceeded; Redux state was not persisted.", { key: exports.LOCAL_STORAGE_REDUX_NAME, error });
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
console.error("[@zauru-sdk/redux] Failed to persist Redux state to localStorage.", error);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
19
56
|
const persistanceLocalStorageMiddleware = (store) => (next) => (action) => {
|
|
20
57
|
const result = next(action);
|
|
21
|
-
|
|
22
|
-
localStorage.setItem(exports.LOCAL_STORAGE_REDUX_NAME, JSON.stringify(store.getState()));
|
|
23
|
-
}
|
|
58
|
+
persistReduxStateToLocalStorage(store.getState());
|
|
24
59
|
return result;
|
|
25
60
|
};
|
|
26
61
|
const buildSliceInitialStates = () => ({
|
|
@@ -124,11 +159,16 @@ const cleanLocalStorage = (whitelist = {}) => {
|
|
|
124
159
|
}
|
|
125
160
|
}
|
|
126
161
|
// Guarda el nuevo estado en el almacenamiento local
|
|
127
|
-
|
|
162
|
+
persistReduxStateToLocalStorage(newState);
|
|
128
163
|
}
|
|
129
164
|
}
|
|
130
165
|
catch (e) {
|
|
131
|
-
|
|
166
|
+
if (isQuotaExceededError(e)) {
|
|
167
|
+
console.warn("[@zauru-sdk/redux] localStorage quota exceeded while saving after cleanLocalStorage.", { key: exports.LOCAL_STORAGE_REDUX_NAME, error: e });
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
console.error("Ocurrió un error al clonar y eliminar el viejo localStorage", e);
|
|
171
|
+
}
|
|
132
172
|
}
|
|
133
173
|
};
|
|
134
174
|
exports.cleanLocalStorage = cleanLocalStorage;
|
package/dist/store.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import type { TypedUseSelectorHook } from "react-redux";
|
|
2
2
|
import { Tuple } from "@reduxjs/toolkit";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Full Redux snapshot key in `localStorage`. Written by
|
|
5
|
+
* `persistanceLocalStorageMiddleware` after every action.
|
|
6
|
+
*
|
|
7
|
+
* **QuotaExceededError:** Browsers cap `localStorage` per origin (often ~5MiB,
|
|
8
|
+
* not standardized). `setItem` throws `QuotaExceededError` when the new value
|
|
9
|
+
* plus existing data for that origin exceeds the cap.
|
|
10
|
+
*
|
|
11
|
+
* **Why only some tenants/devices:** Serialized state grows with cached
|
|
12
|
+
* catalogs (items, invoices, forms, etc.). Heavy tenants hit the limit sooner;
|
|
13
|
+
* private mode, Safari, or nearly full disks can lower the effective cap. Other
|
|
14
|
+
* apps on the same origin share the same quota.
|
|
15
|
+
*/
|
|
16
|
+
export declare const LOCAL_STORAGE_REDUX_NAME = "___redux__state__v7.0";
|
|
4
17
|
type Whitelist = {
|
|
5
18
|
[K in keyof RootState]?: string[];
|
|
6
19
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/redux",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.33.0",
|
|
4
4
|
"description": "Estructura de Redux propuesta para el desarrollo de webapps en Zauru.",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"react-redux": "^9.1.0",
|
|
32
32
|
"react-select": "^5.8.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "186e9f5d73be2baf7f1ee88437923e13e4e6b505"
|
|
35
35
|
}
|