@logixjs/react 0.1.0 → 1.0.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/LICENSE +201 -0
- package/README.md +1 -1
- package/dist/Hooks.cjs +462 -325
- package/dist/Hooks.d.cts +6 -6
- package/dist/Hooks.d.ts +6 -6
- package/dist/Hooks.js +3 -3
- package/dist/{ModuleRef-wZSQ3Wwo.d.cts → ModuleRef-gZmL6Zvb.d.cts} +8 -3
- package/dist/{ModuleRef-wZSQ3Wwo.d.ts → ModuleRef-gZmL6Zvb.d.ts} +8 -3
- package/dist/ModuleScope.cjs +596 -362
- package/dist/ModuleScope.d.cts +4 -4
- package/dist/ModuleScope.d.ts +4 -4
- package/dist/ModuleScope.js +4 -4
- package/dist/Platform.cjs +1 -4
- package/dist/Platform.d.cts +1 -2
- package/dist/Platform.d.ts +1 -2
- package/dist/Platform.js +1 -1
- package/dist/ReactPlatform.cjs +543 -309
- package/dist/ReactPlatform.d.cts +2 -2
- package/dist/ReactPlatform.d.ts +2 -2
- package/dist/ReactPlatform.js +5 -5
- package/dist/RuntimeProvider.cjs +276 -56
- package/dist/RuntimeProvider.js +2 -2
- package/dist/{chunk-PYWHL7TA.js → chunk-6NLXTHZ7.js} +8 -8
- package/dist/{chunk-UFFCJGSZ.js → chunk-E3ZXST5F.js} +256 -240
- package/dist/{chunk-4G7H66OY.js → chunk-KYWW4KMQ.js} +3 -3
- package/dist/{chunk-2WFULYPJ.js → chunk-L7KTYBXN.js} +155 -32
- package/dist/{chunk-ZANGOPUQ.js → chunk-NKYV44OG.js} +1 -4
- package/dist/{chunk-G5MRIFKK.js → chunk-SDQF3WRT.js} +7 -7
- package/dist/{chunk-JXAJTWSZ.js → chunk-XSGDBJXD.js} +122 -25
- package/dist/index.cjs +564 -333
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -7
- package/dist/{useDispatch-BnzYVkRE.d.ts → useDispatch-CiDimIYZ.d.ts} +13 -15
- package/dist/{useDispatch-CnO5-66H.d.cts → useDispatch-DiwQQAfC.d.cts} +13 -15
- package/package.json +12 -4
package/dist/ReactPlatform.cjs
CHANGED
|
@@ -45,7 +45,7 @@ var RuntimeContext = (0, import_react.createContext)(null);
|
|
|
45
45
|
|
|
46
46
|
// src/internal/provider/config.ts
|
|
47
47
|
var import_effect = require("effect");
|
|
48
|
-
var ReactRuntimeConfigTag = class extends import_effect.
|
|
48
|
+
var ReactRuntimeConfigTag = class extends import_effect.ServiceMap.Service()("@logixjs/react/RuntimeConfig") {
|
|
49
49
|
};
|
|
50
50
|
var DEFAULT_CONFIG = {
|
|
51
51
|
gcTime: 500,
|
|
@@ -155,13 +155,13 @@ var ReactRuntimeConfigSnapshot = {
|
|
|
155
155
|
})
|
|
156
156
|
};
|
|
157
157
|
|
|
158
|
+
// src/internal/provider/env.ts
|
|
159
|
+
var import_Env = require("@logixjs/core/Env");
|
|
160
|
+
|
|
158
161
|
// src/internal/provider/fallback.tsx
|
|
159
162
|
var import_react2 = require("react");
|
|
160
163
|
var Logix = __toESM(require("@logixjs/core"), 1);
|
|
161
164
|
|
|
162
|
-
// src/internal/provider/env.ts
|
|
163
|
-
var import_Env = require("@logixjs/core/Env");
|
|
164
|
-
|
|
165
165
|
// src/internal/provider/docs.ts
|
|
166
166
|
var LOGIX_DOCS_PREFIX_ENV = "LOGIX_DOCS_PREFIX";
|
|
167
167
|
var stripTrailingSlashes = (value) => value.replace(/\/+$/, "");
|
|
@@ -422,14 +422,11 @@ var useLayerBinding = (runtime, layer, enabled, onError) => {
|
|
|
422
422
|
const newScope = import_effect2.Effect.runSync(import_effect2.Scope.make());
|
|
423
423
|
const buildEffect = import_effect2.Effect.gen(function* () {
|
|
424
424
|
const context = yield* import_effect2.Layer.buildWithScope(layer, newScope);
|
|
425
|
-
const applyEnv = (effect) => import_effect2.Effect.
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
);
|
|
429
|
-
const loggers = yield* applyEnv(import_effect2.FiberRef.get(import_effect2.FiberRef.currentLoggers));
|
|
430
|
-
const logLevel = yield* applyEnv(import_effect2.FiberRef.get(import_effect2.FiberRef.currentLogLevel));
|
|
425
|
+
const applyEnv = (effect) => import_effect2.Scope.provide(newScope)(import_effect2.Effect.provideServices(effect, context));
|
|
426
|
+
const loggers = yield* applyEnv(import_effect2.Effect.service(import_effect2.Logger.CurrentLoggers)).pipe(import_effect2.Effect.orDie);
|
|
427
|
+
const logLevel = yield* applyEnv(import_effect2.Effect.service(import_effect2.References.MinimumLogLevel)).pipe(import_effect2.Effect.orDie);
|
|
431
428
|
const debugSinks = yield* applyEnv(
|
|
432
|
-
import_effect2.
|
|
429
|
+
import_effect2.Effect.service(Logix2.Debug.internal.currentDebugSinks).pipe(import_effect2.Effect.orDie)
|
|
433
430
|
);
|
|
434
431
|
return { context, loggers, logLevel, debugSinks };
|
|
435
432
|
});
|
|
@@ -474,7 +471,7 @@ var useLayerBinding = (runtime, layer, enabled, onError) => {
|
|
|
474
471
|
const cause = import_effect2.Cause.die(error);
|
|
475
472
|
runtime.runFork(
|
|
476
473
|
onError(cause, { source: "provider", phase: "provider.layer.build" }).pipe(
|
|
477
|
-
import_effect2.Effect.
|
|
474
|
+
import_effect2.Effect.catchCause(() => import_effect2.Effect.void)
|
|
478
475
|
)
|
|
479
476
|
);
|
|
480
477
|
}
|
|
@@ -512,18 +509,11 @@ var createRuntimeAdapter = (runtime, contexts, scopes, loggerSets, logLevels, de
|
|
|
512
509
|
if (contexts.length === 0 && scopes.length === 0 && loggerSets.length === 0 && logLevels.length === 0 && debugSinks.length === 0) {
|
|
513
510
|
return runtime;
|
|
514
511
|
}
|
|
515
|
-
const applyContexts = (effect) => (
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
acc,
|
|
521
|
-
(parent) => import_effect2.Context.merge(parent, ctx)
|
|
522
|
-
),
|
|
523
|
-
scopes.reduceRight(
|
|
524
|
-
(acc, scope) => import_effect2.Scope.extend(acc, scope),
|
|
525
|
-
effect
|
|
526
|
-
)
|
|
512
|
+
const applyContexts = (effect) => contexts.reduceRight(
|
|
513
|
+
(acc, ctx) => import_effect2.Effect.provideServices(acc, ctx),
|
|
514
|
+
scopes.reduceRight(
|
|
515
|
+
(acc, scope) => import_effect2.Scope.provide(scope)(acc),
|
|
516
|
+
effect
|
|
527
517
|
)
|
|
528
518
|
);
|
|
529
519
|
const applyLoggers = (effect) => {
|
|
@@ -532,16 +522,13 @@ var createRuntimeAdapter = (runtime, contexts, scopes, loggerSets, logLevels, de
|
|
|
532
522
|
const sinks = debugSinks.length > 0 ? debugSinks[debugSinks.length - 1] : null;
|
|
533
523
|
let result = effect;
|
|
534
524
|
if (last) {
|
|
535
|
-
result = import_effect2.Effect.
|
|
525
|
+
result = import_effect2.Effect.provideService(result, import_effect2.Logger.CurrentLoggers, last);
|
|
536
526
|
}
|
|
537
527
|
if (logLevel) {
|
|
538
|
-
result = import_effect2.Effect.
|
|
528
|
+
result = import_effect2.Effect.provideService(result, import_effect2.References.MinimumLogLevel, logLevel);
|
|
539
529
|
}
|
|
540
530
|
if (sinks && sinks.length > 0) {
|
|
541
|
-
result = import_effect2.Effect.
|
|
542
|
-
Logix2.Debug.internal.currentDebugSinks,
|
|
543
|
-
sinks
|
|
544
|
-
)(result);
|
|
531
|
+
result = import_effect2.Effect.provideService(result, Logix2.Debug.internal.currentDebugSinks, sinks);
|
|
545
532
|
}
|
|
546
533
|
return result;
|
|
547
534
|
};
|
|
@@ -672,9 +659,9 @@ ${message}`;
|
|
|
672
659
|
console.debug(label, message);
|
|
673
660
|
};
|
|
674
661
|
var causeToUnknown = (cause) => {
|
|
675
|
-
const failure = import_effect4.Option.getOrUndefined(import_effect4.Cause.
|
|
662
|
+
const failure = import_effect4.Option.getOrUndefined(import_effect4.Cause.findErrorOption(cause));
|
|
676
663
|
if (failure !== void 0) return failure;
|
|
677
|
-
const defect =
|
|
664
|
+
const defect = cause.reasons.filter(import_effect4.Cause.isDieReason).map((reason) => reason.defect)[0];
|
|
678
665
|
if (defect !== void 0) return defect;
|
|
679
666
|
return cause;
|
|
680
667
|
};
|
|
@@ -683,7 +670,7 @@ var yieldEffect = (strategy) => {
|
|
|
683
670
|
case "none":
|
|
684
671
|
return import_effect4.Effect.void;
|
|
685
672
|
case "microtask":
|
|
686
|
-
return import_effect4.Effect.yieldNow
|
|
673
|
+
return import_effect4.Effect.yieldNow;
|
|
687
674
|
case "macrotask":
|
|
688
675
|
return import_effect4.Effect.promise(
|
|
689
676
|
() => new Promise((resolve) => {
|
|
@@ -776,6 +763,67 @@ var ModuleCache = class {
|
|
|
776
763
|
const scope = import_effect4.Effect.runSync(import_effect4.Scope.make());
|
|
777
764
|
const workloadKey = `${options?.entrypoint ?? "unknown"}::${ownerId ?? "unknown"}`;
|
|
778
765
|
const yieldDecision = decideYieldStrategy(this.runtime, workloadKey, options?.yield);
|
|
766
|
+
const optimisticSyncBudgetMs = options?.optimisticSyncBudgetMs ?? 0;
|
|
767
|
+
const shouldTryOptimisticSync = options?.policyMode === "suspend" && optimisticSyncBudgetMs > 0;
|
|
768
|
+
if (shouldTryOptimisticSync) {
|
|
769
|
+
const startedAt2 = performance.now();
|
|
770
|
+
try {
|
|
771
|
+
const value = this.runtime.runSync(factory(scope));
|
|
772
|
+
const durationMs = performance.now() - startedAt2;
|
|
773
|
+
YieldBudgetMemory.record({ runtime: this.runtime, workloadKey, durationMs });
|
|
774
|
+
const entry2 = {
|
|
775
|
+
scope,
|
|
776
|
+
status: "success",
|
|
777
|
+
promise: Promise.resolve(value),
|
|
778
|
+
value,
|
|
779
|
+
refCount: 0,
|
|
780
|
+
preloadRefCount: 0,
|
|
781
|
+
gcTime: gcTime ?? this.gcDelayMs,
|
|
782
|
+
ownerId,
|
|
783
|
+
createdBy: "read",
|
|
784
|
+
workloadKey,
|
|
785
|
+
yieldStrategy: "none"
|
|
786
|
+
};
|
|
787
|
+
this.scheduleGC(key, entry2);
|
|
788
|
+
this.entries.set(key, entry2);
|
|
789
|
+
if ((0, import_Env.isDevEnv)() || Logix4.Debug.isDevtoolsEnabled()) {
|
|
790
|
+
void this.runtime.runPromise(
|
|
791
|
+
Logix4.Debug.record({
|
|
792
|
+
type: "trace:react.module.init",
|
|
793
|
+
moduleId: ownerId,
|
|
794
|
+
instanceId: value.instanceId,
|
|
795
|
+
data: {
|
|
796
|
+
mode: "suspend",
|
|
797
|
+
key,
|
|
798
|
+
durationMs: Math.round(durationMs * 100) / 100,
|
|
799
|
+
yieldStrategy: "none",
|
|
800
|
+
fastPath: "sync"
|
|
801
|
+
}
|
|
802
|
+
})
|
|
803
|
+
).catch((error) => {
|
|
804
|
+
debugBestEffortFailure("[ModuleCache] Debug.record failed", error);
|
|
805
|
+
});
|
|
806
|
+
void this.runtime.runPromise(
|
|
807
|
+
Logix4.Debug.record({
|
|
808
|
+
type: "trace:react.module-instance",
|
|
809
|
+
moduleId: ownerId,
|
|
810
|
+
instanceId: value.instanceId,
|
|
811
|
+
data: {
|
|
812
|
+
event: "attach",
|
|
813
|
+
key,
|
|
814
|
+
mode: "suspend",
|
|
815
|
+
gcTime: entry2.gcTime,
|
|
816
|
+
fastPath: "sync"
|
|
817
|
+
}
|
|
818
|
+
})
|
|
819
|
+
).catch((error) => {
|
|
820
|
+
debugBestEffortFailure("[ModuleCache] Debug.record failed", error);
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
return value;
|
|
824
|
+
} catch {
|
|
825
|
+
}
|
|
826
|
+
}
|
|
779
827
|
const entry = {
|
|
780
828
|
scope,
|
|
781
829
|
status: "pending",
|
|
@@ -791,7 +839,7 @@ var ModuleCache = class {
|
|
|
791
839
|
};
|
|
792
840
|
this.scheduleGC(key, entry);
|
|
793
841
|
const startedAt = performance.now();
|
|
794
|
-
const buildEffect = yieldEffect(yieldDecision.strategy).pipe(import_effect4.Effect.
|
|
842
|
+
const buildEffect = yieldEffect(yieldDecision.strategy).pipe(import_effect4.Effect.flatMap(() => factory(scope)));
|
|
795
843
|
const fiber = this.runtime.runFork(buildEffect);
|
|
796
844
|
entry.fiber = fiber;
|
|
797
845
|
const promise = this.runtime.runPromise(import_effect4.Fiber.await(fiber)).then((exit) => {
|
|
@@ -987,6 +1035,49 @@ var ModuleCache = class {
|
|
|
987
1035
|
throw error;
|
|
988
1036
|
}
|
|
989
1037
|
}
|
|
1038
|
+
warmSync(key, factory, gcTime, ownerId, options) {
|
|
1039
|
+
const existing = this.entries.get(key);
|
|
1040
|
+
if (existing) {
|
|
1041
|
+
if ((0, import_Env.isDevEnv)() && existing.ownerId !== void 0 && ownerId !== void 0 && existing.ownerId !== ownerId) {
|
|
1042
|
+
throw new Error(
|
|
1043
|
+
`[ModuleCache.warmSync] resource key "${key}" has already been claimed by module "${existing.ownerId}", but is now requested by module "${ownerId}".`
|
|
1044
|
+
);
|
|
1045
|
+
}
|
|
1046
|
+
if (existing.status === "success") {
|
|
1047
|
+
return existing.value;
|
|
1048
|
+
}
|
|
1049
|
+
return void 0;
|
|
1050
|
+
}
|
|
1051
|
+
const scope = this.runtime.runSync(import_effect4.Scope.make());
|
|
1052
|
+
const startedAt = performance.now();
|
|
1053
|
+
const workloadKey = `${options?.entrypoint ?? "unknown"}::${ownerId ?? "unknown"}`;
|
|
1054
|
+
try {
|
|
1055
|
+
const value = this.runtime.runSync(factory(scope));
|
|
1056
|
+
const durationMs = performance.now() - startedAt;
|
|
1057
|
+
YieldBudgetMemory.record({ runtime: this.runtime, workloadKey, durationMs });
|
|
1058
|
+
const entry = {
|
|
1059
|
+
scope,
|
|
1060
|
+
status: "success",
|
|
1061
|
+
promise: Promise.resolve(value),
|
|
1062
|
+
value,
|
|
1063
|
+
refCount: 0,
|
|
1064
|
+
preloadRefCount: 0,
|
|
1065
|
+
gcTime: gcTime ?? this.gcDelayMs,
|
|
1066
|
+
ownerId,
|
|
1067
|
+
createdBy: "preload",
|
|
1068
|
+
workloadKey,
|
|
1069
|
+
yieldStrategy: "none"
|
|
1070
|
+
};
|
|
1071
|
+
this.scheduleGC(key, entry);
|
|
1072
|
+
this.entries.set(key, entry);
|
|
1073
|
+
return value;
|
|
1074
|
+
} catch (error) {
|
|
1075
|
+
void this.runtime.runPromise(import_effect4.Scope.close(scope, import_effect4.Exit.fail(error))).catch((closeError) => {
|
|
1076
|
+
debugBestEffortFailure("[ModuleCache] Scope.close failed", closeError);
|
|
1077
|
+
});
|
|
1078
|
+
return void 0;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
990
1081
|
preload(key, factory, options) {
|
|
991
1082
|
const existing = this.entries.get(key);
|
|
992
1083
|
if (existing) {
|
|
@@ -1016,6 +1107,38 @@ var ModuleCache = class {
|
|
|
1016
1107
|
const gcTime = options?.gcTime ?? this.gcDelayMs;
|
|
1017
1108
|
const workloadKey = `${options?.entrypoint ?? "unknown"}::${ownerId ?? "unknown"}`;
|
|
1018
1109
|
const yieldDecision = decideYieldStrategy(this.runtime, workloadKey, options?.yield);
|
|
1110
|
+
const optimisticSyncBudgetMs = options?.optimisticSyncBudgetMs ?? 0;
|
|
1111
|
+
const shouldTryOptimisticSync = options?.policyMode === "defer" && optimisticSyncBudgetMs > 0;
|
|
1112
|
+
if (shouldTryOptimisticSync) {
|
|
1113
|
+
const startedAt2 = performance.now();
|
|
1114
|
+
try {
|
|
1115
|
+
const value = this.runtime.runSync(factory(scope));
|
|
1116
|
+
const durationMs = performance.now() - startedAt2;
|
|
1117
|
+
YieldBudgetMemory.record({ runtime: this.runtime, workloadKey, durationMs });
|
|
1118
|
+
const entry2 = {
|
|
1119
|
+
scope,
|
|
1120
|
+
status: "success",
|
|
1121
|
+
promise: Promise.resolve(value),
|
|
1122
|
+
value,
|
|
1123
|
+
refCount: 0,
|
|
1124
|
+
preloadRefCount: 1,
|
|
1125
|
+
gcTime,
|
|
1126
|
+
ownerId,
|
|
1127
|
+
createdBy: "preload",
|
|
1128
|
+
workloadKey,
|
|
1129
|
+
yieldStrategy: "none"
|
|
1130
|
+
};
|
|
1131
|
+
this.scheduleGC(key, entry2);
|
|
1132
|
+
this.entries.set(key, entry2);
|
|
1133
|
+
return {
|
|
1134
|
+
promise: Promise.resolve(value),
|
|
1135
|
+
cancel: () => {
|
|
1136
|
+
this.cancelPreload(key, entry2);
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
1139
|
+
} catch {
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1019
1142
|
const entry = {
|
|
1020
1143
|
scope,
|
|
1021
1144
|
status: "pending",
|
|
@@ -1031,7 +1154,7 @@ var ModuleCache = class {
|
|
|
1031
1154
|
this.scheduleGC(key, entry);
|
|
1032
1155
|
this.entries.set(key, entry);
|
|
1033
1156
|
const startedAt = performance.now();
|
|
1034
|
-
const buildEffect = yieldEffect(yieldDecision.strategy).pipe(import_effect4.Effect.
|
|
1157
|
+
const buildEffect = yieldEffect(yieldDecision.strategy).pipe(import_effect4.Effect.flatMap(() => factory(scope)));
|
|
1035
1158
|
const fiber = this.runtime.runFork(buildEffect);
|
|
1036
1159
|
entry.fiber = fiber;
|
|
1037
1160
|
const promise = this.runtime.runPromise(import_effect4.Fiber.await(fiber)).then((exit) => {
|
|
@@ -1270,6 +1393,9 @@ var RuntimeProvider = ({
|
|
|
1270
1393
|
}) => {
|
|
1271
1394
|
const parent = (0, import_react4.useContext)(RuntimeContext);
|
|
1272
1395
|
const baseRuntime = useRuntimeResolution(runtime, parent);
|
|
1396
|
+
const providerStartedAtRef = import_react4.default.useRef(performance.now());
|
|
1397
|
+
const providerReadyAtRef = import_react4.default.useRef(void 0);
|
|
1398
|
+
const didReportProviderGatingRef = import_react4.default.useRef(false);
|
|
1273
1399
|
const resolvedPolicy = (0, import_react4.useMemo)(
|
|
1274
1400
|
() => resolveRuntimeProviderPolicy({
|
|
1275
1401
|
policy,
|
|
@@ -1279,6 +1405,20 @@ var RuntimeProvider = ({
|
|
|
1279
1405
|
);
|
|
1280
1406
|
const onErrorRef = import_react4.default.useRef(onError);
|
|
1281
1407
|
onErrorRef.current = onError;
|
|
1408
|
+
const hasTickServices = (0, import_react4.useMemo)(() => {
|
|
1409
|
+
try {
|
|
1410
|
+
Logix5.InternalContracts.getRuntimeStore(baseRuntime);
|
|
1411
|
+
return true;
|
|
1412
|
+
} catch {
|
|
1413
|
+
return false;
|
|
1414
|
+
}
|
|
1415
|
+
}, [baseRuntime]);
|
|
1416
|
+
const { binding: tickBinding } = useLayerBinding(
|
|
1417
|
+
baseRuntime,
|
|
1418
|
+
Logix5.InternalContracts.tickServicesLayer,
|
|
1419
|
+
!hasTickServices,
|
|
1420
|
+
onErrorRef.current
|
|
1421
|
+
);
|
|
1282
1422
|
const { binding: layerBinding } = useLayerBinding(baseRuntime, layer, Boolean(layer), onErrorRef.current);
|
|
1283
1423
|
const onErrorSink = (0, import_react4.useMemo)(() => {
|
|
1284
1424
|
if (!onError) return null;
|
|
@@ -1295,7 +1435,7 @@ var RuntimeProvider = ({
|
|
|
1295
1435
|
moduleId: event.moduleId,
|
|
1296
1436
|
instanceId: event.instanceId,
|
|
1297
1437
|
runtimeLabel: event.runtimeLabel
|
|
1298
|
-
}).pipe(import_effect5.Effect.
|
|
1438
|
+
}).pipe(import_effect5.Effect.catchCause(() => import_effect5.Effect.void));
|
|
1299
1439
|
}
|
|
1300
1440
|
if (event.type === "diagnostic" && event.severity === "error") {
|
|
1301
1441
|
return handler(
|
|
@@ -1314,7 +1454,7 @@ var RuntimeProvider = ({
|
|
|
1314
1454
|
instanceId: event.instanceId,
|
|
1315
1455
|
runtimeLabel: event.runtimeLabel
|
|
1316
1456
|
}
|
|
1317
|
-
).pipe(import_effect5.Effect.
|
|
1457
|
+
).pipe(import_effect5.Effect.catchCause(() => import_effect5.Effect.void));
|
|
1318
1458
|
}
|
|
1319
1459
|
return import_effect5.Effect.void;
|
|
1320
1460
|
}
|
|
@@ -1329,25 +1469,23 @@ var RuntimeProvider = ({
|
|
|
1329
1469
|
return layerBinding.debugSinks;
|
|
1330
1470
|
}
|
|
1331
1471
|
try {
|
|
1332
|
-
return baseRuntime.runSync(
|
|
1333
|
-
import_effect5.FiberRef.get(Logix5.Debug.internal.currentDebugSinks)
|
|
1334
|
-
);
|
|
1472
|
+
return baseRuntime.runSync(import_effect5.Effect.service(Logix5.Debug.internal.currentDebugSinks).pipe(import_effect5.Effect.orDie));
|
|
1335
1473
|
} catch {
|
|
1336
1474
|
return [];
|
|
1337
1475
|
}
|
|
1338
1476
|
}, [baseRuntime, layerBinding, onErrorSink]);
|
|
1339
1477
|
const runtimeWithBindings = (0, import_react4.useMemo)(
|
|
1340
|
-
() => layerBinding || onErrorSink ? createRuntimeAdapter(
|
|
1478
|
+
() => tickBinding || layerBinding || onErrorSink ? createRuntimeAdapter(
|
|
1341
1479
|
baseRuntime,
|
|
1342
|
-
layerBinding ? [layerBinding.context] : [],
|
|
1343
|
-
layerBinding ? [layerBinding.scope] : [],
|
|
1344
|
-
layerBinding ? [layerBinding.loggers] : [],
|
|
1345
|
-
layerBinding ? [layerBinding.logLevel] : [],
|
|
1480
|
+
[...tickBinding ? [tickBinding.context] : [], ...layerBinding ? [layerBinding.context] : []],
|
|
1481
|
+
[...tickBinding ? [tickBinding.scope] : [], ...layerBinding ? [layerBinding.scope] : []],
|
|
1482
|
+
layerBinding ? [layerBinding.loggers] : tickBinding ? [tickBinding.loggers] : [],
|
|
1483
|
+
layerBinding ? [layerBinding.logLevel] : tickBinding ? [tickBinding.logLevel] : [],
|
|
1346
1484
|
[
|
|
1347
1485
|
onErrorSink ? [onErrorSink, ...inheritedDebugSinks] : layerBinding ? layerBinding.debugSinks : []
|
|
1348
1486
|
]
|
|
1349
1487
|
) : baseRuntime,
|
|
1350
|
-
[baseRuntime, inheritedDebugSinks, layerBinding, onErrorSink]
|
|
1488
|
+
[baseRuntime, inheritedDebugSinks, layerBinding, onErrorSink, tickBinding]
|
|
1351
1489
|
);
|
|
1352
1490
|
const didReportSyncConfigSnapshotRef = import_react4.default.useRef(false);
|
|
1353
1491
|
const [configState, setConfigState] = (0, import_react4.useState)(() => {
|
|
@@ -1452,11 +1590,47 @@ var RuntimeProvider = ({
|
|
|
1452
1590
|
}),
|
|
1453
1591
|
[runtimeWithBindings, configState, resolvedPolicy]
|
|
1454
1592
|
);
|
|
1593
|
+
const isTickServicesReady = hasTickServices || tickBinding !== null;
|
|
1455
1594
|
const isLayerReady = !layer || layerBinding !== null;
|
|
1456
1595
|
const isConfigReady = configState.loaded;
|
|
1457
1596
|
const resolveFallback = (phase) => {
|
|
1458
1597
|
return resolveRuntimeProviderFallback({ fallback, phase, policyMode: resolvedPolicy.mode });
|
|
1459
1598
|
};
|
|
1599
|
+
const preloadCache = (0, import_react4.useMemo)(
|
|
1600
|
+
() => getModuleCache(runtimeWithBindings, configState.snapshot, configState.version),
|
|
1601
|
+
[runtimeWithBindings, configState.snapshot, configState.version]
|
|
1602
|
+
);
|
|
1603
|
+
const syncWarmPreloadReady = (0, import_react4.useMemo)(() => {
|
|
1604
|
+
if (resolvedPolicy.mode !== "defer") return false;
|
|
1605
|
+
if (!resolvedPolicy.preload) return true;
|
|
1606
|
+
if (!isLayerReady || !isConfigReady) return false;
|
|
1607
|
+
const handles = resolvedPolicy.preload.handles;
|
|
1608
|
+
if (handles.length === 0) return true;
|
|
1609
|
+
for (const handle of handles) {
|
|
1610
|
+
if (handle?._tag === "ModuleImpl") {
|
|
1611
|
+
const moduleId = handle.module?.id ?? "ModuleImpl";
|
|
1612
|
+
const key2 = resolvedPolicy.preload.keysByModuleId.get(moduleId) ?? getPreloadKeyForModuleId(moduleId);
|
|
1613
|
+
const factory2 = (scope) => import_effect5.Layer.buildWithScope(handle.layer, scope).pipe(
|
|
1614
|
+
import_effect5.Effect.map((context) => import_effect5.ServiceMap.get(context, handle.module))
|
|
1615
|
+
);
|
|
1616
|
+
const value2 = preloadCache.warmSync(key2, factory2, configState.snapshot.gcTime, moduleId, {
|
|
1617
|
+
entrypoint: "react.runtime.preload.sync-warm",
|
|
1618
|
+
policyMode: "defer"
|
|
1619
|
+
});
|
|
1620
|
+
if (!value2) return false;
|
|
1621
|
+
continue;
|
|
1622
|
+
}
|
|
1623
|
+
const tagId = handle.id ?? "ModuleTag";
|
|
1624
|
+
const key = resolvedPolicy.preload.keysByTagId.get(tagId) ?? getPreloadKeyForTagId(tagId);
|
|
1625
|
+
const factory = (scope) => import_effect5.Scope.provide(scope)(import_effect5.Effect.service(handle).pipe(import_effect5.Effect.orDie));
|
|
1626
|
+
const value = preloadCache.warmSync(key, factory, configState.snapshot.gcTime, tagId, {
|
|
1627
|
+
entrypoint: "react.runtime.preload.sync-warm",
|
|
1628
|
+
policyMode: "defer"
|
|
1629
|
+
});
|
|
1630
|
+
if (!value) return false;
|
|
1631
|
+
}
|
|
1632
|
+
return true;
|
|
1633
|
+
}, [resolvedPolicy, isLayerReady, isConfigReady, preloadCache, configState.snapshot.gcTime]);
|
|
1460
1634
|
const [deferReady, setDeferReady] = (0, import_react4.useState)(false);
|
|
1461
1635
|
(0, import_react4.useEffect)(() => {
|
|
1462
1636
|
if (resolvedPolicy.mode !== "defer") {
|
|
@@ -1470,6 +1644,10 @@ var RuntimeProvider = ({
|
|
|
1470
1644
|
if (resolvedPolicy.mode !== "defer") {
|
|
1471
1645
|
return;
|
|
1472
1646
|
}
|
|
1647
|
+
if (syncWarmPreloadReady) {
|
|
1648
|
+
setDeferReady(true);
|
|
1649
|
+
return;
|
|
1650
|
+
}
|
|
1473
1651
|
setDeferReady(false);
|
|
1474
1652
|
if (!resolvedPolicy.preload) {
|
|
1475
1653
|
setDeferReady(true);
|
|
@@ -1479,7 +1657,7 @@ var RuntimeProvider = ({
|
|
|
1479
1657
|
return;
|
|
1480
1658
|
}
|
|
1481
1659
|
let cancelled = false;
|
|
1482
|
-
const cache =
|
|
1660
|
+
const cache = preloadCache;
|
|
1483
1661
|
const preloadHandles = resolvedPolicy.preload.handles;
|
|
1484
1662
|
if (preloadHandles.length === 0) {
|
|
1485
1663
|
setDeferReady(true);
|
|
@@ -1497,13 +1675,14 @@ var RuntimeProvider = ({
|
|
|
1497
1675
|
const moduleId = handle.module?.id ?? "ModuleImpl";
|
|
1498
1676
|
const key2 = resolvedPolicy.preload.keysByModuleId.get(moduleId) ?? getPreloadKeyForModuleId(moduleId);
|
|
1499
1677
|
const factory2 = (scope) => import_effect5.Layer.buildWithScope(handle.layer, scope).pipe(
|
|
1500
|
-
import_effect5.Effect.map((context) => import_effect5.
|
|
1678
|
+
import_effect5.Effect.map((context) => import_effect5.ServiceMap.get(context, handle.module))
|
|
1501
1679
|
);
|
|
1502
1680
|
const op2 = cache.preload(key2, factory2, {
|
|
1503
1681
|
ownerId: moduleId,
|
|
1504
1682
|
yield: resolvedPolicy.preload.yield,
|
|
1505
1683
|
entrypoint: "react.runtime.preload",
|
|
1506
|
-
policyMode: "defer"
|
|
1684
|
+
policyMode: "defer",
|
|
1685
|
+
optimisticSyncBudgetMs: resolvedPolicy.syncBudgetMs
|
|
1507
1686
|
});
|
|
1508
1687
|
allCancels.add(op2.cancel);
|
|
1509
1688
|
await op2.promise;
|
|
@@ -1528,14 +1707,13 @@ var RuntimeProvider = ({
|
|
|
1528
1707
|
}
|
|
1529
1708
|
const tagId = handle.id ?? "ModuleTag";
|
|
1530
1709
|
const key = resolvedPolicy.preload.keysByTagId.get(tagId) ?? getPreloadKeyForTagId(tagId);
|
|
1531
|
-
const factory = (scope) => handle.pipe(
|
|
1532
|
-
import_effect5.Scope.extend(scope)
|
|
1533
|
-
);
|
|
1710
|
+
const factory = (scope) => import_effect5.Scope.provide(scope)(import_effect5.Effect.service(handle).pipe(import_effect5.Effect.orDie));
|
|
1534
1711
|
const op = cache.preload(key, factory, {
|
|
1535
1712
|
ownerId: tagId,
|
|
1536
1713
|
yield: resolvedPolicy.preload.yield,
|
|
1537
1714
|
entrypoint: "react.runtime.preload",
|
|
1538
|
-
policyMode: "defer"
|
|
1715
|
+
policyMode: "defer",
|
|
1716
|
+
optimisticSyncBudgetMs: resolvedPolicy.syncBudgetMs
|
|
1539
1717
|
});
|
|
1540
1718
|
allCancels.add(op.cancel);
|
|
1541
1719
|
await op.promise;
|
|
@@ -1573,7 +1751,7 @@ var RuntimeProvider = ({
|
|
|
1573
1751
|
if (cancelled) return;
|
|
1574
1752
|
if (onErrorRef.current) {
|
|
1575
1753
|
runtimeWithBindings.runFork(
|
|
1576
|
-
onErrorRef.current(import_effect5.Cause.die(error), { source: "provider", phase: "provider.layer.build" }).pipe(import_effect5.Effect.
|
|
1754
|
+
onErrorRef.current(import_effect5.Cause.die(error), { source: "provider", phase: "provider.layer.build" }).pipe(import_effect5.Effect.catchCause(() => import_effect5.Effect.void))
|
|
1577
1755
|
);
|
|
1578
1756
|
}
|
|
1579
1757
|
setDeferReady(true);
|
|
@@ -1606,12 +1784,54 @@ var RuntimeProvider = ({
|
|
|
1606
1784
|
release();
|
|
1607
1785
|
};
|
|
1608
1786
|
}, [resolvedPolicy.mode, deferReady]);
|
|
1609
|
-
const isReady = isLayerReady && isConfigReady && (resolvedPolicy.mode !== "defer" || deferReady);
|
|
1787
|
+
const isReady = isTickServicesReady && isLayerReady && isConfigReady && (resolvedPolicy.mode !== "defer" || deferReady || syncWarmPreloadReady);
|
|
1788
|
+
if (isReady && providerReadyAtRef.current === void 0) {
|
|
1789
|
+
providerReadyAtRef.current = performance.now();
|
|
1790
|
+
}
|
|
1791
|
+
(0, import_react4.useEffect)(() => {
|
|
1792
|
+
if (!isReady) {
|
|
1793
|
+
return;
|
|
1794
|
+
}
|
|
1795
|
+
if (didReportProviderGatingRef.current) {
|
|
1796
|
+
return;
|
|
1797
|
+
}
|
|
1798
|
+
let diagnosticsLevel = "off";
|
|
1799
|
+
try {
|
|
1800
|
+
diagnosticsLevel = runtimeWithBindings.runSync(
|
|
1801
|
+
import_effect5.Effect.service(Logix5.Debug.internal.currentDiagnosticsLevel).pipe(import_effect5.Effect.orDie)
|
|
1802
|
+
);
|
|
1803
|
+
} catch {
|
|
1804
|
+
diagnosticsLevel = (0, import_Env.isDevEnv)() ? "light" : "off";
|
|
1805
|
+
}
|
|
1806
|
+
if (diagnosticsLevel === "off") {
|
|
1807
|
+
return;
|
|
1808
|
+
}
|
|
1809
|
+
didReportProviderGatingRef.current = true;
|
|
1810
|
+
const readyAt = providerReadyAtRef.current ?? performance.now();
|
|
1811
|
+
const durationMs = Math.round((readyAt - providerStartedAtRef.current) * 100) / 100;
|
|
1812
|
+
const effectDelayMs = Math.round((performance.now() - readyAt) * 100) / 100;
|
|
1813
|
+
void runtimeWithBindings.runPromise(
|
|
1814
|
+
Logix5.Debug.record({
|
|
1815
|
+
type: "trace:react.provider.gating",
|
|
1816
|
+
data: {
|
|
1817
|
+
event: "ready",
|
|
1818
|
+
policyMode: resolvedPolicy.mode,
|
|
1819
|
+
durationMs,
|
|
1820
|
+
effectDelayMs,
|
|
1821
|
+
configLoadMode: configState.loadMode,
|
|
1822
|
+
syncOverBudget: Boolean(configState.syncOverBudget),
|
|
1823
|
+
syncDurationMs: configState.syncDurationMs !== void 0 ? Math.round(configState.syncDurationMs * 100) / 100 : void 0
|
|
1824
|
+
}
|
|
1825
|
+
})
|
|
1826
|
+
).catch(() => {
|
|
1827
|
+
});
|
|
1828
|
+
}, [configState.loadMode, configState.syncDurationMs, configState.syncOverBudget, isReady, resolvedPolicy.mode, runtimeWithBindings]);
|
|
1610
1829
|
if (!isReady) {
|
|
1611
1830
|
const blockersList = [
|
|
1831
|
+
isTickServicesReady ? null : "tick",
|
|
1612
1832
|
isLayerReady ? null : "layer",
|
|
1613
1833
|
isConfigReady ? null : "config",
|
|
1614
|
-
resolvedPolicy.mode !== "defer" || deferReady ? null : "preload"
|
|
1834
|
+
resolvedPolicy.mode !== "defer" || deferReady || syncWarmPreloadReady ? null : "preload"
|
|
1615
1835
|
].filter((x) => x !== null);
|
|
1616
1836
|
const blockers = blockersList.length > 0 ? blockersList.join("+") : void 0;
|
|
1617
1837
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
@@ -1724,13 +1944,13 @@ function useRuntime(options) {
|
|
|
1724
1944
|
|
|
1725
1945
|
// src/internal/hooks/useModule.ts
|
|
1726
1946
|
var import_react9 = __toESM(require("react"), 1);
|
|
1727
|
-
var
|
|
1947
|
+
var Logix11 = __toESM(require("@logixjs/core"), 1);
|
|
1728
1948
|
var import_effect10 = require("effect");
|
|
1729
1949
|
|
|
1730
1950
|
// src/internal/hooks/useModuleRuntime.ts
|
|
1731
1951
|
var import_react6 = require("react");
|
|
1732
|
-
var
|
|
1733
|
-
var
|
|
1952
|
+
var Logix7 = __toESM(require("@logixjs/core"), 1);
|
|
1953
|
+
var import_effect8 = require("effect");
|
|
1734
1954
|
|
|
1735
1955
|
// src/internal/store/ModuleRef.ts
|
|
1736
1956
|
var isModuleRef = (value) => typeof value === "object" && value !== null && "runtime" in value && "actions" in value && "dispatch" in value;
|
|
@@ -1821,11 +2041,26 @@ var applyHandleExtend = (tag, runtime, base) => {
|
|
|
1821
2041
|
return { ...base, ...next };
|
|
1822
2042
|
};
|
|
1823
2043
|
|
|
2044
|
+
// src/internal/provider/runtimeDebugBridge.ts
|
|
2045
|
+
var import_effect7 = require("effect");
|
|
2046
|
+
var Logix6 = __toESM(require("@logixjs/core"), 1);
|
|
2047
|
+
var readRuntimeDiagnosticsLevel = (runtime) => {
|
|
2048
|
+
try {
|
|
2049
|
+
return runtime.runSync(import_effect7.Effect.service(Logix6.Debug.internal.currentDiagnosticsLevel).pipe(import_effect7.Effect.orDie));
|
|
2050
|
+
} catch {
|
|
2051
|
+
return (0, import_Env.isDevEnv)() ? "light" : "off";
|
|
2052
|
+
}
|
|
2053
|
+
};
|
|
2054
|
+
var emitRuntimeDebugEventBestEffort = (runtime, event) => {
|
|
2055
|
+
runtime.runFork(event);
|
|
2056
|
+
};
|
|
2057
|
+
|
|
1824
2058
|
// src/internal/hooks/useModuleRuntime.ts
|
|
1825
2059
|
var isModuleRuntime = (value) => typeof value === "object" && value !== null && "dispatch" in value && "getState" in value;
|
|
1826
2060
|
function useModuleRuntime(handle) {
|
|
1827
2061
|
const runtime = useRuntime();
|
|
1828
2062
|
const runtimeContext = (0, import_react6.useContext)(RuntimeContext);
|
|
2063
|
+
const moduleTagResolveTraceRef = (0, import_react6.useRef)(void 0);
|
|
1829
2064
|
if (!runtimeContext) {
|
|
1830
2065
|
throw new RuntimeProviderNotFoundError("useModuleRuntime");
|
|
1831
2066
|
}
|
|
@@ -1846,36 +2081,48 @@ function useModuleRuntime(handle) {
|
|
|
1846
2081
|
const preloadKey = runtimeContext.policy.preload?.keysByTagId.get(tokenId);
|
|
1847
2082
|
const key = preloadKey ?? `tag:${tokenId}`;
|
|
1848
2083
|
const mode = runtimeContext.policy.moduleTagMode;
|
|
1849
|
-
const
|
|
1850
|
-
|
|
2084
|
+
const startedAtMs = performance.now();
|
|
2085
|
+
const factory = (scope) => import_effect8.Scope.provide(scope)(import_effect8.Effect.service(tag).pipe(import_effect8.Effect.orDie));
|
|
2086
|
+
const resolvedRuntime = mode === "suspend" ? cache.read(key, factory, void 0, tokenId, {
|
|
1851
2087
|
entrypoint: "react.useModuleRuntime",
|
|
1852
2088
|
policyMode: runtimeContext.policy.mode,
|
|
1853
|
-
yield: runtimeContext.policy.yield
|
|
2089
|
+
yield: runtimeContext.policy.yield,
|
|
2090
|
+
optimisticSyncBudgetMs: runtimeContext.policy.syncBudgetMs
|
|
1854
2091
|
}) : cache.readSync(key, factory, void 0, tokenId, {
|
|
1855
2092
|
entrypoint: "react.useModuleRuntime",
|
|
1856
2093
|
policyMode: runtimeContext.policy.mode,
|
|
1857
2094
|
warnSyncBlockingThresholdMs: 5
|
|
1858
2095
|
});
|
|
2096
|
+
moduleTagResolveTraceRef.current = {
|
|
2097
|
+
tokenId,
|
|
2098
|
+
durationMs: Math.round((performance.now() - startedAtMs) * 100) / 100,
|
|
2099
|
+
cacheMode: mode
|
|
2100
|
+
};
|
|
2101
|
+
return resolvedRuntime;
|
|
1859
2102
|
}, [cache, runtimeContext.policy, handle]);
|
|
1860
2103
|
(0, import_react6.useEffect)(() => {
|
|
1861
2104
|
if (!isTagHandle) {
|
|
1862
2105
|
return;
|
|
1863
2106
|
}
|
|
1864
|
-
|
|
2107
|
+
const diagnosticsLevel = readRuntimeDiagnosticsLevel(runtime);
|
|
2108
|
+
if (diagnosticsLevel === "off") {
|
|
1865
2109
|
return;
|
|
1866
2110
|
}
|
|
1867
2111
|
const tokenId = handle?.id ?? "ModuleTag";
|
|
1868
|
-
const
|
|
2112
|
+
const trace = moduleTagResolveTraceRef.current;
|
|
2113
|
+
const effect = Logix7.Debug.record({
|
|
1869
2114
|
type: "trace:react.moduleTag.resolve",
|
|
1870
2115
|
moduleId: resolved.moduleId,
|
|
1871
2116
|
instanceId: resolved.instanceId,
|
|
1872
2117
|
data: {
|
|
1873
2118
|
mode: runtimeContext.policy.moduleTagMode,
|
|
1874
2119
|
tokenId,
|
|
1875
|
-
yieldStrategy: runtimeContext.policy.yield.strategy
|
|
2120
|
+
yieldStrategy: runtimeContext.policy.yield.strategy,
|
|
2121
|
+
durationMs: trace?.durationMs,
|
|
2122
|
+
cacheMode: trace?.cacheMode ?? runtimeContext.policy.moduleTagMode
|
|
1876
2123
|
}
|
|
1877
2124
|
});
|
|
1878
|
-
runtime
|
|
2125
|
+
emitRuntimeDebugEventBestEffort(runtime, effect);
|
|
1879
2126
|
}, [runtime, runtimeContext.policy, resolved, handle, isTagHandle]);
|
|
1880
2127
|
return resolved;
|
|
1881
2128
|
}
|
|
@@ -1883,55 +2130,73 @@ function useModuleRuntime(handle) {
|
|
|
1883
2130
|
// src/internal/hooks/useSelector.ts
|
|
1884
2131
|
var import_react7 = require("react");
|
|
1885
2132
|
var import_with_selector = require("use-sync-external-store/shim/with-selector");
|
|
1886
|
-
var
|
|
2133
|
+
var Logix9 = __toESM(require("@logixjs/core"), 1);
|
|
1887
2134
|
|
|
1888
|
-
// src/internal/store/
|
|
1889
|
-
var
|
|
2135
|
+
// src/internal/store/RuntimeExternalStore.ts
|
|
2136
|
+
var Logix8 = __toESM(require("@logixjs/core"), 1);
|
|
2137
|
+
var import_effect9 = require("effect");
|
|
1890
2138
|
var storesByRuntime = /* @__PURE__ */ new WeakMap();
|
|
1891
2139
|
var getStoreMapForRuntime = (runtime) => {
|
|
1892
2140
|
const cached = storesByRuntime.get(runtime);
|
|
1893
2141
|
if (cached) return cached;
|
|
1894
|
-
const next = /* @__PURE__ */ new
|
|
2142
|
+
const next = /* @__PURE__ */ new Map();
|
|
1895
2143
|
storesByRuntime.set(runtime, next);
|
|
1896
2144
|
return next;
|
|
1897
2145
|
};
|
|
1898
|
-
var
|
|
1899
|
-
|
|
1900
|
-
|
|
2146
|
+
var makeModuleInstanceKey = (moduleId, instanceId) => `${moduleId}::${instanceId}`;
|
|
2147
|
+
var makeReadQueryTopicKey = (moduleInstanceKey, selectorId) => `${moduleInstanceKey}::rq:${selectorId}`;
|
|
2148
|
+
var getRuntimeStore = (runtime) => Logix8.InternalContracts.getRuntimeStore(runtime);
|
|
2149
|
+
var getHostScheduler = (runtime) => Logix8.InternalContracts.getHostScheduler(runtime);
|
|
2150
|
+
var getOrCreateStore = (runtime, topicKey, make) => {
|
|
2151
|
+
const map = getStoreMapForRuntime(runtime);
|
|
2152
|
+
const cached = map.get(topicKey);
|
|
1901
2153
|
if (cached) {
|
|
1902
2154
|
return cached;
|
|
1903
2155
|
}
|
|
1904
|
-
|
|
2156
|
+
const created = make();
|
|
2157
|
+
map.set(topicKey, created);
|
|
2158
|
+
return created;
|
|
2159
|
+
};
|
|
2160
|
+
var removeStore = (runtime, topicKey) => {
|
|
2161
|
+
const map = storesByRuntime.get(runtime);
|
|
2162
|
+
if (!map) return;
|
|
2163
|
+
map.delete(topicKey);
|
|
2164
|
+
};
|
|
2165
|
+
var makeTopicExternalStore = (args) => {
|
|
2166
|
+
const { runtime, runtimeStore, topicKey } = args;
|
|
2167
|
+
const hostScheduler = getHostScheduler(runtime);
|
|
2168
|
+
let currentVersion;
|
|
2169
|
+
let hasSnapshot = false;
|
|
2170
|
+
let currentSnapshot;
|
|
1905
2171
|
const listeners = /* @__PURE__ */ new Set();
|
|
1906
|
-
|
|
1907
|
-
|
|
2172
|
+
let unsubscribeFromRuntimeStore;
|
|
2173
|
+
let teardownScheduled = false;
|
|
2174
|
+
let teardownToken = 0;
|
|
2175
|
+
const lowPriorityDelayMs = args.options?.lowPriorityDelayMs ?? 16;
|
|
2176
|
+
const lowPriorityMaxDelayMs = args.options?.lowPriorityMaxDelayMs ?? 50;
|
|
1908
2177
|
let notifyScheduled = false;
|
|
1909
2178
|
let notifyScheduledLow = false;
|
|
1910
|
-
let
|
|
1911
|
-
let
|
|
1912
|
-
let
|
|
2179
|
+
let lowCancelDelay;
|
|
2180
|
+
let lowCancelMaxDelay;
|
|
2181
|
+
let lowCancelRaf;
|
|
1913
2182
|
const cancelLow = () => {
|
|
1914
2183
|
if (!notifyScheduledLow) return;
|
|
1915
2184
|
notifyScheduledLow = false;
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
lowMaxTimeoutId = void 0;
|
|
1923
|
-
}
|
|
1924
|
-
const cancel = globalThis.cancelAnimationFrame;
|
|
1925
|
-
if (cancel && typeof lowRafId === "number") {
|
|
1926
|
-
cancel(lowRafId);
|
|
1927
|
-
lowRafId = void 0;
|
|
1928
|
-
}
|
|
2185
|
+
lowCancelDelay?.();
|
|
2186
|
+
lowCancelDelay = void 0;
|
|
2187
|
+
lowCancelMaxDelay?.();
|
|
2188
|
+
lowCancelMaxDelay = void 0;
|
|
2189
|
+
lowCancelRaf?.();
|
|
2190
|
+
lowCancelRaf = void 0;
|
|
1929
2191
|
};
|
|
1930
2192
|
const flushNotify = () => {
|
|
1931
2193
|
notifyScheduled = false;
|
|
1932
2194
|
cancelLow();
|
|
1933
2195
|
for (const listener of listeners) {
|
|
1934
|
-
|
|
2196
|
+
try {
|
|
2197
|
+
listener();
|
|
2198
|
+
} catch {
|
|
2199
|
+
}
|
|
1935
2200
|
}
|
|
1936
2201
|
};
|
|
1937
2202
|
const scheduleNotify = (priority) => {
|
|
@@ -1943,72 +2208,155 @@ var getModuleRuntimeExternalStore = (runtime, moduleRuntime, options) => {
|
|
|
1943
2208
|
if (!notifyScheduledLow) return;
|
|
1944
2209
|
flushNotify();
|
|
1945
2210
|
};
|
|
1946
|
-
const
|
|
1947
|
-
|
|
1948
|
-
|
|
2211
|
+
const scheduleRaf = () => {
|
|
2212
|
+
if (!notifyScheduledLow) return;
|
|
2213
|
+
lowCancelRaf = hostScheduler.scheduleAnimationFrame(flush);
|
|
2214
|
+
};
|
|
2215
|
+
if (lowPriorityDelayMs <= 0) {
|
|
2216
|
+
scheduleRaf();
|
|
1949
2217
|
} else {
|
|
1950
|
-
|
|
2218
|
+
lowCancelDelay = hostScheduler.scheduleTimeout(lowPriorityDelayMs, scheduleRaf);
|
|
1951
2219
|
}
|
|
1952
|
-
|
|
2220
|
+
lowCancelMaxDelay = hostScheduler.scheduleTimeout(lowPriorityMaxDelayMs, flush);
|
|
1953
2221
|
return;
|
|
1954
2222
|
}
|
|
1955
2223
|
cancelLow();
|
|
1956
2224
|
if (notifyScheduled) return;
|
|
1957
2225
|
notifyScheduled = true;
|
|
1958
|
-
|
|
2226
|
+
hostScheduler.scheduleMicrotask(flushNotify);
|
|
2227
|
+
};
|
|
2228
|
+
const onRuntimeStoreChange = () => {
|
|
2229
|
+
try {
|
|
2230
|
+
scheduleNotify(runtimeStore.getTopicPriority(topicKey));
|
|
2231
|
+
} catch {
|
|
2232
|
+
}
|
|
1959
2233
|
};
|
|
1960
|
-
let fiber;
|
|
1961
2234
|
const ensureSubscription = () => {
|
|
1962
|
-
if (
|
|
1963
|
-
|
|
1964
|
-
import_effect8.Stream.runForEach(
|
|
1965
|
-
moduleRuntime.changesWithMeta((state) => state),
|
|
1966
|
-
({ value: state, meta }) => import_effect8.Effect.sync(() => {
|
|
1967
|
-
currentState = state;
|
|
1968
|
-
scheduleNotify(meta.priority);
|
|
1969
|
-
})
|
|
1970
|
-
)
|
|
1971
|
-
);
|
|
2235
|
+
if (unsubscribeFromRuntimeStore) return;
|
|
2236
|
+
unsubscribeFromRuntimeStore = runtimeStore.subscribeTopic(topicKey, onRuntimeStoreChange);
|
|
1972
2237
|
};
|
|
1973
2238
|
const refreshSnapshotIfStale = () => {
|
|
1974
|
-
if (
|
|
1975
|
-
return;
|
|
1976
|
-
}
|
|
2239
|
+
if (!hasSnapshot) return;
|
|
1977
2240
|
try {
|
|
1978
|
-
const
|
|
1979
|
-
if (
|
|
1980
|
-
|
|
1981
|
-
scheduleNotify("normal");
|
|
2241
|
+
const version = runtimeStore.getTopicVersion(topicKey);
|
|
2242
|
+
if (currentVersion !== version) {
|
|
2243
|
+
scheduleNotify(runtimeStore.getTopicPriority(topicKey));
|
|
1982
2244
|
}
|
|
1983
2245
|
} catch {
|
|
1984
2246
|
}
|
|
1985
2247
|
};
|
|
1986
2248
|
const getSnapshot = () => {
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
2249
|
+
const version = runtimeStore.getTopicVersion(topicKey);
|
|
2250
|
+
if (hasSnapshot && currentVersion === version) {
|
|
2251
|
+
return currentSnapshot;
|
|
2252
|
+
}
|
|
2253
|
+
const next = args.readSnapshot();
|
|
2254
|
+
currentVersion = version;
|
|
2255
|
+
hasSnapshot = true;
|
|
2256
|
+
currentSnapshot = next;
|
|
2257
|
+
return next;
|
|
2258
|
+
};
|
|
2259
|
+
const cancelScheduledTeardown = () => {
|
|
2260
|
+
if (!teardownScheduled) return;
|
|
2261
|
+
teardownScheduled = false;
|
|
2262
|
+
teardownToken += 1;
|
|
2263
|
+
};
|
|
2264
|
+
const finalizeTeardown = () => {
|
|
2265
|
+
if (listeners.size > 0) return;
|
|
2266
|
+
try {
|
|
2267
|
+
args.onLastListener?.();
|
|
2268
|
+
} catch {
|
|
2269
|
+
}
|
|
2270
|
+
const unsub = unsubscribeFromRuntimeStore;
|
|
2271
|
+
unsubscribeFromRuntimeStore = void 0;
|
|
2272
|
+
cancelLow();
|
|
2273
|
+
try {
|
|
2274
|
+
unsub?.();
|
|
2275
|
+
} catch {
|
|
2276
|
+
}
|
|
2277
|
+
removeStore(runtime, topicKey);
|
|
2278
|
+
};
|
|
2279
|
+
const scheduleTeardown = () => {
|
|
2280
|
+
if (teardownScheduled) return;
|
|
2281
|
+
teardownScheduled = true;
|
|
2282
|
+
const token = ++teardownToken;
|
|
2283
|
+
hostScheduler.scheduleMicrotask(() => {
|
|
2284
|
+
if (!teardownScheduled || token !== teardownToken) return;
|
|
2285
|
+
teardownScheduled = false;
|
|
2286
|
+
finalizeTeardown();
|
|
2287
|
+
});
|
|
1990
2288
|
};
|
|
1991
2289
|
const subscribe = (listener) => {
|
|
2290
|
+
cancelScheduledTeardown();
|
|
2291
|
+
const isFirst = listeners.size === 0;
|
|
1992
2292
|
listeners.add(listener);
|
|
1993
2293
|
ensureSubscription();
|
|
1994
2294
|
refreshSnapshotIfStale();
|
|
2295
|
+
if (isFirst) {
|
|
2296
|
+
try {
|
|
2297
|
+
args.onFirstListener?.();
|
|
2298
|
+
} catch {
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
1995
2301
|
return () => {
|
|
1996
2302
|
listeners.delete(listener);
|
|
1997
2303
|
if (listeners.size > 0) return;
|
|
1998
|
-
|
|
1999
|
-
if (!running) return;
|
|
2000
|
-
fiber = void 0;
|
|
2001
|
-
cancelLow();
|
|
2002
|
-
runtime.runFork(import_effect8.Fiber.interrupt(running));
|
|
2304
|
+
scheduleTeardown();
|
|
2003
2305
|
};
|
|
2004
2306
|
};
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2307
|
+
return { getSnapshot, getServerSnapshot: getSnapshot, subscribe };
|
|
2308
|
+
};
|
|
2309
|
+
var getRuntimeModuleExternalStore = (runtime, moduleRuntime, options) => {
|
|
2310
|
+
const moduleInstanceKey = makeModuleInstanceKey(moduleRuntime.moduleId, moduleRuntime.instanceId);
|
|
2311
|
+
const runtimeStore = getRuntimeStore(runtime);
|
|
2312
|
+
return getOrCreateStore(
|
|
2313
|
+
runtime,
|
|
2314
|
+
moduleInstanceKey,
|
|
2315
|
+
() => makeTopicExternalStore({
|
|
2316
|
+
runtime,
|
|
2317
|
+
runtimeStore,
|
|
2318
|
+
topicKey: moduleInstanceKey,
|
|
2319
|
+
readSnapshot: () => {
|
|
2320
|
+
const state = runtimeStore.getModuleState(moduleInstanceKey);
|
|
2321
|
+
if (state !== void 0) return state;
|
|
2322
|
+
return runtime.runSync(moduleRuntime.getState);
|
|
2323
|
+
},
|
|
2324
|
+
options
|
|
2325
|
+
})
|
|
2326
|
+
);
|
|
2327
|
+
};
|
|
2328
|
+
var getRuntimeReadQueryExternalStore = (runtime, moduleRuntime, selectorReadQuery, options) => {
|
|
2329
|
+
const moduleInstanceKey = makeModuleInstanceKey(moduleRuntime.moduleId, moduleRuntime.instanceId);
|
|
2330
|
+
const topicKey = makeReadQueryTopicKey(moduleInstanceKey, selectorReadQuery.selectorId);
|
|
2331
|
+
const runtimeStore = getRuntimeStore(runtime);
|
|
2332
|
+
let readQueryDrainFiber;
|
|
2333
|
+
return getOrCreateStore(
|
|
2334
|
+
runtime,
|
|
2335
|
+
topicKey,
|
|
2336
|
+
() => makeTopicExternalStore({
|
|
2337
|
+
runtime,
|
|
2338
|
+
runtimeStore,
|
|
2339
|
+
topicKey,
|
|
2340
|
+
readSnapshot: () => {
|
|
2341
|
+
const state = runtimeStore.getModuleState(moduleInstanceKey);
|
|
2342
|
+
const current = state ?? runtime.runSync(moduleRuntime.getState);
|
|
2343
|
+
return selectorReadQuery.select(current);
|
|
2344
|
+
},
|
|
2345
|
+
options,
|
|
2346
|
+
onFirstListener: () => {
|
|
2347
|
+
if (readQueryDrainFiber) return;
|
|
2348
|
+
const effect = import_effect9.Stream.runDrain(moduleRuntime.changesReadQueryWithMeta(selectorReadQuery));
|
|
2349
|
+
readQueryDrainFiber = runtime.runFork(effect);
|
|
2350
|
+
},
|
|
2351
|
+
onLastListener: () => {
|
|
2352
|
+
const fiber = readQueryDrainFiber;
|
|
2353
|
+
if (!fiber) return;
|
|
2354
|
+
readQueryDrainFiber = void 0;
|
|
2355
|
+
runtime.runFork(import_effect9.Fiber.interrupt(fiber));
|
|
2356
|
+
}
|
|
2357
|
+
})
|
|
2358
|
+
);
|
|
2008
2359
|
};
|
|
2009
|
-
|
|
2010
|
-
// src/internal/store/ModuleRuntimeSelectorExternalStore.ts
|
|
2011
|
-
var import_effect9 = require("effect");
|
|
2012
2360
|
|
|
2013
2361
|
// src/internal/hooks/shallow.ts
|
|
2014
2362
|
var hasObjectShape = (value) => typeof value === "object" && value !== null;
|
|
@@ -2060,146 +2408,6 @@ var shallow = (previous, next) => {
|
|
|
2060
2408
|
return true;
|
|
2061
2409
|
};
|
|
2062
2410
|
|
|
2063
|
-
// src/internal/store/ModuleRuntimeSelectorExternalStore.ts
|
|
2064
|
-
var storesByRuntime2 = /* @__PURE__ */ new WeakMap();
|
|
2065
|
-
var getStoreMapForRuntime2 = (runtime) => {
|
|
2066
|
-
const cached = storesByRuntime2.get(runtime);
|
|
2067
|
-
if (cached) return cached;
|
|
2068
|
-
const next = /* @__PURE__ */ new WeakMap();
|
|
2069
|
-
storesByRuntime2.set(runtime, next);
|
|
2070
|
-
return next;
|
|
2071
|
-
};
|
|
2072
|
-
var getOrCreateSelectorMapForModule = (byModule, moduleRuntime) => {
|
|
2073
|
-
const cached = byModule.get(moduleRuntime);
|
|
2074
|
-
if (cached) return cached;
|
|
2075
|
-
const next = /* @__PURE__ */ new Map();
|
|
2076
|
-
byModule.set(moduleRuntime, next);
|
|
2077
|
-
return next;
|
|
2078
|
-
};
|
|
2079
|
-
var equalsValue = (readQuery, a, b) => {
|
|
2080
|
-
if (readQuery.equalsKind === "custom" && typeof readQuery.equals === "function") {
|
|
2081
|
-
return readQuery.equals(a, b);
|
|
2082
|
-
}
|
|
2083
|
-
if (readQuery.equalsKind === "shallowStruct") {
|
|
2084
|
-
return shallow(a, b);
|
|
2085
|
-
}
|
|
2086
|
-
return Object.is(a, b);
|
|
2087
|
-
};
|
|
2088
|
-
var getModuleRuntimeSelectorExternalStore = (runtime, moduleRuntime, selectorReadQuery, options) => {
|
|
2089
|
-
const byModule = getStoreMapForRuntime2(runtime);
|
|
2090
|
-
const bySelector = getOrCreateSelectorMapForModule(byModule, moduleRuntime);
|
|
2091
|
-
const cached = bySelector.get(selectorReadQuery.selectorId);
|
|
2092
|
-
if (cached) {
|
|
2093
|
-
return cached;
|
|
2094
|
-
}
|
|
2095
|
-
let currentValue;
|
|
2096
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
2097
|
-
const lowPriorityDelayMs = options?.lowPriorityDelayMs ?? 16;
|
|
2098
|
-
const lowPriorityMaxDelayMs = options?.lowPriorityMaxDelayMs ?? 50;
|
|
2099
|
-
let notifyScheduled = false;
|
|
2100
|
-
let notifyScheduledLow = false;
|
|
2101
|
-
let lowTimeoutId;
|
|
2102
|
-
let lowMaxTimeoutId;
|
|
2103
|
-
let lowRafId;
|
|
2104
|
-
const cancelLow = () => {
|
|
2105
|
-
if (!notifyScheduledLow) return;
|
|
2106
|
-
notifyScheduledLow = false;
|
|
2107
|
-
if (lowTimeoutId != null) {
|
|
2108
|
-
clearTimeout(lowTimeoutId);
|
|
2109
|
-
lowTimeoutId = void 0;
|
|
2110
|
-
}
|
|
2111
|
-
if (lowMaxTimeoutId != null) {
|
|
2112
|
-
clearTimeout(lowMaxTimeoutId);
|
|
2113
|
-
lowMaxTimeoutId = void 0;
|
|
2114
|
-
}
|
|
2115
|
-
const cancel = globalThis.cancelAnimationFrame;
|
|
2116
|
-
if (cancel && typeof lowRafId === "number") {
|
|
2117
|
-
cancel(lowRafId);
|
|
2118
|
-
lowRafId = void 0;
|
|
2119
|
-
}
|
|
2120
|
-
};
|
|
2121
|
-
const flushNotify = () => {
|
|
2122
|
-
notifyScheduled = false;
|
|
2123
|
-
cancelLow();
|
|
2124
|
-
for (const listener of listeners) {
|
|
2125
|
-
listener();
|
|
2126
|
-
}
|
|
2127
|
-
};
|
|
2128
|
-
const scheduleNotify = (priority) => {
|
|
2129
|
-
if (priority === "low") {
|
|
2130
|
-
if (notifyScheduled) return;
|
|
2131
|
-
if (notifyScheduledLow) return;
|
|
2132
|
-
notifyScheduledLow = true;
|
|
2133
|
-
const flush = () => {
|
|
2134
|
-
if (!notifyScheduledLow) return;
|
|
2135
|
-
flushNotify();
|
|
2136
|
-
};
|
|
2137
|
-
const raf = globalThis.requestAnimationFrame;
|
|
2138
|
-
if (raf) {
|
|
2139
|
-
lowRafId = raf(flush);
|
|
2140
|
-
} else {
|
|
2141
|
-
lowTimeoutId = setTimeout(flush, lowPriorityDelayMs);
|
|
2142
|
-
}
|
|
2143
|
-
lowMaxTimeoutId = setTimeout(flush, lowPriorityMaxDelayMs);
|
|
2144
|
-
return;
|
|
2145
|
-
}
|
|
2146
|
-
cancelLow();
|
|
2147
|
-
if (notifyScheduled) return;
|
|
2148
|
-
notifyScheduled = true;
|
|
2149
|
-
queueMicrotask(flushNotify);
|
|
2150
|
-
};
|
|
2151
|
-
let fiber;
|
|
2152
|
-
const ensureSubscription = () => {
|
|
2153
|
-
if (fiber) return;
|
|
2154
|
-
fiber = runtime.runFork(
|
|
2155
|
-
import_effect9.Stream.runForEach(
|
|
2156
|
-
moduleRuntime.changesReadQueryWithMeta(selectorReadQuery),
|
|
2157
|
-
({ value, meta }) => import_effect9.Effect.sync(() => {
|
|
2158
|
-
currentValue = value;
|
|
2159
|
-
scheduleNotify(meta.priority);
|
|
2160
|
-
})
|
|
2161
|
-
)
|
|
2162
|
-
);
|
|
2163
|
-
};
|
|
2164
|
-
const refreshSnapshotIfStale = () => {
|
|
2165
|
-
if (currentValue === void 0) {
|
|
2166
|
-
return;
|
|
2167
|
-
}
|
|
2168
|
-
try {
|
|
2169
|
-
const state = runtime.runSync(moduleRuntime.getState);
|
|
2170
|
-
const next = selectorReadQuery.select(state);
|
|
2171
|
-
if (currentValue === void 0 || !equalsValue(selectorReadQuery, currentValue, next)) {
|
|
2172
|
-
currentValue = next;
|
|
2173
|
-
scheduleNotify("normal");
|
|
2174
|
-
}
|
|
2175
|
-
} catch {
|
|
2176
|
-
}
|
|
2177
|
-
};
|
|
2178
|
-
const getSnapshot = () => {
|
|
2179
|
-
if (currentValue !== void 0) return currentValue;
|
|
2180
|
-
const state = runtime.runSync(moduleRuntime.getState);
|
|
2181
|
-
currentValue = selectorReadQuery.select(state);
|
|
2182
|
-
return currentValue;
|
|
2183
|
-
};
|
|
2184
|
-
const subscribe = (listener) => {
|
|
2185
|
-
listeners.add(listener);
|
|
2186
|
-
ensureSubscription();
|
|
2187
|
-
refreshSnapshotIfStale();
|
|
2188
|
-
return () => {
|
|
2189
|
-
listeners.delete(listener);
|
|
2190
|
-
if (listeners.size > 0) return;
|
|
2191
|
-
const running = fiber;
|
|
2192
|
-
if (!running) return;
|
|
2193
|
-
fiber = void 0;
|
|
2194
|
-
cancelLow();
|
|
2195
|
-
runtime.runFork(import_effect9.Fiber.interrupt(running));
|
|
2196
|
-
};
|
|
2197
|
-
};
|
|
2198
|
-
const store = { getSnapshot, subscribe };
|
|
2199
|
-
bySelector.set(selectorReadQuery.selectorId, store);
|
|
2200
|
-
return store;
|
|
2201
|
-
};
|
|
2202
|
-
|
|
2203
2411
|
// src/internal/hooks/useSelector.ts
|
|
2204
2412
|
function useSelector(handle, selector, equalityFn) {
|
|
2205
2413
|
const runtimeContext = (0, import_react7.useContext)(RuntimeContext);
|
|
@@ -2210,7 +2418,7 @@ function useSelector(handle, selector, equalityFn) {
|
|
|
2210
2418
|
const moduleRuntime = useModuleRuntime(handle);
|
|
2211
2419
|
const actualSelector = selector ?? ((state) => state);
|
|
2212
2420
|
const selectorReadQuery = (0, import_react7.useMemo)(
|
|
2213
|
-
() => typeof selector === "function" ?
|
|
2421
|
+
() => typeof selector === "function" ? Logix9.ReadQuery.compile(selector) : void 0,
|
|
2214
2422
|
[selector]
|
|
2215
2423
|
);
|
|
2216
2424
|
const actualEqualityFn = (0, import_react7.useMemo)(() => {
|
|
@@ -2218,17 +2426,12 @@ function useSelector(handle, selector, equalityFn) {
|
|
|
2218
2426
|
if (typeof selector !== "function") return Object.is;
|
|
2219
2427
|
return selectorReadQuery?.equalsKind === "shallowStruct" ? shallow : Object.is;
|
|
2220
2428
|
}, [equalityFn, selector, selectorReadQuery?.equalsKind]);
|
|
2221
|
-
const
|
|
2429
|
+
const selectorTopicEligible = typeof selector === "function" && selectorReadQuery?.lane === "static" && selectorReadQuery.readsDigest != null && selectorReadQuery.fallbackReason == null;
|
|
2222
2430
|
const store = (0, import_react7.useMemo)(
|
|
2223
|
-
() =>
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
{
|
|
2228
|
-
lowPriorityDelayMs: runtimeContext.reactConfigSnapshot.lowPriorityDelayMs,
|
|
2229
|
-
lowPriorityMaxDelayMs: runtimeContext.reactConfigSnapshot.lowPriorityMaxDelayMs
|
|
2230
|
-
}
|
|
2231
|
-
) : getModuleRuntimeExternalStore(
|
|
2431
|
+
() => selectorTopicEligible && selectorReadQuery ? getRuntimeReadQueryExternalStore(runtime, moduleRuntime, selectorReadQuery, {
|
|
2432
|
+
lowPriorityDelayMs: runtimeContext.reactConfigSnapshot.lowPriorityDelayMs,
|
|
2433
|
+
lowPriorityMaxDelayMs: runtimeContext.reactConfigSnapshot.lowPriorityMaxDelayMs
|
|
2434
|
+
}) : getRuntimeModuleExternalStore(
|
|
2232
2435
|
runtime,
|
|
2233
2436
|
moduleRuntime,
|
|
2234
2437
|
{
|
|
@@ -2242,18 +2445,18 @@ function useSelector(handle, selector, equalityFn) {
|
|
|
2242
2445
|
runtimeContext.reactConfigSnapshot.lowPriorityDelayMs,
|
|
2243
2446
|
runtimeContext.reactConfigSnapshot.lowPriorityMaxDelayMs,
|
|
2244
2447
|
selectorReadQuery,
|
|
2245
|
-
|
|
2448
|
+
selectorTopicEligible
|
|
2246
2449
|
]
|
|
2247
2450
|
);
|
|
2248
2451
|
const selected = (0, import_with_selector.useSyncExternalStoreWithSelector)(
|
|
2249
2452
|
store.subscribe,
|
|
2250
2453
|
store.getSnapshot,
|
|
2251
|
-
store.getSnapshot,
|
|
2252
|
-
|
|
2454
|
+
store.getServerSnapshot ?? store.getSnapshot,
|
|
2455
|
+
selectorTopicEligible ? (snapshot) => snapshot : (snapshot) => actualSelector(snapshot),
|
|
2253
2456
|
actualEqualityFn
|
|
2254
2457
|
);
|
|
2255
2458
|
(0, import_react7.useEffect)(() => {
|
|
2256
|
-
if (!(0, import_Env.isDevEnv)() && !
|
|
2459
|
+
if (!(0, import_Env.isDevEnv)() && !Logix9.Debug.isDevtoolsEnabled()) {
|
|
2257
2460
|
return;
|
|
2258
2461
|
}
|
|
2259
2462
|
const instanceId = moduleRuntime.instanceId;
|
|
@@ -2269,7 +2472,7 @@ function useSelector(handle, selector, equalityFn) {
|
|
|
2269
2472
|
const rawDebugKey = meta.debugKey;
|
|
2270
2473
|
selectorKey = typeof rawDebugKey === "string" && rawDebugKey.length > 0 ? rawDebugKey : typeof selector.name === "string" && selector.name.length > 0 ? selector.name : void 0;
|
|
2271
2474
|
}
|
|
2272
|
-
const effect =
|
|
2475
|
+
const effect = Logix9.Debug.record({
|
|
2273
2476
|
type: "trace:react-selector",
|
|
2274
2477
|
moduleId: moduleRuntime.moduleId,
|
|
2275
2478
|
instanceId,
|
|
@@ -2292,7 +2495,7 @@ function useSelector(handle, selector, equalityFn) {
|
|
|
2292
2495
|
}
|
|
2293
2496
|
|
|
2294
2497
|
// src/internal/store/resolveImportedModuleRef.ts
|
|
2295
|
-
var
|
|
2498
|
+
var Logix10 = __toESM(require("@logixjs/core"), 1);
|
|
2296
2499
|
var getOrCreateWeakMap = (map, key, make) => {
|
|
2297
2500
|
const cached = map.get(key);
|
|
2298
2501
|
if (cached) return cached;
|
|
@@ -2316,7 +2519,7 @@ var resolveImportedModuleRef = (runtime, parentRuntime, module2) => {
|
|
|
2316
2519
|
if (cached) {
|
|
2317
2520
|
return cached;
|
|
2318
2521
|
}
|
|
2319
|
-
const importsScope =
|
|
2522
|
+
const importsScope = Logix10.InternalContracts.getImportsScope(parentRuntime);
|
|
2320
2523
|
const childRuntime = importsScope.get(module2);
|
|
2321
2524
|
if (childRuntime) {
|
|
2322
2525
|
const dispatch = Object.assign(
|
|
@@ -2402,8 +2605,8 @@ var useStableId = () => {
|
|
|
2402
2605
|
|
|
2403
2606
|
// src/internal/hooks/useModule.ts
|
|
2404
2607
|
var isModuleImpl2 = (handle) => Boolean(handle) && typeof handle === "object" && handle._tag === "ModuleImpl";
|
|
2405
|
-
var isModule = (handle) =>
|
|
2406
|
-
var isModuleDef = (handle) =>
|
|
2608
|
+
var isModule = (handle) => Logix11.Module.hasImpl(handle);
|
|
2609
|
+
var isModuleDef = (handle) => Logix11.Module.is(handle) && handle._kind === "ModuleDef";
|
|
2407
2610
|
function useModule(handle, selectorOrOptions, equalityFn) {
|
|
2408
2611
|
const runtimeBase = useRuntime();
|
|
2409
2612
|
const runtimeContext = import_react9.default.useContext(RuntimeContext);
|
|
@@ -2427,6 +2630,7 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
2427
2630
|
}
|
|
2428
2631
|
}
|
|
2429
2632
|
let runtime;
|
|
2633
|
+
const moduleImplResolveTraceRef = import_react9.default.useRef(void 0);
|
|
2430
2634
|
if (isModuleImpl2(normalizedHandle)) {
|
|
2431
2635
|
const cache = import_react9.default.useMemo(
|
|
2432
2636
|
() => getModuleCache(runtimeBase, runtimeContext.reactConfigSnapshot, runtimeContext.configVersion),
|
|
@@ -2455,9 +2659,9 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
2455
2659
|
const key = depsHash ? `${baseKey}:${depsHash}` : baseKey;
|
|
2456
2660
|
const ownerId = moduleId;
|
|
2457
2661
|
const baseFactory = import_react9.default.useMemo(
|
|
2458
|
-
() => (scope) => import_effect10.Layer.buildWithScope(normalizedHandle.layer, scope).pipe(
|
|
2662
|
+
() => (scope) => import_effect10.Layer.buildWithScope(import_effect10.Layer.fresh(normalizedHandle.layer), scope).pipe(
|
|
2459
2663
|
import_effect10.Effect.map(
|
|
2460
|
-
(context) => import_effect10.
|
|
2664
|
+
(context) => import_effect10.ServiceMap.get(context, normalizedHandle.module)
|
|
2461
2665
|
)
|
|
2462
2666
|
),
|
|
2463
2667
|
[normalizedHandle]
|
|
@@ -2467,26 +2671,56 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
2467
2671
|
return baseFactory;
|
|
2468
2672
|
}
|
|
2469
2673
|
return (scope) => baseFactory(scope).pipe(
|
|
2470
|
-
import_effect10.Effect.
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2674
|
+
import_effect10.Effect.timeoutOption(initTimeoutMs),
|
|
2675
|
+
import_effect10.Effect.flatMap(
|
|
2676
|
+
(maybe) => maybe._tag === "Some" ? import_effect10.Effect.succeed(maybe.value) : import_effect10.Effect.die(new Error(`[useModule] Module "${ownerId}" initialization timed out after ${initTimeoutMs}ms`))
|
|
2677
|
+
)
|
|
2474
2678
|
);
|
|
2475
2679
|
}, [baseFactory, suspend, initTimeoutMs, ownerId]);
|
|
2680
|
+
const moduleResolveStartedAt = performance.now();
|
|
2476
2681
|
const moduleRuntime = suspend ? cache.read(key, factory, gcTime, ownerId, {
|
|
2477
2682
|
entrypoint: "react.useModule",
|
|
2478
2683
|
policyMode: runtimeContext.policy.mode,
|
|
2479
|
-
yield: runtimeContext.policy.yield
|
|
2684
|
+
yield: runtimeContext.policy.yield,
|
|
2685
|
+
optimisticSyncBudgetMs: runtimeContext.policy.syncBudgetMs
|
|
2480
2686
|
}) : cache.readSync(key, factory, gcTime, ownerId, {
|
|
2481
2687
|
entrypoint: "react.useModule",
|
|
2482
2688
|
policyMode: runtimeContext.policy.mode,
|
|
2483
2689
|
warnSyncBlockingThresholdMs: 5
|
|
2484
2690
|
});
|
|
2691
|
+
moduleImplResolveTraceRef.current = {
|
|
2692
|
+
moduleId,
|
|
2693
|
+
cacheMode: suspend ? "suspend" : "sync",
|
|
2694
|
+
durationMs: Math.round((performance.now() - moduleResolveStartedAt) * 100) / 100
|
|
2695
|
+
};
|
|
2485
2696
|
import_react9.default.useEffect(() => cache.retain(key), [cache, key]);
|
|
2486
2697
|
runtime = moduleRuntime;
|
|
2487
2698
|
} else {
|
|
2488
2699
|
runtime = useModuleRuntime(normalizedHandle);
|
|
2489
2700
|
}
|
|
2701
|
+
import_react9.default.useEffect(() => {
|
|
2702
|
+
if (!isModuleImpl2(normalizedHandle)) {
|
|
2703
|
+
return;
|
|
2704
|
+
}
|
|
2705
|
+
const diagnosticsLevel = readRuntimeDiagnosticsLevel(runtimeBase);
|
|
2706
|
+
if (diagnosticsLevel === "off") {
|
|
2707
|
+
return;
|
|
2708
|
+
}
|
|
2709
|
+
const trace = moduleImplResolveTraceRef.current;
|
|
2710
|
+
if (!trace) {
|
|
2711
|
+
return;
|
|
2712
|
+
}
|
|
2713
|
+
const effect = Logix11.Debug.record({
|
|
2714
|
+
type: "trace:react.moduleImpl.resolve",
|
|
2715
|
+
moduleId: trace.moduleId,
|
|
2716
|
+
instanceId: runtime.instanceId,
|
|
2717
|
+
data: {
|
|
2718
|
+
cacheMode: trace.cacheMode,
|
|
2719
|
+
durationMs: trace.durationMs
|
|
2720
|
+
}
|
|
2721
|
+
});
|
|
2722
|
+
emitRuntimeDebugEventBestEffort(runtimeBase, effect);
|
|
2723
|
+
}, [runtimeBase, runtime, normalizedHandle]);
|
|
2490
2724
|
import_react9.default.useEffect(() => {
|
|
2491
2725
|
if (!isModuleImpl2(normalizedHandle)) {
|
|
2492
2726
|
return;
|
|
@@ -2496,22 +2730,22 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
2496
2730
|
if (!label) {
|
|
2497
2731
|
return;
|
|
2498
2732
|
}
|
|
2499
|
-
const effect =
|
|
2733
|
+
const effect = Logix11.Debug.record({
|
|
2500
2734
|
type: "trace:instanceLabel",
|
|
2501
2735
|
moduleId: normalizedHandle.module.id,
|
|
2502
2736
|
instanceId: runtime.instanceId,
|
|
2503
2737
|
data: { label }
|
|
2504
2738
|
});
|
|
2505
|
-
runtimeBase
|
|
2739
|
+
emitRuntimeDebugEventBestEffort(runtimeBase, effect);
|
|
2506
2740
|
}, [runtimeBase, runtime, normalizedHandle, options]);
|
|
2507
2741
|
import_react9.default.useEffect(() => {
|
|
2508
|
-
if (!(0, import_Env.isDevEnv)() && !
|
|
2742
|
+
if (!(0, import_Env.isDevEnv)() && !Logix11.Debug.isDevtoolsEnabled()) {
|
|
2509
2743
|
return;
|
|
2510
2744
|
}
|
|
2511
2745
|
if (!runtime.instanceId) {
|
|
2512
2746
|
return;
|
|
2513
2747
|
}
|
|
2514
|
-
const effect =
|
|
2748
|
+
const effect = Logix11.Debug.record({
|
|
2515
2749
|
type: "trace:react-render",
|
|
2516
2750
|
moduleId: runtime.moduleId,
|
|
2517
2751
|
instanceId: runtime.instanceId,
|
|
@@ -2521,7 +2755,7 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
2521
2755
|
}
|
|
2522
2756
|
});
|
|
2523
2757
|
runtimeBase.runFork(effect);
|
|
2524
|
-
}
|
|
2758
|
+
});
|
|
2525
2759
|
if (selector) {
|
|
2526
2760
|
if (isModuleImpl2(normalizedHandle)) {
|
|
2527
2761
|
return useSelector(runtime, selector, equalityFn);
|
|
@@ -2608,7 +2842,7 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
2608
2842
|
|
|
2609
2843
|
// src/internal/hooks/useLocalModule.ts
|
|
2610
2844
|
var import_react10 = __toESM(require("react"), 1);
|
|
2611
|
-
var
|
|
2845
|
+
var Logix12 = __toESM(require("@logixjs/core"), 1);
|
|
2612
2846
|
var import_effect11 = require("effect");
|
|
2613
2847
|
function isModuleTag2(source) {
|
|
2614
2848
|
if (!source || typeof source !== "object" && typeof source !== "function") {
|
|
@@ -2629,7 +2863,7 @@ function useLocalModule(source, second) {
|
|
|
2629
2863
|
);
|
|
2630
2864
|
const componentId = useStableId();
|
|
2631
2865
|
const moduleTag = import_react10.default.useMemo(() => {
|
|
2632
|
-
if (
|
|
2866
|
+
if (Logix12.Module.is(source)) {
|
|
2633
2867
|
return source.tag;
|
|
2634
2868
|
}
|
|
2635
2869
|
if (isModuleTag2(source)) {
|
|
@@ -2638,7 +2872,7 @@ function useLocalModule(source, second) {
|
|
|
2638
2872
|
return null;
|
|
2639
2873
|
}, [source]);
|
|
2640
2874
|
const def = import_react10.default.useMemo(() => {
|
|
2641
|
-
if (
|
|
2875
|
+
if (Logix12.Module.is(source) || isModuleTag2(source)) {
|
|
2642
2876
|
return source;
|
|
2643
2877
|
}
|
|
2644
2878
|
return void 0;
|
|
@@ -2666,7 +2900,7 @@ function useLocalModule(source, second) {
|
|
|
2666
2900
|
return createModuleTagFactory(moduleTag, moduleOptions);
|
|
2667
2901
|
}
|
|
2668
2902
|
const factoryFn = source;
|
|
2669
|
-
return (scope) =>
|
|
2903
|
+
return (scope) => import_effect11.Scope.provide(scope)(factoryFn());
|
|
2670
2904
|
}, [isModule2, moduleTag, source, moduleOptions]);
|
|
2671
2905
|
const moduleRuntime = cache.readSync(key, factory, void 0, ownerId, {
|
|
2672
2906
|
entrypoint: "react.useLocalModule",
|
|
@@ -2728,7 +2962,7 @@ function createModuleTagFactory(module2, options) {
|
|
|
2728
2962
|
const logics = options.logics ?? [];
|
|
2729
2963
|
return (scope) => import_effect11.Layer.buildWithScope(module2.live(options.initial, ...logics), scope).pipe(
|
|
2730
2964
|
import_effect11.Effect.map((context) => {
|
|
2731
|
-
const runtime = import_effect11.
|
|
2965
|
+
const runtime = import_effect11.ServiceMap.get(context, module2);
|
|
2732
2966
|
return runtime;
|
|
2733
2967
|
})
|
|
2734
2968
|
);
|
|
@@ -2767,7 +3001,7 @@ var import_react14 = __toESM(require("react"), 1);
|
|
|
2767
3001
|
// src/internal/hooks/useProcesses.ts
|
|
2768
3002
|
var import_react15 = __toESM(require("react"), 1);
|
|
2769
3003
|
var import_effect13 = require("effect");
|
|
2770
|
-
var
|
|
3004
|
+
var Logix13 = __toESM(require("@logixjs/core"), 1);
|
|
2771
3005
|
|
|
2772
3006
|
// src/ReactPlatform.ts
|
|
2773
3007
|
var import_react16 = __toESM(require("react"), 1);
|