@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.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { RuntimeProviderProps } from './RuntimeProvider.cjs';
|
|
2
2
|
import { ManagedRuntime } from 'effect';
|
|
3
|
-
import { u as useModule, a as useLocalModule, b as useSelector, c as useDispatch } from './useDispatch-
|
|
3
|
+
import { u as useModule, a as useLocalModule, b as useSelector, c as useDispatch } from './useDispatch-DiwQQAfC.cjs';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import '@logixjs/core';
|
|
6
|
-
import './ModuleRef-
|
|
6
|
+
import './ModuleRef-gZmL6Zvb.cjs';
|
|
7
7
|
|
|
8
8
|
declare const ReactPlatform: {
|
|
9
9
|
/**
|
package/dist/ReactPlatform.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { RuntimeProviderProps } from './RuntimeProvider.js';
|
|
2
2
|
import { ManagedRuntime } from 'effect';
|
|
3
|
-
import { u as useModule, a as useLocalModule, b as useSelector, c as useDispatch } from './useDispatch-
|
|
3
|
+
import { u as useModule, a as useLocalModule, b as useSelector, c as useDispatch } from './useDispatch-CiDimIYZ.js';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import '@logixjs/core';
|
|
6
|
-
import './ModuleRef-
|
|
6
|
+
import './ModuleRef-gZmL6Zvb.js';
|
|
7
7
|
|
|
8
8
|
declare const ReactPlatform: {
|
|
9
9
|
/**
|
package/dist/ReactPlatform.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ReactPlatform
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-KYWW4KMQ.js";
|
|
4
|
+
import "./chunk-6NLXTHZ7.js";
|
|
5
|
+
import "./chunk-E3ZXST5F.js";
|
|
6
6
|
import "./chunk-VFWWMK67.js";
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
7
|
+
import "./chunk-XSGDBJXD.js";
|
|
8
|
+
import "./chunk-L7KTYBXN.js";
|
|
9
9
|
export {
|
|
10
10
|
ReactPlatform
|
|
11
11
|
};
|
package/dist/RuntimeProvider.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) => {
|
|
@@ -1239,6 +1362,9 @@ var RuntimeProvider = ({
|
|
|
1239
1362
|
}) => {
|
|
1240
1363
|
const parent = (0, import_react4.useContext)(RuntimeContext);
|
|
1241
1364
|
const baseRuntime = useRuntimeResolution(runtime, parent);
|
|
1365
|
+
const providerStartedAtRef = import_react4.default.useRef(performance.now());
|
|
1366
|
+
const providerReadyAtRef = import_react4.default.useRef(void 0);
|
|
1367
|
+
const didReportProviderGatingRef = import_react4.default.useRef(false);
|
|
1242
1368
|
const resolvedPolicy = (0, import_react4.useMemo)(
|
|
1243
1369
|
() => resolveRuntimeProviderPolicy({
|
|
1244
1370
|
policy,
|
|
@@ -1248,6 +1374,20 @@ var RuntimeProvider = ({
|
|
|
1248
1374
|
);
|
|
1249
1375
|
const onErrorRef = import_react4.default.useRef(onError);
|
|
1250
1376
|
onErrorRef.current = onError;
|
|
1377
|
+
const hasTickServices = (0, import_react4.useMemo)(() => {
|
|
1378
|
+
try {
|
|
1379
|
+
Logix5.InternalContracts.getRuntimeStore(baseRuntime);
|
|
1380
|
+
return true;
|
|
1381
|
+
} catch {
|
|
1382
|
+
return false;
|
|
1383
|
+
}
|
|
1384
|
+
}, [baseRuntime]);
|
|
1385
|
+
const { binding: tickBinding } = useLayerBinding(
|
|
1386
|
+
baseRuntime,
|
|
1387
|
+
Logix5.InternalContracts.tickServicesLayer,
|
|
1388
|
+
!hasTickServices,
|
|
1389
|
+
onErrorRef.current
|
|
1390
|
+
);
|
|
1251
1391
|
const { binding: layerBinding } = useLayerBinding(baseRuntime, layer, Boolean(layer), onErrorRef.current);
|
|
1252
1392
|
const onErrorSink = (0, import_react4.useMemo)(() => {
|
|
1253
1393
|
if (!onError) return null;
|
|
@@ -1264,7 +1404,7 @@ var RuntimeProvider = ({
|
|
|
1264
1404
|
moduleId: event.moduleId,
|
|
1265
1405
|
instanceId: event.instanceId,
|
|
1266
1406
|
runtimeLabel: event.runtimeLabel
|
|
1267
|
-
}).pipe(import_effect5.Effect.
|
|
1407
|
+
}).pipe(import_effect5.Effect.catchCause(() => import_effect5.Effect.void));
|
|
1268
1408
|
}
|
|
1269
1409
|
if (event.type === "diagnostic" && event.severity === "error") {
|
|
1270
1410
|
return handler(
|
|
@@ -1283,7 +1423,7 @@ var RuntimeProvider = ({
|
|
|
1283
1423
|
instanceId: event.instanceId,
|
|
1284
1424
|
runtimeLabel: event.runtimeLabel
|
|
1285
1425
|
}
|
|
1286
|
-
).pipe(import_effect5.Effect.
|
|
1426
|
+
).pipe(import_effect5.Effect.catchCause(() => import_effect5.Effect.void));
|
|
1287
1427
|
}
|
|
1288
1428
|
return import_effect5.Effect.void;
|
|
1289
1429
|
}
|
|
@@ -1298,25 +1438,23 @@ var RuntimeProvider = ({
|
|
|
1298
1438
|
return layerBinding.debugSinks;
|
|
1299
1439
|
}
|
|
1300
1440
|
try {
|
|
1301
|
-
return baseRuntime.runSync(
|
|
1302
|
-
import_effect5.FiberRef.get(Logix5.Debug.internal.currentDebugSinks)
|
|
1303
|
-
);
|
|
1441
|
+
return baseRuntime.runSync(import_effect5.Effect.service(Logix5.Debug.internal.currentDebugSinks).pipe(import_effect5.Effect.orDie));
|
|
1304
1442
|
} catch {
|
|
1305
1443
|
return [];
|
|
1306
1444
|
}
|
|
1307
1445
|
}, [baseRuntime, layerBinding, onErrorSink]);
|
|
1308
1446
|
const runtimeWithBindings = (0, import_react4.useMemo)(
|
|
1309
|
-
() => layerBinding || onErrorSink ? createRuntimeAdapter(
|
|
1447
|
+
() => tickBinding || layerBinding || onErrorSink ? createRuntimeAdapter(
|
|
1310
1448
|
baseRuntime,
|
|
1311
|
-
layerBinding ? [layerBinding.context] : [],
|
|
1312
|
-
layerBinding ? [layerBinding.scope] : [],
|
|
1313
|
-
layerBinding ? [layerBinding.loggers] : [],
|
|
1314
|
-
layerBinding ? [layerBinding.logLevel] : [],
|
|
1449
|
+
[...tickBinding ? [tickBinding.context] : [], ...layerBinding ? [layerBinding.context] : []],
|
|
1450
|
+
[...tickBinding ? [tickBinding.scope] : [], ...layerBinding ? [layerBinding.scope] : []],
|
|
1451
|
+
layerBinding ? [layerBinding.loggers] : tickBinding ? [tickBinding.loggers] : [],
|
|
1452
|
+
layerBinding ? [layerBinding.logLevel] : tickBinding ? [tickBinding.logLevel] : [],
|
|
1315
1453
|
[
|
|
1316
1454
|
onErrorSink ? [onErrorSink, ...inheritedDebugSinks] : layerBinding ? layerBinding.debugSinks : []
|
|
1317
1455
|
]
|
|
1318
1456
|
) : baseRuntime,
|
|
1319
|
-
[baseRuntime, inheritedDebugSinks, layerBinding, onErrorSink]
|
|
1457
|
+
[baseRuntime, inheritedDebugSinks, layerBinding, onErrorSink, tickBinding]
|
|
1320
1458
|
);
|
|
1321
1459
|
const didReportSyncConfigSnapshotRef = import_react4.default.useRef(false);
|
|
1322
1460
|
const [configState, setConfigState] = (0, import_react4.useState)(() => {
|
|
@@ -1421,11 +1559,47 @@ var RuntimeProvider = ({
|
|
|
1421
1559
|
}),
|
|
1422
1560
|
[runtimeWithBindings, configState, resolvedPolicy]
|
|
1423
1561
|
);
|
|
1562
|
+
const isTickServicesReady = hasTickServices || tickBinding !== null;
|
|
1424
1563
|
const isLayerReady = !layer || layerBinding !== null;
|
|
1425
1564
|
const isConfigReady = configState.loaded;
|
|
1426
1565
|
const resolveFallback = (phase) => {
|
|
1427
1566
|
return resolveRuntimeProviderFallback({ fallback, phase, policyMode: resolvedPolicy.mode });
|
|
1428
1567
|
};
|
|
1568
|
+
const preloadCache = (0, import_react4.useMemo)(
|
|
1569
|
+
() => getModuleCache(runtimeWithBindings, configState.snapshot, configState.version),
|
|
1570
|
+
[runtimeWithBindings, configState.snapshot, configState.version]
|
|
1571
|
+
);
|
|
1572
|
+
const syncWarmPreloadReady = (0, import_react4.useMemo)(() => {
|
|
1573
|
+
if (resolvedPolicy.mode !== "defer") return false;
|
|
1574
|
+
if (!resolvedPolicy.preload) return true;
|
|
1575
|
+
if (!isLayerReady || !isConfigReady) return false;
|
|
1576
|
+
const handles = resolvedPolicy.preload.handles;
|
|
1577
|
+
if (handles.length === 0) return true;
|
|
1578
|
+
for (const handle of handles) {
|
|
1579
|
+
if (handle?._tag === "ModuleImpl") {
|
|
1580
|
+
const moduleId = handle.module?.id ?? "ModuleImpl";
|
|
1581
|
+
const key2 = resolvedPolicy.preload.keysByModuleId.get(moduleId) ?? getPreloadKeyForModuleId(moduleId);
|
|
1582
|
+
const factory2 = (scope) => import_effect5.Layer.buildWithScope(handle.layer, scope).pipe(
|
|
1583
|
+
import_effect5.Effect.map((context) => import_effect5.ServiceMap.get(context, handle.module))
|
|
1584
|
+
);
|
|
1585
|
+
const value2 = preloadCache.warmSync(key2, factory2, configState.snapshot.gcTime, moduleId, {
|
|
1586
|
+
entrypoint: "react.runtime.preload.sync-warm",
|
|
1587
|
+
policyMode: "defer"
|
|
1588
|
+
});
|
|
1589
|
+
if (!value2) return false;
|
|
1590
|
+
continue;
|
|
1591
|
+
}
|
|
1592
|
+
const tagId = handle.id ?? "ModuleTag";
|
|
1593
|
+
const key = resolvedPolicy.preload.keysByTagId.get(tagId) ?? getPreloadKeyForTagId(tagId);
|
|
1594
|
+
const factory = (scope) => import_effect5.Scope.provide(scope)(import_effect5.Effect.service(handle).pipe(import_effect5.Effect.orDie));
|
|
1595
|
+
const value = preloadCache.warmSync(key, factory, configState.snapshot.gcTime, tagId, {
|
|
1596
|
+
entrypoint: "react.runtime.preload.sync-warm",
|
|
1597
|
+
policyMode: "defer"
|
|
1598
|
+
});
|
|
1599
|
+
if (!value) return false;
|
|
1600
|
+
}
|
|
1601
|
+
return true;
|
|
1602
|
+
}, [resolvedPolicy, isLayerReady, isConfigReady, preloadCache, configState.snapshot.gcTime]);
|
|
1429
1603
|
const [deferReady, setDeferReady] = (0, import_react4.useState)(false);
|
|
1430
1604
|
(0, import_react4.useEffect)(() => {
|
|
1431
1605
|
if (resolvedPolicy.mode !== "defer") {
|
|
@@ -1439,6 +1613,10 @@ var RuntimeProvider = ({
|
|
|
1439
1613
|
if (resolvedPolicy.mode !== "defer") {
|
|
1440
1614
|
return;
|
|
1441
1615
|
}
|
|
1616
|
+
if (syncWarmPreloadReady) {
|
|
1617
|
+
setDeferReady(true);
|
|
1618
|
+
return;
|
|
1619
|
+
}
|
|
1442
1620
|
setDeferReady(false);
|
|
1443
1621
|
if (!resolvedPolicy.preload) {
|
|
1444
1622
|
setDeferReady(true);
|
|
@@ -1448,7 +1626,7 @@ var RuntimeProvider = ({
|
|
|
1448
1626
|
return;
|
|
1449
1627
|
}
|
|
1450
1628
|
let cancelled = false;
|
|
1451
|
-
const cache =
|
|
1629
|
+
const cache = preloadCache;
|
|
1452
1630
|
const preloadHandles = resolvedPolicy.preload.handles;
|
|
1453
1631
|
if (preloadHandles.length === 0) {
|
|
1454
1632
|
setDeferReady(true);
|
|
@@ -1466,13 +1644,14 @@ var RuntimeProvider = ({
|
|
|
1466
1644
|
const moduleId = handle.module?.id ?? "ModuleImpl";
|
|
1467
1645
|
const key2 = resolvedPolicy.preload.keysByModuleId.get(moduleId) ?? getPreloadKeyForModuleId(moduleId);
|
|
1468
1646
|
const factory2 = (scope) => import_effect5.Layer.buildWithScope(handle.layer, scope).pipe(
|
|
1469
|
-
import_effect5.Effect.map((context) => import_effect5.
|
|
1647
|
+
import_effect5.Effect.map((context) => import_effect5.ServiceMap.get(context, handle.module))
|
|
1470
1648
|
);
|
|
1471
1649
|
const op2 = cache.preload(key2, factory2, {
|
|
1472
1650
|
ownerId: moduleId,
|
|
1473
1651
|
yield: resolvedPolicy.preload.yield,
|
|
1474
1652
|
entrypoint: "react.runtime.preload",
|
|
1475
|
-
policyMode: "defer"
|
|
1653
|
+
policyMode: "defer",
|
|
1654
|
+
optimisticSyncBudgetMs: resolvedPolicy.syncBudgetMs
|
|
1476
1655
|
});
|
|
1477
1656
|
allCancels.add(op2.cancel);
|
|
1478
1657
|
await op2.promise;
|
|
@@ -1497,14 +1676,13 @@ var RuntimeProvider = ({
|
|
|
1497
1676
|
}
|
|
1498
1677
|
const tagId = handle.id ?? "ModuleTag";
|
|
1499
1678
|
const key = resolvedPolicy.preload.keysByTagId.get(tagId) ?? getPreloadKeyForTagId(tagId);
|
|
1500
|
-
const factory = (scope) => handle.pipe(
|
|
1501
|
-
import_effect5.Scope.extend(scope)
|
|
1502
|
-
);
|
|
1679
|
+
const factory = (scope) => import_effect5.Scope.provide(scope)(import_effect5.Effect.service(handle).pipe(import_effect5.Effect.orDie));
|
|
1503
1680
|
const op = cache.preload(key, factory, {
|
|
1504
1681
|
ownerId: tagId,
|
|
1505
1682
|
yield: resolvedPolicy.preload.yield,
|
|
1506
1683
|
entrypoint: "react.runtime.preload",
|
|
1507
|
-
policyMode: "defer"
|
|
1684
|
+
policyMode: "defer",
|
|
1685
|
+
optimisticSyncBudgetMs: resolvedPolicy.syncBudgetMs
|
|
1508
1686
|
});
|
|
1509
1687
|
allCancels.add(op.cancel);
|
|
1510
1688
|
await op.promise;
|
|
@@ -1542,7 +1720,7 @@ var RuntimeProvider = ({
|
|
|
1542
1720
|
if (cancelled) return;
|
|
1543
1721
|
if (onErrorRef.current) {
|
|
1544
1722
|
runtimeWithBindings.runFork(
|
|
1545
|
-
onErrorRef.current(import_effect5.Cause.die(error), { source: "provider", phase: "provider.layer.build" }).pipe(import_effect5.Effect.
|
|
1723
|
+
onErrorRef.current(import_effect5.Cause.die(error), { source: "provider", phase: "provider.layer.build" }).pipe(import_effect5.Effect.catchCause(() => import_effect5.Effect.void))
|
|
1546
1724
|
);
|
|
1547
1725
|
}
|
|
1548
1726
|
setDeferReady(true);
|
|
@@ -1575,12 +1753,54 @@ var RuntimeProvider = ({
|
|
|
1575
1753
|
release();
|
|
1576
1754
|
};
|
|
1577
1755
|
}, [resolvedPolicy.mode, deferReady]);
|
|
1578
|
-
const isReady = isLayerReady && isConfigReady && (resolvedPolicy.mode !== "defer" || deferReady);
|
|
1756
|
+
const isReady = isTickServicesReady && isLayerReady && isConfigReady && (resolvedPolicy.mode !== "defer" || deferReady || syncWarmPreloadReady);
|
|
1757
|
+
if (isReady && providerReadyAtRef.current === void 0) {
|
|
1758
|
+
providerReadyAtRef.current = performance.now();
|
|
1759
|
+
}
|
|
1760
|
+
(0, import_react4.useEffect)(() => {
|
|
1761
|
+
if (!isReady) {
|
|
1762
|
+
return;
|
|
1763
|
+
}
|
|
1764
|
+
if (didReportProviderGatingRef.current) {
|
|
1765
|
+
return;
|
|
1766
|
+
}
|
|
1767
|
+
let diagnosticsLevel = "off";
|
|
1768
|
+
try {
|
|
1769
|
+
diagnosticsLevel = runtimeWithBindings.runSync(
|
|
1770
|
+
import_effect5.Effect.service(Logix5.Debug.internal.currentDiagnosticsLevel).pipe(import_effect5.Effect.orDie)
|
|
1771
|
+
);
|
|
1772
|
+
} catch {
|
|
1773
|
+
diagnosticsLevel = (0, import_Env.isDevEnv)() ? "light" : "off";
|
|
1774
|
+
}
|
|
1775
|
+
if (diagnosticsLevel === "off") {
|
|
1776
|
+
return;
|
|
1777
|
+
}
|
|
1778
|
+
didReportProviderGatingRef.current = true;
|
|
1779
|
+
const readyAt = providerReadyAtRef.current ?? performance.now();
|
|
1780
|
+
const durationMs = Math.round((readyAt - providerStartedAtRef.current) * 100) / 100;
|
|
1781
|
+
const effectDelayMs = Math.round((performance.now() - readyAt) * 100) / 100;
|
|
1782
|
+
void runtimeWithBindings.runPromise(
|
|
1783
|
+
Logix5.Debug.record({
|
|
1784
|
+
type: "trace:react.provider.gating",
|
|
1785
|
+
data: {
|
|
1786
|
+
event: "ready",
|
|
1787
|
+
policyMode: resolvedPolicy.mode,
|
|
1788
|
+
durationMs,
|
|
1789
|
+
effectDelayMs,
|
|
1790
|
+
configLoadMode: configState.loadMode,
|
|
1791
|
+
syncOverBudget: Boolean(configState.syncOverBudget),
|
|
1792
|
+
syncDurationMs: configState.syncDurationMs !== void 0 ? Math.round(configState.syncDurationMs * 100) / 100 : void 0
|
|
1793
|
+
}
|
|
1794
|
+
})
|
|
1795
|
+
).catch(() => {
|
|
1796
|
+
});
|
|
1797
|
+
}, [configState.loadMode, configState.syncDurationMs, configState.syncOverBudget, isReady, resolvedPolicy.mode, runtimeWithBindings]);
|
|
1579
1798
|
if (!isReady) {
|
|
1580
1799
|
const blockersList = [
|
|
1800
|
+
isTickServicesReady ? null : "tick",
|
|
1581
1801
|
isLayerReady ? null : "layer",
|
|
1582
1802
|
isConfigReady ? null : "config",
|
|
1583
|
-
resolvedPolicy.mode !== "defer" || deferReady ? null : "preload"
|
|
1803
|
+
resolvedPolicy.mode !== "defer" || deferReady || syncWarmPreloadReady ? null : "preload"
|
|
1584
1804
|
].filter((x) => x !== null);
|
|
1585
1805
|
const blockers = blockersList.length > 0 ? blockersList.join("+") : void 0;
|
|
1586
1806
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
package/dist/RuntimeProvider.js
CHANGED
|
@@ -6,18 +6,18 @@ import {
|
|
|
6
6
|
useModuleRuntime,
|
|
7
7
|
useRuntime,
|
|
8
8
|
useStableId
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-E3ZXST5F.js";
|
|
10
10
|
import {
|
|
11
11
|
RuntimeContext,
|
|
12
12
|
getModuleCache,
|
|
13
13
|
isDevEnv,
|
|
14
14
|
stableHash
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-L7KTYBXN.js";
|
|
16
16
|
|
|
17
17
|
// src/internal/hooks/useLocalModule.ts
|
|
18
18
|
import React, { useEffect, useMemo } from "react";
|
|
19
19
|
import * as Logix from "@logixjs/core";
|
|
20
|
-
import {
|
|
20
|
+
import { Effect, Layer, Scope, ServiceMap } from "effect";
|
|
21
21
|
function isModuleTag(source) {
|
|
22
22
|
if (!source || typeof source !== "object" && typeof source !== "function") {
|
|
23
23
|
return false;
|
|
@@ -74,7 +74,7 @@ function useLocalModule(source, second) {
|
|
|
74
74
|
return createModuleTagFactory(moduleTag, moduleOptions);
|
|
75
75
|
}
|
|
76
76
|
const factoryFn = source;
|
|
77
|
-
return (scope) =>
|
|
77
|
+
return (scope) => Scope.provide(scope)(factoryFn());
|
|
78
78
|
}, [isModule, moduleTag, source, moduleOptions]);
|
|
79
79
|
const moduleRuntime = cache.readSync(key, factory, void 0, ownerId, {
|
|
80
80
|
entrypoint: "react.useLocalModule",
|
|
@@ -136,7 +136,7 @@ function createModuleTagFactory(module, options) {
|
|
|
136
136
|
const logics = options.logics ?? [];
|
|
137
137
|
return (scope) => Layer.buildWithScope(module.live(options.initial, ...logics), scope).pipe(
|
|
138
138
|
Effect.map((context) => {
|
|
139
|
-
const runtime =
|
|
139
|
+
const runtime = ServiceMap.get(context, module);
|
|
140
140
|
return runtime;
|
|
141
141
|
})
|
|
142
142
|
);
|
|
@@ -144,12 +144,12 @@ function createModuleTagFactory(module, options) {
|
|
|
144
144
|
|
|
145
145
|
// src/internal/hooks/useLayerModule.ts
|
|
146
146
|
import React2 from "react";
|
|
147
|
-
import {
|
|
147
|
+
import { Effect as Effect2, Layer as Layer2, ServiceMap as ServiceMap2 } from "effect";
|
|
148
148
|
function useLayerModule(module, layer, deps = []) {
|
|
149
149
|
const factory = React2.useCallback(
|
|
150
150
|
() => Layer2.build(layer).pipe(
|
|
151
151
|
Effect2.scoped,
|
|
152
|
-
Effect2.map((context) =>
|
|
152
|
+
Effect2.map((context) => ServiceMap2.get(context, module))
|
|
153
153
|
),
|
|
154
154
|
// layer/module are typically constants; deps lets callers opt into rebuilding when needed.
|
|
155
155
|
[layer, module]
|
|
@@ -330,7 +330,7 @@ function useProcesses(processes, options) {
|
|
|
330
330
|
}
|
|
331
331
|
return Effect3.forkScoped(process).pipe(Effect3.asVoid);
|
|
332
332
|
}),
|
|
333
|
-
Effect3.
|
|
333
|
+
Effect3.catch(() => Effect3.forkScoped(process).pipe(Effect3.asVoid))
|
|
334
334
|
),
|
|
335
335
|
{ discard: true }
|
|
336
336
|
).pipe(Effect3.provideService(Scope2.Scope, scope));
|