@openmrs/esm-state 10.0.1-pre.5299 → 10.0.1-pre.5316
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/.turbo/turbo-build.log +1 -1
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +16 -0
- package/package.json +5 -5
- package/src/state.ts +24 -0
package/.turbo/turbo-build.log
CHANGED
package/dist/state.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AA2ChD,KAAK,WAAW,GAAG,MAAM,GAAG,gBAAgB,CAAC;AAE7C;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,EAAE,WAAW,GAAE,WAAoB,GAAG,QAAQ,CAAC,CAAC,CAAC,CAwBlH;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAsBpF;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC9B,IAAI,EAAE,MAAM,EACZ,aAAa,CAAC,EAAE,CAAC,EACjB,mBAAmB,GAAE,WAAoB,GACxC,QAAQ,CAAC,CAAC,CAAC,CAab;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;AAClG,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAC9B,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAClB,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,EACvB,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,IAAI,GAC5B,MAAM,IAAI,CAAC"}
|
package/dist/state.js
CHANGED
|
@@ -3,6 +3,22 @@ import { persist, createJSONStorage } from "zustand/middleware";
|
|
|
3
3
|
import { createStore } from "zustand/vanilla";
|
|
4
4
|
import { isTestEnvironment } from "./utils.js";
|
|
5
5
|
const availableStores = {};
|
|
6
|
+
/**
|
|
7
|
+
* Each copy of this module owns a separate `availableStores`, so a page running more than one copy
|
|
8
|
+
* has stores, config and extension state that cannot see each other. Nothing fails outright, which
|
|
9
|
+
* is what makes it expensive: the symptoms are missing state and "store already exists" errors far
|
|
10
|
+
* from the cause. The count lives on a global registry key rather than in module scope, since a
|
|
11
|
+
* second copy would not share module scope — that is the whole problem being detected.
|
|
12
|
+
*
|
|
13
|
+
* A hot reload re-evaluates this module and so also trips this, which is the honest answer: after a
|
|
14
|
+
* hot reload the page really is running two copies.
|
|
15
|
+
*/ const instanceCountKey = Symbol.for('openmrs.esm-state.instanceCount');
|
|
16
|
+
const globalCounters = globalThis;
|
|
17
|
+
const instanceCount = (globalCounters[instanceCountKey] ?? 0) + 1;
|
|
18
|
+
globalCounters[instanceCountKey] = instanceCount;
|
|
19
|
+
if (instanceCount > 1 && !isTestEnvironment()) {
|
|
20
|
+
console.error(`Detected ${instanceCount} copies of @openmrs/esm-framework running on this page. Each copy keeps ` + 'its own store registry, so stores, configuration and extension state are not shared between ' + 'them. This usually means a frontend module loaded its own bundled framework instead of the one ' + 'the app shell provides.');
|
|
21
|
+
}
|
|
6
22
|
// spaEnv isn't available immediately. Wait a bit before making stores available
|
|
7
23
|
// on window in development mode.
|
|
8
24
|
globalThis.setTimeout?.(()=>{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-state",
|
|
3
|
-
"version": "10.0.1-pre.
|
|
3
|
+
"version": "10.0.1-pre.5316",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "Frontend stores & state management for OpenMRS",
|
|
6
6
|
"type": "module",
|
|
@@ -58,12 +58,12 @@
|
|
|
58
58
|
"zustand": "^4.5.5"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
|
-
"@openmrs/esm-globals": "^10.0.1-pre.
|
|
62
|
-
"@openmrs/esm-utils": "^10.0.1-pre.
|
|
61
|
+
"@openmrs/esm-globals": "^10.0.1-pre.5316",
|
|
62
|
+
"@openmrs/esm-utils": "^10.0.1-pre.5316"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@openmrs/esm-globals": "10.0.1-pre.
|
|
66
|
-
"@openmrs/esm-utils": "10.0.1-pre.
|
|
65
|
+
"@openmrs/esm-globals": "10.0.1-pre.5316",
|
|
66
|
+
"@openmrs/esm-utils": "10.0.1-pre.5316",
|
|
67
67
|
"@swc/cli": "0.8.1",
|
|
68
68
|
"@swc/core": "1.15.21",
|
|
69
69
|
"@vitest/coverage-v8": "^4.1.2",
|
package/src/state.ts
CHANGED
|
@@ -13,6 +13,30 @@ interface StoreEntity {
|
|
|
13
13
|
|
|
14
14
|
const availableStores: Record<string, StoreEntity> = {};
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Each copy of this module owns a separate `availableStores`, so a page running more than one copy
|
|
18
|
+
* has stores, config and extension state that cannot see each other. Nothing fails outright, which
|
|
19
|
+
* is what makes it expensive: the symptoms are missing state and "store already exists" errors far
|
|
20
|
+
* from the cause. The count lives on a global registry key rather than in module scope, since a
|
|
21
|
+
* second copy would not share module scope — that is the whole problem being detected.
|
|
22
|
+
*
|
|
23
|
+
* A hot reload re-evaluates this module and so also trips this, which is the honest answer: after a
|
|
24
|
+
* hot reload the page really is running two copies.
|
|
25
|
+
*/
|
|
26
|
+
const instanceCountKey = Symbol.for('openmrs.esm-state.instanceCount');
|
|
27
|
+
const globalCounters = globalThis as unknown as Record<symbol, number | undefined>;
|
|
28
|
+
const instanceCount = (globalCounters[instanceCountKey] ?? 0) + 1;
|
|
29
|
+
globalCounters[instanceCountKey] = instanceCount;
|
|
30
|
+
|
|
31
|
+
if (instanceCount > 1 && !isTestEnvironment()) {
|
|
32
|
+
console.error(
|
|
33
|
+
`Detected ${instanceCount} copies of @openmrs/esm-framework running on this page. Each copy keeps ` +
|
|
34
|
+
'its own store registry, so stores, configuration and extension state are not shared between ' +
|
|
35
|
+
'them. This usually means a frontend module loaded its own bundled framework instead of the one ' +
|
|
36
|
+
'the app shell provides.',
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
16
40
|
// spaEnv isn't available immediately. Wait a bit before making stores available
|
|
17
41
|
// on window in development mode.
|
|
18
42
|
globalThis.setTimeout?.(() => {
|