@logixjs/react 0.1.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Hooks.cjs +345 -142
- package/dist/Hooks.js +3 -3
- package/dist/ModuleScope.cjs +474 -187
- 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 +395 -111
- package/dist/ReactPlatform.js +5 -5
- package/dist/RuntimeProvider.cjs +254 -50
- package/dist/RuntimeProvider.js +2 -2
- package/dist/{chunk-WOTNVLCD.js → chunk-6NLXTHZ7.js} +8 -8
- package/dist/{chunk-G2LX7WWQ.js → chunk-E3ZXST5F.js} +129 -49
- package/dist/{chunk-JC3R6GII.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-STTE4SOJ.js → chunk-SDQF3WRT.js} +6 -3
- package/dist/{chunk-2M6MDNVT.js → chunk-XSGDBJXD.js} +100 -19
- package/dist/index.cjs +435 -151
- package/dist/index.js +7 -7
- package/package.json +9 -4
package/dist/ModuleScope.cjs
CHANGED
|
@@ -34,17 +34,18 @@ __export(ModuleScope_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(ModuleScope_exports);
|
|
36
36
|
var import_react10 = __toESM(require("react"), 1);
|
|
37
|
-
var
|
|
37
|
+
var import_effect11 = require("effect");
|
|
38
|
+
var Logix12 = __toESM(require("@logixjs/core"), 1);
|
|
38
39
|
|
|
39
40
|
// src/internal/hooks/useModule.ts
|
|
40
41
|
var import_react7 = __toESM(require("react"), 1);
|
|
41
|
-
var
|
|
42
|
-
var
|
|
42
|
+
var Logix9 = __toESM(require("@logixjs/core"), 1);
|
|
43
|
+
var import_effect8 = require("effect");
|
|
43
44
|
|
|
44
45
|
// src/internal/hooks/useModuleRuntime.ts
|
|
45
46
|
var import_react4 = require("react");
|
|
46
|
-
var
|
|
47
|
-
var
|
|
47
|
+
var Logix5 = __toESM(require("@logixjs/core"), 1);
|
|
48
|
+
var import_effect6 = require("effect");
|
|
48
49
|
|
|
49
50
|
// src/internal/hooks/useRuntime.ts
|
|
50
51
|
var import_react3 = require("react");
|
|
@@ -128,14 +129,11 @@ var useLayerBinding = (runtime, layer, enabled, onError) => {
|
|
|
128
129
|
const newScope = import_effect.Effect.runSync(import_effect.Scope.make());
|
|
129
130
|
const buildEffect = import_effect.Effect.gen(function* () {
|
|
130
131
|
const context = yield* import_effect.Layer.buildWithScope(layer, newScope);
|
|
131
|
-
const applyEnv = (effect) => import_effect.Effect.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
);
|
|
135
|
-
const loggers = yield* applyEnv(import_effect.FiberRef.get(import_effect.FiberRef.currentLoggers));
|
|
136
|
-
const logLevel = yield* applyEnv(import_effect.FiberRef.get(import_effect.FiberRef.currentLogLevel));
|
|
132
|
+
const applyEnv = (effect) => import_effect.Scope.provide(newScope)(import_effect.Effect.provideServices(effect, context));
|
|
133
|
+
const loggers = yield* applyEnv(import_effect.Effect.service(import_effect.Logger.CurrentLoggers)).pipe(import_effect.Effect.orDie);
|
|
134
|
+
const logLevel = yield* applyEnv(import_effect.Effect.service(import_effect.References.MinimumLogLevel)).pipe(import_effect.Effect.orDie);
|
|
137
135
|
const debugSinks = yield* applyEnv(
|
|
138
|
-
import_effect.
|
|
136
|
+
import_effect.Effect.service(Logix.Debug.internal.currentDebugSinks).pipe(import_effect.Effect.orDie)
|
|
139
137
|
);
|
|
140
138
|
return { context, loggers, logLevel, debugSinks };
|
|
141
139
|
});
|
|
@@ -180,7 +178,7 @@ var useLayerBinding = (runtime, layer, enabled, onError) => {
|
|
|
180
178
|
const cause = import_effect.Cause.die(error);
|
|
181
179
|
runtime.runFork(
|
|
182
180
|
onError(cause, { source: "provider", phase: "provider.layer.build" }).pipe(
|
|
183
|
-
import_effect.Effect.
|
|
181
|
+
import_effect.Effect.catchCause(() => import_effect.Effect.void)
|
|
184
182
|
)
|
|
185
183
|
);
|
|
186
184
|
}
|
|
@@ -218,18 +216,11 @@ var createRuntimeAdapter = (runtime, contexts, scopes, loggerSets, logLevels, de
|
|
|
218
216
|
if (contexts.length === 0 && scopes.length === 0 && loggerSets.length === 0 && logLevels.length === 0 && debugSinks.length === 0) {
|
|
219
217
|
return runtime;
|
|
220
218
|
}
|
|
221
|
-
const applyContexts = (effect) => (
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
acc,
|
|
227
|
-
(parent) => import_effect.Context.merge(parent, ctx)
|
|
228
|
-
),
|
|
229
|
-
scopes.reduceRight(
|
|
230
|
-
(acc, scope) => import_effect.Scope.extend(acc, scope),
|
|
231
|
-
effect
|
|
232
|
-
)
|
|
219
|
+
const applyContexts = (effect) => contexts.reduceRight(
|
|
220
|
+
(acc, ctx) => import_effect.Effect.provideServices(acc, ctx),
|
|
221
|
+
scopes.reduceRight(
|
|
222
|
+
(acc, scope) => import_effect.Scope.provide(scope)(acc),
|
|
223
|
+
effect
|
|
233
224
|
)
|
|
234
225
|
);
|
|
235
226
|
const applyLoggers = (effect) => {
|
|
@@ -238,16 +229,13 @@ var createRuntimeAdapter = (runtime, contexts, scopes, loggerSets, logLevels, de
|
|
|
238
229
|
const sinks = debugSinks.length > 0 ? debugSinks[debugSinks.length - 1] : null;
|
|
239
230
|
let result = effect;
|
|
240
231
|
if (last) {
|
|
241
|
-
result = import_effect.Effect.
|
|
232
|
+
result = import_effect.Effect.provideService(result, import_effect.Logger.CurrentLoggers, last);
|
|
242
233
|
}
|
|
243
234
|
if (logLevel) {
|
|
244
|
-
result = import_effect.Effect.
|
|
235
|
+
result = import_effect.Effect.provideService(result, import_effect.References.MinimumLogLevel, logLevel);
|
|
245
236
|
}
|
|
246
237
|
if (sinks && sinks.length > 0) {
|
|
247
|
-
result = import_effect.Effect.
|
|
248
|
-
Logix.Debug.internal.currentDebugSinks,
|
|
249
|
-
sinks
|
|
250
|
-
)(result);
|
|
238
|
+
result = import_effect.Effect.provideService(result, Logix.Debug.internal.currentDebugSinks, sinks);
|
|
251
239
|
}
|
|
252
240
|
return result;
|
|
253
241
|
};
|
|
@@ -426,27 +414,41 @@ var applyHandleExtend = (tag, runtime, base) => {
|
|
|
426
414
|
return { ...base, ...next };
|
|
427
415
|
};
|
|
428
416
|
|
|
417
|
+
// src/internal/provider/runtimeDebugBridge.ts
|
|
418
|
+
var import_effect3 = require("effect");
|
|
419
|
+
var Logix2 = __toESM(require("@logixjs/core"), 1);
|
|
420
|
+
var readRuntimeDiagnosticsLevel = (runtime) => {
|
|
421
|
+
try {
|
|
422
|
+
return runtime.runSync(import_effect3.Effect.service(Logix2.Debug.internal.currentDiagnosticsLevel).pipe(import_effect3.Effect.orDie));
|
|
423
|
+
} catch {
|
|
424
|
+
return (0, import_Env.isDevEnv)() ? "light" : "off";
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
var emitRuntimeDebugEventBestEffort = (runtime, event) => {
|
|
428
|
+
runtime.runFork(event);
|
|
429
|
+
};
|
|
430
|
+
|
|
429
431
|
// src/internal/store/ModuleCache.ts
|
|
430
|
-
var
|
|
431
|
-
var
|
|
432
|
+
var Logix4 = __toESM(require("@logixjs/core"), 1);
|
|
433
|
+
var import_effect5 = require("effect");
|
|
432
434
|
|
|
433
435
|
// src/internal/store/perfWorkloads.ts
|
|
434
|
-
var
|
|
435
|
-
var
|
|
436
|
-
var PerfCounterStateSchema =
|
|
437
|
-
value:
|
|
436
|
+
var Logix3 = __toESM(require("@logixjs/core"), 1);
|
|
437
|
+
var import_effect4 = require("effect");
|
|
438
|
+
var PerfCounterStateSchema = import_effect4.Schema.Struct({
|
|
439
|
+
value: import_effect4.Schema.Number
|
|
438
440
|
});
|
|
439
441
|
var PerfCounterActions = {
|
|
440
|
-
inc:
|
|
442
|
+
inc: import_effect4.Schema.Void
|
|
441
443
|
};
|
|
442
|
-
var PerfListScopeRowSchema =
|
|
443
|
-
id:
|
|
444
|
-
warehouseId:
|
|
444
|
+
var PerfListScopeRowSchema = import_effect4.Schema.Struct({
|
|
445
|
+
id: import_effect4.Schema.String,
|
|
446
|
+
warehouseId: import_effect4.Schema.String
|
|
445
447
|
});
|
|
446
|
-
var PerfListScopeStateSchema =
|
|
447
|
-
items:
|
|
448
|
-
digest:
|
|
449
|
-
errors:
|
|
448
|
+
var PerfListScopeStateSchema = import_effect4.Schema.Struct({
|
|
449
|
+
items: import_effect4.Schema.Array(PerfListScopeRowSchema),
|
|
450
|
+
digest: import_effect4.Schema.String,
|
|
451
|
+
errors: import_effect4.Schema.Any
|
|
450
452
|
});
|
|
451
453
|
var GLOBAL_YIELD_BUDGET_MEMORY_KEY = "__LOGIX_REACT_YIELD_BUDGET_MEMORY__";
|
|
452
454
|
var getGlobalYieldBudgetMemory = () => {
|
|
@@ -541,20 +543,20 @@ ${message}`;
|
|
|
541
543
|
console.debug(label, message);
|
|
542
544
|
};
|
|
543
545
|
var causeToUnknown = (cause) => {
|
|
544
|
-
const failure =
|
|
546
|
+
const failure = import_effect5.Option.getOrUndefined(import_effect5.Cause.findErrorOption(cause));
|
|
545
547
|
if (failure !== void 0) return failure;
|
|
546
|
-
const defect =
|
|
548
|
+
const defect = cause.reasons.filter(import_effect5.Cause.isDieReason).map((reason) => reason.defect)[0];
|
|
547
549
|
if (defect !== void 0) return defect;
|
|
548
550
|
return cause;
|
|
549
551
|
};
|
|
550
552
|
var yieldEffect = (strategy) => {
|
|
551
553
|
switch (strategy) {
|
|
552
554
|
case "none":
|
|
553
|
-
return
|
|
555
|
+
return import_effect5.Effect.void;
|
|
554
556
|
case "microtask":
|
|
555
|
-
return
|
|
557
|
+
return import_effect5.Effect.yieldNow;
|
|
556
558
|
case "macrotask":
|
|
557
|
-
return
|
|
559
|
+
return import_effect5.Effect.promise(
|
|
558
560
|
() => new Promise((resolve) => {
|
|
559
561
|
setTimeout(resolve, 0);
|
|
560
562
|
})
|
|
@@ -602,11 +604,11 @@ var ModuleCache = class {
|
|
|
602
604
|
this.scheduleGC(key, current);
|
|
603
605
|
return;
|
|
604
606
|
}
|
|
605
|
-
void this.runtime.runPromise(
|
|
607
|
+
void this.runtime.runPromise(import_effect5.Scope.close(current.scope, import_effect5.Exit.void)).catch((error) => {
|
|
606
608
|
debugBestEffortFailure("[ModuleCache] Scope.close failed", error);
|
|
607
609
|
});
|
|
608
610
|
void this.runtime.runPromise(
|
|
609
|
-
|
|
611
|
+
Logix4.Debug.record({
|
|
610
612
|
type: "trace:react.module-instance",
|
|
611
613
|
moduleId: current.ownerId,
|
|
612
614
|
instanceId: current.value?.instanceId,
|
|
@@ -642,9 +644,70 @@ var ModuleCache = class {
|
|
|
642
644
|
}
|
|
643
645
|
return existing.value;
|
|
644
646
|
}
|
|
645
|
-
const scope =
|
|
647
|
+
const scope = import_effect5.Effect.runSync(import_effect5.Scope.make());
|
|
646
648
|
const workloadKey = `${options?.entrypoint ?? "unknown"}::${ownerId ?? "unknown"}`;
|
|
647
649
|
const yieldDecision = decideYieldStrategy(this.runtime, workloadKey, options?.yield);
|
|
650
|
+
const optimisticSyncBudgetMs = options?.optimisticSyncBudgetMs ?? 0;
|
|
651
|
+
const shouldTryOptimisticSync = options?.policyMode === "suspend" && optimisticSyncBudgetMs > 0;
|
|
652
|
+
if (shouldTryOptimisticSync) {
|
|
653
|
+
const startedAt2 = performance.now();
|
|
654
|
+
try {
|
|
655
|
+
const value = this.runtime.runSync(factory(scope));
|
|
656
|
+
const durationMs = performance.now() - startedAt2;
|
|
657
|
+
YieldBudgetMemory.record({ runtime: this.runtime, workloadKey, durationMs });
|
|
658
|
+
const entry2 = {
|
|
659
|
+
scope,
|
|
660
|
+
status: "success",
|
|
661
|
+
promise: Promise.resolve(value),
|
|
662
|
+
value,
|
|
663
|
+
refCount: 0,
|
|
664
|
+
preloadRefCount: 0,
|
|
665
|
+
gcTime: gcTime ?? this.gcDelayMs,
|
|
666
|
+
ownerId,
|
|
667
|
+
createdBy: "read",
|
|
668
|
+
workloadKey,
|
|
669
|
+
yieldStrategy: "none"
|
|
670
|
+
};
|
|
671
|
+
this.scheduleGC(key, entry2);
|
|
672
|
+
this.entries.set(key, entry2);
|
|
673
|
+
if ((0, import_Env.isDevEnv)() || Logix4.Debug.isDevtoolsEnabled()) {
|
|
674
|
+
void this.runtime.runPromise(
|
|
675
|
+
Logix4.Debug.record({
|
|
676
|
+
type: "trace:react.module.init",
|
|
677
|
+
moduleId: ownerId,
|
|
678
|
+
instanceId: value.instanceId,
|
|
679
|
+
data: {
|
|
680
|
+
mode: "suspend",
|
|
681
|
+
key,
|
|
682
|
+
durationMs: Math.round(durationMs * 100) / 100,
|
|
683
|
+
yieldStrategy: "none",
|
|
684
|
+
fastPath: "sync"
|
|
685
|
+
}
|
|
686
|
+
})
|
|
687
|
+
).catch((error) => {
|
|
688
|
+
debugBestEffortFailure("[ModuleCache] Debug.record failed", error);
|
|
689
|
+
});
|
|
690
|
+
void this.runtime.runPromise(
|
|
691
|
+
Logix4.Debug.record({
|
|
692
|
+
type: "trace:react.module-instance",
|
|
693
|
+
moduleId: ownerId,
|
|
694
|
+
instanceId: value.instanceId,
|
|
695
|
+
data: {
|
|
696
|
+
event: "attach",
|
|
697
|
+
key,
|
|
698
|
+
mode: "suspend",
|
|
699
|
+
gcTime: entry2.gcTime,
|
|
700
|
+
fastPath: "sync"
|
|
701
|
+
}
|
|
702
|
+
})
|
|
703
|
+
).catch((error) => {
|
|
704
|
+
debugBestEffortFailure("[ModuleCache] Debug.record failed", error);
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
return value;
|
|
708
|
+
} catch {
|
|
709
|
+
}
|
|
710
|
+
}
|
|
648
711
|
const entry = {
|
|
649
712
|
scope,
|
|
650
713
|
status: "pending",
|
|
@@ -660,11 +723,11 @@ var ModuleCache = class {
|
|
|
660
723
|
};
|
|
661
724
|
this.scheduleGC(key, entry);
|
|
662
725
|
const startedAt = performance.now();
|
|
663
|
-
const buildEffect = yieldEffect(yieldDecision.strategy).pipe(
|
|
726
|
+
const buildEffect = yieldEffect(yieldDecision.strategy).pipe(import_effect5.Effect.flatMap(() => factory(scope)));
|
|
664
727
|
const fiber = this.runtime.runFork(buildEffect);
|
|
665
728
|
entry.fiber = fiber;
|
|
666
|
-
const promise = this.runtime.runPromise(
|
|
667
|
-
if (
|
|
729
|
+
const promise = this.runtime.runPromise(import_effect5.Fiber.await(fiber)).then((exit) => {
|
|
730
|
+
if (import_effect5.Exit.isSuccess(exit)) return exit.value;
|
|
668
731
|
throw causeToUnknown(exit.cause);
|
|
669
732
|
});
|
|
670
733
|
promise.then((value) => {
|
|
@@ -672,9 +735,9 @@ var ModuleCache = class {
|
|
|
672
735
|
entry.value = value;
|
|
673
736
|
const durationMs = performance.now() - startedAt;
|
|
674
737
|
YieldBudgetMemory.record({ runtime: this.runtime, workloadKey, durationMs });
|
|
675
|
-
if ((0, import_Env.isDevEnv)() ||
|
|
738
|
+
if ((0, import_Env.isDevEnv)() || Logix4.Debug.isDevtoolsEnabled()) {
|
|
676
739
|
void this.runtime.runPromise(
|
|
677
|
-
|
|
740
|
+
Logix4.Debug.record({
|
|
678
741
|
type: "trace:react.module.init",
|
|
679
742
|
moduleId: ownerId,
|
|
680
743
|
instanceId: value.instanceId,
|
|
@@ -691,7 +754,7 @@ var ModuleCache = class {
|
|
|
691
754
|
debugBestEffortFailure("[ModuleCache] Debug.record failed", error);
|
|
692
755
|
});
|
|
693
756
|
void this.runtime.runPromise(
|
|
694
|
-
|
|
757
|
+
Logix4.Debug.record({
|
|
695
758
|
type: "trace:react.module-instance",
|
|
696
759
|
moduleId: ownerId,
|
|
697
760
|
instanceId: value.instanceId,
|
|
@@ -721,7 +784,7 @@ var ModuleCache = class {
|
|
|
721
784
|
workloadKey,
|
|
722
785
|
durationMs: performance.now() - startedAt
|
|
723
786
|
});
|
|
724
|
-
void this.runtime.runPromise(
|
|
787
|
+
void this.runtime.runPromise(import_effect5.Scope.close(scope, import_effect5.Exit.fail(error))).catch((closeError) => {
|
|
725
788
|
debugBestEffortFailure("[ModuleCache] Scope.close failed", closeError);
|
|
726
789
|
});
|
|
727
790
|
throw error;
|
|
@@ -753,7 +816,7 @@ var ModuleCache = class {
|
|
|
753
816
|
}
|
|
754
817
|
return existing.value;
|
|
755
818
|
}
|
|
756
|
-
const scope = this.runtime.runSync(
|
|
819
|
+
const scope = this.runtime.runSync(import_effect5.Scope.make());
|
|
757
820
|
const startedAt = performance.now();
|
|
758
821
|
try {
|
|
759
822
|
const value = this.runtime.runSync(factory(scope));
|
|
@@ -801,9 +864,9 @@ var ModuleCache = class {
|
|
|
801
864
|
}
|
|
802
865
|
}
|
|
803
866
|
}
|
|
804
|
-
if ((0, import_Env.isDevEnv)() ||
|
|
867
|
+
if ((0, import_Env.isDevEnv)() || Logix4.Debug.isDevtoolsEnabled()) {
|
|
805
868
|
void this.runtime.runPromise(
|
|
806
|
-
|
|
869
|
+
Logix4.Debug.record({
|
|
807
870
|
type: "trace:react.module.init",
|
|
808
871
|
moduleId: ownerId,
|
|
809
872
|
instanceId: value.instanceId,
|
|
@@ -818,7 +881,7 @@ var ModuleCache = class {
|
|
|
818
881
|
debugBestEffortFailure("[ModuleCache] Debug.record failed", error);
|
|
819
882
|
});
|
|
820
883
|
void this.runtime.runPromise(
|
|
821
|
-
|
|
884
|
+
Logix4.Debug.record({
|
|
822
885
|
type: "trace:react.module-instance",
|
|
823
886
|
moduleId: ownerId,
|
|
824
887
|
instanceId: value.instanceId,
|
|
@@ -835,7 +898,7 @@ var ModuleCache = class {
|
|
|
835
898
|
}
|
|
836
899
|
return value;
|
|
837
900
|
} catch (error) {
|
|
838
|
-
void this.runtime.runPromise(
|
|
901
|
+
void this.runtime.runPromise(import_effect5.Scope.close(scope, import_effect5.Exit.fail(error))).catch((closeError) => {
|
|
839
902
|
debugBestEffortFailure("[ModuleCache] Scope.close failed", closeError);
|
|
840
903
|
});
|
|
841
904
|
const entry = {
|
|
@@ -856,6 +919,49 @@ var ModuleCache = class {
|
|
|
856
919
|
throw error;
|
|
857
920
|
}
|
|
858
921
|
}
|
|
922
|
+
warmSync(key, factory, gcTime, ownerId, options) {
|
|
923
|
+
const existing = this.entries.get(key);
|
|
924
|
+
if (existing) {
|
|
925
|
+
if ((0, import_Env.isDevEnv)() && existing.ownerId !== void 0 && ownerId !== void 0 && existing.ownerId !== ownerId) {
|
|
926
|
+
throw new Error(
|
|
927
|
+
`[ModuleCache.warmSync] resource key "${key}" has already been claimed by module "${existing.ownerId}", but is now requested by module "${ownerId}".`
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
if (existing.status === "success") {
|
|
931
|
+
return existing.value;
|
|
932
|
+
}
|
|
933
|
+
return void 0;
|
|
934
|
+
}
|
|
935
|
+
const scope = this.runtime.runSync(import_effect5.Scope.make());
|
|
936
|
+
const startedAt = performance.now();
|
|
937
|
+
const workloadKey = `${options?.entrypoint ?? "unknown"}::${ownerId ?? "unknown"}`;
|
|
938
|
+
try {
|
|
939
|
+
const value = this.runtime.runSync(factory(scope));
|
|
940
|
+
const durationMs = performance.now() - startedAt;
|
|
941
|
+
YieldBudgetMemory.record({ runtime: this.runtime, workloadKey, durationMs });
|
|
942
|
+
const entry = {
|
|
943
|
+
scope,
|
|
944
|
+
status: "success",
|
|
945
|
+
promise: Promise.resolve(value),
|
|
946
|
+
value,
|
|
947
|
+
refCount: 0,
|
|
948
|
+
preloadRefCount: 0,
|
|
949
|
+
gcTime: gcTime ?? this.gcDelayMs,
|
|
950
|
+
ownerId,
|
|
951
|
+
createdBy: "preload",
|
|
952
|
+
workloadKey,
|
|
953
|
+
yieldStrategy: "none"
|
|
954
|
+
};
|
|
955
|
+
this.scheduleGC(key, entry);
|
|
956
|
+
this.entries.set(key, entry);
|
|
957
|
+
return value;
|
|
958
|
+
} catch (error) {
|
|
959
|
+
void this.runtime.runPromise(import_effect5.Scope.close(scope, import_effect5.Exit.fail(error))).catch((closeError) => {
|
|
960
|
+
debugBestEffortFailure("[ModuleCache] Scope.close failed", closeError);
|
|
961
|
+
});
|
|
962
|
+
return void 0;
|
|
963
|
+
}
|
|
964
|
+
}
|
|
859
965
|
preload(key, factory, options) {
|
|
860
966
|
const existing = this.entries.get(key);
|
|
861
967
|
if (existing) {
|
|
@@ -880,11 +986,43 @@ var ModuleCache = class {
|
|
|
880
986
|
}
|
|
881
987
|
};
|
|
882
988
|
}
|
|
883
|
-
const scope =
|
|
989
|
+
const scope = import_effect5.Effect.runSync(import_effect5.Scope.make());
|
|
884
990
|
const ownerId = options?.ownerId;
|
|
885
991
|
const gcTime = options?.gcTime ?? this.gcDelayMs;
|
|
886
992
|
const workloadKey = `${options?.entrypoint ?? "unknown"}::${ownerId ?? "unknown"}`;
|
|
887
993
|
const yieldDecision = decideYieldStrategy(this.runtime, workloadKey, options?.yield);
|
|
994
|
+
const optimisticSyncBudgetMs = options?.optimisticSyncBudgetMs ?? 0;
|
|
995
|
+
const shouldTryOptimisticSync = options?.policyMode === "defer" && optimisticSyncBudgetMs > 0;
|
|
996
|
+
if (shouldTryOptimisticSync) {
|
|
997
|
+
const startedAt2 = performance.now();
|
|
998
|
+
try {
|
|
999
|
+
const value = this.runtime.runSync(factory(scope));
|
|
1000
|
+
const durationMs = performance.now() - startedAt2;
|
|
1001
|
+
YieldBudgetMemory.record({ runtime: this.runtime, workloadKey, durationMs });
|
|
1002
|
+
const entry2 = {
|
|
1003
|
+
scope,
|
|
1004
|
+
status: "success",
|
|
1005
|
+
promise: Promise.resolve(value),
|
|
1006
|
+
value,
|
|
1007
|
+
refCount: 0,
|
|
1008
|
+
preloadRefCount: 1,
|
|
1009
|
+
gcTime,
|
|
1010
|
+
ownerId,
|
|
1011
|
+
createdBy: "preload",
|
|
1012
|
+
workloadKey,
|
|
1013
|
+
yieldStrategy: "none"
|
|
1014
|
+
};
|
|
1015
|
+
this.scheduleGC(key, entry2);
|
|
1016
|
+
this.entries.set(key, entry2);
|
|
1017
|
+
return {
|
|
1018
|
+
promise: Promise.resolve(value),
|
|
1019
|
+
cancel: () => {
|
|
1020
|
+
this.cancelPreload(key, entry2);
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
} catch {
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
888
1026
|
const entry = {
|
|
889
1027
|
scope,
|
|
890
1028
|
status: "pending",
|
|
@@ -900,11 +1038,11 @@ var ModuleCache = class {
|
|
|
900
1038
|
this.scheduleGC(key, entry);
|
|
901
1039
|
this.entries.set(key, entry);
|
|
902
1040
|
const startedAt = performance.now();
|
|
903
|
-
const buildEffect = yieldEffect(yieldDecision.strategy).pipe(
|
|
1041
|
+
const buildEffect = yieldEffect(yieldDecision.strategy).pipe(import_effect5.Effect.flatMap(() => factory(scope)));
|
|
904
1042
|
const fiber = this.runtime.runFork(buildEffect);
|
|
905
1043
|
entry.fiber = fiber;
|
|
906
|
-
const promise = this.runtime.runPromise(
|
|
907
|
-
if (
|
|
1044
|
+
const promise = this.runtime.runPromise(import_effect5.Fiber.await(fiber)).then((exit) => {
|
|
1045
|
+
if (import_effect5.Exit.isSuccess(exit)) return exit.value;
|
|
908
1046
|
throw causeToUnknown(exit.cause);
|
|
909
1047
|
});
|
|
910
1048
|
entry.promise = promise;
|
|
@@ -930,7 +1068,7 @@ var ModuleCache = class {
|
|
|
930
1068
|
workloadKey,
|
|
931
1069
|
durationMs: performance.now() - startedAt
|
|
932
1070
|
});
|
|
933
|
-
void this.runtime.runPromise(
|
|
1071
|
+
void this.runtime.runPromise(import_effect5.Scope.close(scope, import_effect5.Exit.fail(error))).catch((closeError) => {
|
|
934
1072
|
debugBestEffortFailure("[ModuleCache] Scope.close failed", closeError);
|
|
935
1073
|
});
|
|
936
1074
|
});
|
|
@@ -962,9 +1100,9 @@ var ModuleCache = class {
|
|
|
962
1100
|
entry.fiber = void 0;
|
|
963
1101
|
this.entries.delete(key);
|
|
964
1102
|
if (running) {
|
|
965
|
-
this.runtime.runFork(
|
|
1103
|
+
this.runtime.runFork(import_effect5.Fiber.interrupt(running));
|
|
966
1104
|
}
|
|
967
|
-
void this.runtime.runPromise(
|
|
1105
|
+
void this.runtime.runPromise(import_effect5.Scope.close(entry.scope, import_effect5.Exit.void)).catch((closeError) => {
|
|
968
1106
|
debugBestEffortFailure("[ModuleCache] Scope.close failed", closeError);
|
|
969
1107
|
});
|
|
970
1108
|
return;
|
|
@@ -1010,7 +1148,7 @@ var ModuleCache = class {
|
|
|
1010
1148
|
if (entry.gcTimeout) {
|
|
1011
1149
|
clearTimeout(entry.gcTimeout);
|
|
1012
1150
|
}
|
|
1013
|
-
void this.runtime.runPromise(
|
|
1151
|
+
void this.runtime.runPromise(import_effect5.Scope.close(entry.scope, import_effect5.Exit.void)).catch((error) => {
|
|
1014
1152
|
debugBestEffortFailure("[ModuleCache] Scope.close failed", error);
|
|
1015
1153
|
});
|
|
1016
1154
|
this.entries.delete(key);
|
|
@@ -1066,6 +1204,7 @@ var isModuleRuntime = (value) => typeof value === "object" && value !== null &&
|
|
|
1066
1204
|
function useModuleRuntime(handle) {
|
|
1067
1205
|
const runtime = useRuntime();
|
|
1068
1206
|
const runtimeContext = (0, import_react4.useContext)(RuntimeContext);
|
|
1207
|
+
const moduleTagResolveTraceRef = (0, import_react4.useRef)(void 0);
|
|
1069
1208
|
if (!runtimeContext) {
|
|
1070
1209
|
throw new RuntimeProviderNotFoundError("useModuleRuntime");
|
|
1071
1210
|
}
|
|
@@ -1086,36 +1225,48 @@ function useModuleRuntime(handle) {
|
|
|
1086
1225
|
const preloadKey = runtimeContext.policy.preload?.keysByTagId.get(tokenId);
|
|
1087
1226
|
const key = preloadKey ?? `tag:${tokenId}`;
|
|
1088
1227
|
const mode = runtimeContext.policy.moduleTagMode;
|
|
1089
|
-
const
|
|
1090
|
-
|
|
1228
|
+
const startedAtMs = performance.now();
|
|
1229
|
+
const factory = (scope) => import_effect6.Scope.provide(scope)(import_effect6.Effect.service(tag).pipe(import_effect6.Effect.orDie));
|
|
1230
|
+
const resolvedRuntime = mode === "suspend" ? cache.read(key, factory, void 0, tokenId, {
|
|
1091
1231
|
entrypoint: "react.useModuleRuntime",
|
|
1092
1232
|
policyMode: runtimeContext.policy.mode,
|
|
1093
|
-
yield: runtimeContext.policy.yield
|
|
1233
|
+
yield: runtimeContext.policy.yield,
|
|
1234
|
+
optimisticSyncBudgetMs: runtimeContext.policy.syncBudgetMs
|
|
1094
1235
|
}) : cache.readSync(key, factory, void 0, tokenId, {
|
|
1095
1236
|
entrypoint: "react.useModuleRuntime",
|
|
1096
1237
|
policyMode: runtimeContext.policy.mode,
|
|
1097
1238
|
warnSyncBlockingThresholdMs: 5
|
|
1098
1239
|
});
|
|
1240
|
+
moduleTagResolveTraceRef.current = {
|
|
1241
|
+
tokenId,
|
|
1242
|
+
durationMs: Math.round((performance.now() - startedAtMs) * 100) / 100,
|
|
1243
|
+
cacheMode: mode
|
|
1244
|
+
};
|
|
1245
|
+
return resolvedRuntime;
|
|
1099
1246
|
}, [cache, runtimeContext.policy, handle]);
|
|
1100
1247
|
(0, import_react4.useEffect)(() => {
|
|
1101
1248
|
if (!isTagHandle) {
|
|
1102
1249
|
return;
|
|
1103
1250
|
}
|
|
1104
|
-
|
|
1251
|
+
const diagnosticsLevel = readRuntimeDiagnosticsLevel(runtime);
|
|
1252
|
+
if (diagnosticsLevel === "off") {
|
|
1105
1253
|
return;
|
|
1106
1254
|
}
|
|
1107
1255
|
const tokenId = handle?.id ?? "ModuleTag";
|
|
1108
|
-
const
|
|
1256
|
+
const trace = moduleTagResolveTraceRef.current;
|
|
1257
|
+
const effect = Logix5.Debug.record({
|
|
1109
1258
|
type: "trace:react.moduleTag.resolve",
|
|
1110
1259
|
moduleId: resolved.moduleId,
|
|
1111
1260
|
instanceId: resolved.instanceId,
|
|
1112
1261
|
data: {
|
|
1113
1262
|
mode: runtimeContext.policy.moduleTagMode,
|
|
1114
1263
|
tokenId,
|
|
1115
|
-
yieldStrategy: runtimeContext.policy.yield.strategy
|
|
1264
|
+
yieldStrategy: runtimeContext.policy.yield.strategy,
|
|
1265
|
+
durationMs: trace?.durationMs,
|
|
1266
|
+
cacheMode: trace?.cacheMode ?? runtimeContext.policy.moduleTagMode
|
|
1116
1267
|
}
|
|
1117
1268
|
});
|
|
1118
|
-
runtime
|
|
1269
|
+
emitRuntimeDebugEventBestEffort(runtime, effect);
|
|
1119
1270
|
}, [runtime, runtimeContext.policy, resolved, handle, isTagHandle]);
|
|
1120
1271
|
return resolved;
|
|
1121
1272
|
}
|
|
@@ -1123,11 +1274,11 @@ function useModuleRuntime(handle) {
|
|
|
1123
1274
|
// src/internal/hooks/useSelector.ts
|
|
1124
1275
|
var import_react5 = require("react");
|
|
1125
1276
|
var import_with_selector = require("use-sync-external-store/shim/with-selector");
|
|
1126
|
-
var
|
|
1277
|
+
var Logix7 = __toESM(require("@logixjs/core"), 1);
|
|
1127
1278
|
|
|
1128
1279
|
// src/internal/store/RuntimeExternalStore.ts
|
|
1129
|
-
var
|
|
1130
|
-
var
|
|
1280
|
+
var Logix6 = __toESM(require("@logixjs/core"), 1);
|
|
1281
|
+
var import_effect7 = require("effect");
|
|
1131
1282
|
var storesByRuntime = /* @__PURE__ */ new WeakMap();
|
|
1132
1283
|
var getStoreMapForRuntime = (runtime) => {
|
|
1133
1284
|
const cached = storesByRuntime.get(runtime);
|
|
@@ -1138,8 +1289,8 @@ var getStoreMapForRuntime = (runtime) => {
|
|
|
1138
1289
|
};
|
|
1139
1290
|
var makeModuleInstanceKey = (moduleId, instanceId) => `${moduleId}::${instanceId}`;
|
|
1140
1291
|
var makeReadQueryTopicKey = (moduleInstanceKey, selectorId) => `${moduleInstanceKey}::rq:${selectorId}`;
|
|
1141
|
-
var getRuntimeStore = (runtime) =>
|
|
1142
|
-
var getHostScheduler = (runtime) =>
|
|
1292
|
+
var getRuntimeStore = (runtime) => Logix6.InternalContracts.getRuntimeStore(runtime);
|
|
1293
|
+
var getHostScheduler = (runtime) => Logix6.InternalContracts.getHostScheduler(runtime);
|
|
1143
1294
|
var getOrCreateStore = (runtime, topicKey, make) => {
|
|
1144
1295
|
const map = getStoreMapForRuntime(runtime);
|
|
1145
1296
|
const cached = map.get(topicKey);
|
|
@@ -1163,6 +1314,8 @@ var makeTopicExternalStore = (args) => {
|
|
|
1163
1314
|
let currentSnapshot;
|
|
1164
1315
|
const listeners = /* @__PURE__ */ new Set();
|
|
1165
1316
|
let unsubscribeFromRuntimeStore;
|
|
1317
|
+
let teardownScheduled = false;
|
|
1318
|
+
let teardownToken = 0;
|
|
1166
1319
|
const lowPriorityDelayMs = args.options?.lowPriorityDelayMs ?? 16;
|
|
1167
1320
|
const lowPriorityMaxDelayMs = args.options?.lowPriorityMaxDelayMs ?? 50;
|
|
1168
1321
|
let notifyScheduled = false;
|
|
@@ -1247,7 +1400,38 @@ var makeTopicExternalStore = (args) => {
|
|
|
1247
1400
|
currentSnapshot = next;
|
|
1248
1401
|
return next;
|
|
1249
1402
|
};
|
|
1403
|
+
const cancelScheduledTeardown = () => {
|
|
1404
|
+
if (!teardownScheduled) return;
|
|
1405
|
+
teardownScheduled = false;
|
|
1406
|
+
teardownToken += 1;
|
|
1407
|
+
};
|
|
1408
|
+
const finalizeTeardown = () => {
|
|
1409
|
+
if (listeners.size > 0) return;
|
|
1410
|
+
try {
|
|
1411
|
+
args.onLastListener?.();
|
|
1412
|
+
} catch {
|
|
1413
|
+
}
|
|
1414
|
+
const unsub = unsubscribeFromRuntimeStore;
|
|
1415
|
+
unsubscribeFromRuntimeStore = void 0;
|
|
1416
|
+
cancelLow();
|
|
1417
|
+
try {
|
|
1418
|
+
unsub?.();
|
|
1419
|
+
} catch {
|
|
1420
|
+
}
|
|
1421
|
+
removeStore(runtime, topicKey);
|
|
1422
|
+
};
|
|
1423
|
+
const scheduleTeardown = () => {
|
|
1424
|
+
if (teardownScheduled) return;
|
|
1425
|
+
teardownScheduled = true;
|
|
1426
|
+
const token = ++teardownToken;
|
|
1427
|
+
hostScheduler.scheduleMicrotask(() => {
|
|
1428
|
+
if (!teardownScheduled || token !== teardownToken) return;
|
|
1429
|
+
teardownScheduled = false;
|
|
1430
|
+
finalizeTeardown();
|
|
1431
|
+
});
|
|
1432
|
+
};
|
|
1250
1433
|
const subscribe = (listener) => {
|
|
1434
|
+
cancelScheduledTeardown();
|
|
1251
1435
|
const isFirst = listeners.size === 0;
|
|
1252
1436
|
listeners.add(listener);
|
|
1253
1437
|
ensureSubscription();
|
|
@@ -1261,18 +1445,7 @@ var makeTopicExternalStore = (args) => {
|
|
|
1261
1445
|
return () => {
|
|
1262
1446
|
listeners.delete(listener);
|
|
1263
1447
|
if (listeners.size > 0) return;
|
|
1264
|
-
|
|
1265
|
-
args.onLastListener?.();
|
|
1266
|
-
} catch {
|
|
1267
|
-
}
|
|
1268
|
-
const unsub = unsubscribeFromRuntimeStore;
|
|
1269
|
-
unsubscribeFromRuntimeStore = void 0;
|
|
1270
|
-
cancelLow();
|
|
1271
|
-
try {
|
|
1272
|
-
unsub?.();
|
|
1273
|
-
} catch {
|
|
1274
|
-
}
|
|
1275
|
-
removeStore(runtime, topicKey);
|
|
1448
|
+
scheduleTeardown();
|
|
1276
1449
|
};
|
|
1277
1450
|
};
|
|
1278
1451
|
return { getSnapshot, getServerSnapshot: getSnapshot, subscribe };
|
|
@@ -1316,14 +1489,14 @@ var getRuntimeReadQueryExternalStore = (runtime, moduleRuntime, selectorReadQuer
|
|
|
1316
1489
|
options,
|
|
1317
1490
|
onFirstListener: () => {
|
|
1318
1491
|
if (readQueryDrainFiber) return;
|
|
1319
|
-
const effect =
|
|
1492
|
+
const effect = import_effect7.Stream.runDrain(moduleRuntime.changesReadQueryWithMeta(selectorReadQuery));
|
|
1320
1493
|
readQueryDrainFiber = runtime.runFork(effect);
|
|
1321
1494
|
},
|
|
1322
1495
|
onLastListener: () => {
|
|
1323
1496
|
const fiber = readQueryDrainFiber;
|
|
1324
1497
|
if (!fiber) return;
|
|
1325
1498
|
readQueryDrainFiber = void 0;
|
|
1326
|
-
runtime.runFork(
|
|
1499
|
+
runtime.runFork(import_effect7.Fiber.interrupt(fiber));
|
|
1327
1500
|
}
|
|
1328
1501
|
})
|
|
1329
1502
|
);
|
|
@@ -1389,7 +1562,7 @@ function useSelector(handle, selector, equalityFn) {
|
|
|
1389
1562
|
const moduleRuntime = useModuleRuntime(handle);
|
|
1390
1563
|
const actualSelector = selector ?? ((state) => state);
|
|
1391
1564
|
const selectorReadQuery = (0, import_react5.useMemo)(
|
|
1392
|
-
() => typeof selector === "function" ?
|
|
1565
|
+
() => typeof selector === "function" ? Logix7.ReadQuery.compile(selector) : void 0,
|
|
1393
1566
|
[selector]
|
|
1394
1567
|
);
|
|
1395
1568
|
const actualEqualityFn = (0, import_react5.useMemo)(() => {
|
|
@@ -1427,7 +1600,7 @@ function useSelector(handle, selector, equalityFn) {
|
|
|
1427
1600
|
actualEqualityFn
|
|
1428
1601
|
);
|
|
1429
1602
|
(0, import_react5.useEffect)(() => {
|
|
1430
|
-
if (!(0, import_Env.isDevEnv)() && !
|
|
1603
|
+
if (!(0, import_Env.isDevEnv)() && !Logix7.Debug.isDevtoolsEnabled()) {
|
|
1431
1604
|
return;
|
|
1432
1605
|
}
|
|
1433
1606
|
const instanceId = moduleRuntime.instanceId;
|
|
@@ -1443,7 +1616,7 @@ function useSelector(handle, selector, equalityFn) {
|
|
|
1443
1616
|
const rawDebugKey = meta.debugKey;
|
|
1444
1617
|
selectorKey = typeof rawDebugKey === "string" && rawDebugKey.length > 0 ? rawDebugKey : typeof selector.name === "string" && selector.name.length > 0 ? selector.name : void 0;
|
|
1445
1618
|
}
|
|
1446
|
-
const effect =
|
|
1619
|
+
const effect = Logix7.Debug.record({
|
|
1447
1620
|
type: "trace:react-selector",
|
|
1448
1621
|
moduleId: moduleRuntime.moduleId,
|
|
1449
1622
|
instanceId,
|
|
@@ -1466,7 +1639,7 @@ function useSelector(handle, selector, equalityFn) {
|
|
|
1466
1639
|
}
|
|
1467
1640
|
|
|
1468
1641
|
// src/internal/store/resolveImportedModuleRef.ts
|
|
1469
|
-
var
|
|
1642
|
+
var Logix8 = __toESM(require("@logixjs/core"), 1);
|
|
1470
1643
|
var getOrCreateWeakMap = (map, key, make) => {
|
|
1471
1644
|
const cached = map.get(key);
|
|
1472
1645
|
if (cached) return cached;
|
|
@@ -1490,7 +1663,7 @@ var resolveImportedModuleRef = (runtime, parentRuntime, module2) => {
|
|
|
1490
1663
|
if (cached) {
|
|
1491
1664
|
return cached;
|
|
1492
1665
|
}
|
|
1493
|
-
const importsScope =
|
|
1666
|
+
const importsScope = Logix8.InternalContracts.getImportsScope(parentRuntime);
|
|
1494
1667
|
const childRuntime = importsScope.get(module2);
|
|
1495
1668
|
if (childRuntime) {
|
|
1496
1669
|
const dispatch = Object.assign(
|
|
@@ -1576,8 +1749,8 @@ var useStableId = () => {
|
|
|
1576
1749
|
|
|
1577
1750
|
// src/internal/hooks/useModule.ts
|
|
1578
1751
|
var isModuleImpl = (handle) => Boolean(handle) && typeof handle === "object" && handle._tag === "ModuleImpl";
|
|
1579
|
-
var isModule = (handle) =>
|
|
1580
|
-
var isModuleDef = (handle) =>
|
|
1752
|
+
var isModule = (handle) => Logix9.Module.hasImpl(handle);
|
|
1753
|
+
var isModuleDef = (handle) => Logix9.Module.is(handle) && handle._kind === "ModuleDef";
|
|
1581
1754
|
function useModule(handle, selectorOrOptions, equalityFn) {
|
|
1582
1755
|
const runtimeBase = useRuntime();
|
|
1583
1756
|
const runtimeContext = import_react7.default.useContext(RuntimeContext);
|
|
@@ -1601,6 +1774,7 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
1601
1774
|
}
|
|
1602
1775
|
}
|
|
1603
1776
|
let runtime;
|
|
1777
|
+
const moduleImplResolveTraceRef = import_react7.default.useRef(void 0);
|
|
1604
1778
|
if (isModuleImpl(normalizedHandle)) {
|
|
1605
1779
|
const cache = import_react7.default.useMemo(
|
|
1606
1780
|
() => getModuleCache(runtimeBase, runtimeContext.reactConfigSnapshot, runtimeContext.configVersion),
|
|
@@ -1629,9 +1803,9 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
1629
1803
|
const key = depsHash ? `${baseKey}:${depsHash}` : baseKey;
|
|
1630
1804
|
const ownerId = moduleId;
|
|
1631
1805
|
const baseFactory = import_react7.default.useMemo(
|
|
1632
|
-
() => (scope) =>
|
|
1633
|
-
|
|
1634
|
-
(context) =>
|
|
1806
|
+
() => (scope) => import_effect8.Layer.buildWithScope(import_effect8.Layer.fresh(normalizedHandle.layer), scope).pipe(
|
|
1807
|
+
import_effect8.Effect.map(
|
|
1808
|
+
(context) => import_effect8.ServiceMap.get(context, normalizedHandle.module)
|
|
1635
1809
|
)
|
|
1636
1810
|
),
|
|
1637
1811
|
[normalizedHandle]
|
|
@@ -1641,26 +1815,56 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
1641
1815
|
return baseFactory;
|
|
1642
1816
|
}
|
|
1643
1817
|
return (scope) => baseFactory(scope).pipe(
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1818
|
+
import_effect8.Effect.timeoutOption(initTimeoutMs),
|
|
1819
|
+
import_effect8.Effect.flatMap(
|
|
1820
|
+
(maybe) => maybe._tag === "Some" ? import_effect8.Effect.succeed(maybe.value) : import_effect8.Effect.die(new Error(`[useModule] Module "${ownerId}" initialization timed out after ${initTimeoutMs}ms`))
|
|
1821
|
+
)
|
|
1648
1822
|
);
|
|
1649
1823
|
}, [baseFactory, suspend, initTimeoutMs, ownerId]);
|
|
1824
|
+
const moduleResolveStartedAt = performance.now();
|
|
1650
1825
|
const moduleRuntime = suspend ? cache.read(key, factory, gcTime, ownerId, {
|
|
1651
1826
|
entrypoint: "react.useModule",
|
|
1652
1827
|
policyMode: runtimeContext.policy.mode,
|
|
1653
|
-
yield: runtimeContext.policy.yield
|
|
1828
|
+
yield: runtimeContext.policy.yield,
|
|
1829
|
+
optimisticSyncBudgetMs: runtimeContext.policy.syncBudgetMs
|
|
1654
1830
|
}) : cache.readSync(key, factory, gcTime, ownerId, {
|
|
1655
1831
|
entrypoint: "react.useModule",
|
|
1656
1832
|
policyMode: runtimeContext.policy.mode,
|
|
1657
1833
|
warnSyncBlockingThresholdMs: 5
|
|
1658
1834
|
});
|
|
1835
|
+
moduleImplResolveTraceRef.current = {
|
|
1836
|
+
moduleId,
|
|
1837
|
+
cacheMode: suspend ? "suspend" : "sync",
|
|
1838
|
+
durationMs: Math.round((performance.now() - moduleResolveStartedAt) * 100) / 100
|
|
1839
|
+
};
|
|
1659
1840
|
import_react7.default.useEffect(() => cache.retain(key), [cache, key]);
|
|
1660
1841
|
runtime = moduleRuntime;
|
|
1661
1842
|
} else {
|
|
1662
1843
|
runtime = useModuleRuntime(normalizedHandle);
|
|
1663
1844
|
}
|
|
1845
|
+
import_react7.default.useEffect(() => {
|
|
1846
|
+
if (!isModuleImpl(normalizedHandle)) {
|
|
1847
|
+
return;
|
|
1848
|
+
}
|
|
1849
|
+
const diagnosticsLevel = readRuntimeDiagnosticsLevel(runtimeBase);
|
|
1850
|
+
if (diagnosticsLevel === "off") {
|
|
1851
|
+
return;
|
|
1852
|
+
}
|
|
1853
|
+
const trace = moduleImplResolveTraceRef.current;
|
|
1854
|
+
if (!trace) {
|
|
1855
|
+
return;
|
|
1856
|
+
}
|
|
1857
|
+
const effect = Logix9.Debug.record({
|
|
1858
|
+
type: "trace:react.moduleImpl.resolve",
|
|
1859
|
+
moduleId: trace.moduleId,
|
|
1860
|
+
instanceId: runtime.instanceId,
|
|
1861
|
+
data: {
|
|
1862
|
+
cacheMode: trace.cacheMode,
|
|
1863
|
+
durationMs: trace.durationMs
|
|
1864
|
+
}
|
|
1865
|
+
});
|
|
1866
|
+
emitRuntimeDebugEventBestEffort(runtimeBase, effect);
|
|
1867
|
+
}, [runtimeBase, runtime, normalizedHandle]);
|
|
1664
1868
|
import_react7.default.useEffect(() => {
|
|
1665
1869
|
if (!isModuleImpl(normalizedHandle)) {
|
|
1666
1870
|
return;
|
|
@@ -1670,22 +1874,22 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
1670
1874
|
if (!label) {
|
|
1671
1875
|
return;
|
|
1672
1876
|
}
|
|
1673
|
-
const effect =
|
|
1877
|
+
const effect = Logix9.Debug.record({
|
|
1674
1878
|
type: "trace:instanceLabel",
|
|
1675
1879
|
moduleId: normalizedHandle.module.id,
|
|
1676
1880
|
instanceId: runtime.instanceId,
|
|
1677
1881
|
data: { label }
|
|
1678
1882
|
});
|
|
1679
|
-
runtimeBase
|
|
1883
|
+
emitRuntimeDebugEventBestEffort(runtimeBase, effect);
|
|
1680
1884
|
}, [runtimeBase, runtime, normalizedHandle, options]);
|
|
1681
1885
|
import_react7.default.useEffect(() => {
|
|
1682
|
-
if (!(0, import_Env.isDevEnv)() && !
|
|
1886
|
+
if (!(0, import_Env.isDevEnv)() && !Logix9.Debug.isDevtoolsEnabled()) {
|
|
1683
1887
|
return;
|
|
1684
1888
|
}
|
|
1685
1889
|
if (!runtime.instanceId) {
|
|
1686
1890
|
return;
|
|
1687
1891
|
}
|
|
1688
|
-
const effect =
|
|
1892
|
+
const effect = Logix9.Debug.record({
|
|
1689
1893
|
type: "trace:react-render",
|
|
1690
1894
|
moduleId: runtime.moduleId,
|
|
1691
1895
|
instanceId: runtime.instanceId,
|
|
@@ -1695,7 +1899,7 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
1695
1899
|
}
|
|
1696
1900
|
});
|
|
1697
1901
|
runtimeBase.runFork(effect);
|
|
1698
|
-
}
|
|
1902
|
+
});
|
|
1699
1903
|
if (selector) {
|
|
1700
1904
|
if (isModuleImpl(normalizedHandle)) {
|
|
1701
1905
|
return useSelector(runtime, selector, equalityFn);
|
|
@@ -1782,12 +1986,12 @@ function useModule(handle, selectorOrOptions, equalityFn) {
|
|
|
1782
1986
|
|
|
1783
1987
|
// src/internal/provider/RuntimeProvider.tsx
|
|
1784
1988
|
var import_react9 = __toESM(require("react"), 1);
|
|
1785
|
-
var
|
|
1786
|
-
var
|
|
1989
|
+
var import_effect10 = require("effect");
|
|
1990
|
+
var Logix11 = __toESM(require("@logixjs/core"), 1);
|
|
1787
1991
|
|
|
1788
1992
|
// src/internal/provider/config.ts
|
|
1789
|
-
var
|
|
1790
|
-
var ReactRuntimeConfigTag = class extends
|
|
1993
|
+
var import_effect9 = require("effect");
|
|
1994
|
+
var ReactRuntimeConfigTag = class extends import_effect9.ServiceMap.Service()("@logixjs/react/RuntimeConfig") {
|
|
1791
1995
|
};
|
|
1792
1996
|
var DEFAULT_CONFIG = {
|
|
1793
1997
|
gcTime: 500,
|
|
@@ -1808,58 +2012,58 @@ var ReactModuleConfigFromEnv = {
|
|
|
1808
2012
|
* - Applies when not explicitly specified in useModule(options.gcTime).
|
|
1809
2013
|
* - Default: 500ms (StrictMode jitter protection).
|
|
1810
2014
|
*/
|
|
1811
|
-
gcTime:
|
|
2015
|
+
gcTime: import_effect9.Config.number("logix.react.gc_time").pipe(import_effect9.Config.withDefault(DEFAULT_CONFIG.gcTime)),
|
|
1812
2016
|
/**
|
|
1813
2017
|
* Default init timeout (ms), only effective when suspend:true.
|
|
1814
2018
|
* - Uses Option<number> to represent "optional config": missing means init timeout is disabled.
|
|
1815
2019
|
* - Callers can map Option.none to undefined.
|
|
1816
2020
|
*/
|
|
1817
|
-
initTimeoutMs:
|
|
2021
|
+
initTimeoutMs: import_effect9.Config.option(import_effect9.Config.number("logix.react.init_timeout_ms")),
|
|
1818
2022
|
/**
|
|
1819
2023
|
* Delay (ms) for low-priority notification scheduling.
|
|
1820
2024
|
* - Roughly "defer to the next frame" cadence (default 16ms).
|
|
1821
2025
|
*/
|
|
1822
|
-
lowPriorityDelayMs:
|
|
1823
|
-
|
|
2026
|
+
lowPriorityDelayMs: import_effect9.Config.number("logix.react.low_priority_delay_ms").pipe(
|
|
2027
|
+
import_effect9.Config.withDefault(DEFAULT_CONFIG.lowPriorityDelayMs ?? 16)
|
|
1824
2028
|
),
|
|
1825
2029
|
/**
|
|
1826
2030
|
* Maximum delay upper bound (ms) for low-priority notification scheduling.
|
|
1827
2031
|
* - Ensures eventual delivery, avoiding indefinite coalescing under extreme high-frequency scenarios.
|
|
1828
2032
|
* - Default 50ms.
|
|
1829
2033
|
*/
|
|
1830
|
-
lowPriorityMaxDelayMs:
|
|
1831
|
-
|
|
2034
|
+
lowPriorityMaxDelayMs: import_effect9.Config.number("logix.react.low_priority_max_delay_ms").pipe(
|
|
2035
|
+
import_effect9.Config.withDefault(DEFAULT_CONFIG.lowPriorityMaxDelayMs ?? 50)
|
|
1832
2036
|
)
|
|
1833
2037
|
};
|
|
1834
2038
|
var ReactModuleConfig = {
|
|
1835
|
-
gcTime:
|
|
1836
|
-
const override = yield*
|
|
1837
|
-
if (
|
|
2039
|
+
gcTime: import_effect9.Effect.gen(function* () {
|
|
2040
|
+
const override = yield* import_effect9.Effect.serviceOption(ReactRuntimeConfigTag);
|
|
2041
|
+
if (import_effect9.Option.isSome(override)) {
|
|
1838
2042
|
return override.value.gcTime;
|
|
1839
2043
|
}
|
|
1840
2044
|
const value = yield* ReactModuleConfigFromEnv.gcTime;
|
|
1841
2045
|
return value;
|
|
1842
2046
|
}),
|
|
1843
|
-
initTimeoutMs:
|
|
1844
|
-
const override = yield*
|
|
1845
|
-
if (
|
|
2047
|
+
initTimeoutMs: import_effect9.Effect.gen(function* () {
|
|
2048
|
+
const override = yield* import_effect9.Effect.serviceOption(ReactRuntimeConfigTag);
|
|
2049
|
+
if (import_effect9.Option.isSome(override)) {
|
|
1846
2050
|
const v = override.value.initTimeoutMs;
|
|
1847
|
-
return v === void 0 ?
|
|
2051
|
+
return v === void 0 ? import_effect9.Option.none() : import_effect9.Option.some(v);
|
|
1848
2052
|
}
|
|
1849
2053
|
const opt = yield* ReactModuleConfigFromEnv.initTimeoutMs;
|
|
1850
2054
|
return opt;
|
|
1851
2055
|
}),
|
|
1852
|
-
lowPriorityDelayMs:
|
|
1853
|
-
const override = yield*
|
|
1854
|
-
if (
|
|
2056
|
+
lowPriorityDelayMs: import_effect9.Effect.gen(function* () {
|
|
2057
|
+
const override = yield* import_effect9.Effect.serviceOption(ReactRuntimeConfigTag);
|
|
2058
|
+
if (import_effect9.Option.isSome(override)) {
|
|
1855
2059
|
return override.value.lowPriorityDelayMs ?? DEFAULT_CONFIG.lowPriorityDelayMs ?? 16;
|
|
1856
2060
|
}
|
|
1857
2061
|
const value = yield* ReactModuleConfigFromEnv.lowPriorityDelayMs;
|
|
1858
2062
|
return value;
|
|
1859
2063
|
}),
|
|
1860
|
-
lowPriorityMaxDelayMs:
|
|
1861
|
-
const override = yield*
|
|
1862
|
-
if (
|
|
2064
|
+
lowPriorityMaxDelayMs: import_effect9.Effect.gen(function* () {
|
|
2065
|
+
const override = yield* import_effect9.Effect.serviceOption(ReactRuntimeConfigTag);
|
|
2066
|
+
if (import_effect9.Option.isSome(override)) {
|
|
1863
2067
|
return override.value.lowPriorityMaxDelayMs ?? DEFAULT_CONFIG.lowPriorityMaxDelayMs ?? 50;
|
|
1864
2068
|
}
|
|
1865
2069
|
const value = yield* ReactModuleConfigFromEnv.lowPriorityMaxDelayMs;
|
|
@@ -1867,9 +2071,9 @@ var ReactModuleConfig = {
|
|
|
1867
2071
|
})
|
|
1868
2072
|
};
|
|
1869
2073
|
var ReactRuntimeConfigSnapshot = {
|
|
1870
|
-
load:
|
|
1871
|
-
const runtimeOverride = yield*
|
|
1872
|
-
if (
|
|
2074
|
+
load: import_effect9.Effect.gen(function* () {
|
|
2075
|
+
const runtimeOverride = yield* import_effect9.Effect.serviceOption(ReactRuntimeConfigTag);
|
|
2076
|
+
if (import_effect9.Option.isSome(runtimeOverride)) {
|
|
1873
2077
|
return {
|
|
1874
2078
|
gcTime: runtimeOverride.value.gcTime,
|
|
1875
2079
|
initTimeoutMs: runtimeOverride.value.initTimeoutMs,
|
|
@@ -1880,10 +2084,10 @@ var ReactRuntimeConfigSnapshot = {
|
|
|
1880
2084
|
}
|
|
1881
2085
|
const envGcTime = yield* ReactModuleConfigFromEnv.gcTime;
|
|
1882
2086
|
const envInitTimeoutOpt = yield* ReactModuleConfigFromEnv.initTimeoutMs;
|
|
1883
|
-
const envInitTimeout =
|
|
2087
|
+
const envInitTimeout = import_effect9.Option.getOrUndefined(envInitTimeoutOpt);
|
|
1884
2088
|
const envLowPriorityDelayMs = yield* ReactModuleConfigFromEnv.lowPriorityDelayMs;
|
|
1885
2089
|
const envLowPriorityMaxDelayMs = yield* ReactModuleConfigFromEnv.lowPriorityMaxDelayMs;
|
|
1886
|
-
const fromConfig = envGcTime !== DEFAULT_CONFIG.gcTime ||
|
|
2090
|
+
const fromConfig = envGcTime !== DEFAULT_CONFIG.gcTime || import_effect9.Option.isSome(envInitTimeoutOpt) || envLowPriorityDelayMs !== (DEFAULT_CONFIG.lowPriorityDelayMs ?? 16) || envLowPriorityMaxDelayMs !== (DEFAULT_CONFIG.lowPriorityMaxDelayMs ?? 50);
|
|
1887
2091
|
if (fromConfig) {
|
|
1888
2092
|
return {
|
|
1889
2093
|
gcTime: envGcTime,
|
|
@@ -1899,7 +2103,7 @@ var ReactRuntimeConfigSnapshot = {
|
|
|
1899
2103
|
|
|
1900
2104
|
// src/internal/provider/fallback.tsx
|
|
1901
2105
|
var import_react8 = require("react");
|
|
1902
|
-
var
|
|
2106
|
+
var Logix10 = __toESM(require("@logixjs/core"), 1);
|
|
1903
2107
|
|
|
1904
2108
|
// src/internal/provider/docs.ts
|
|
1905
2109
|
var LOGIX_DOCS_PREFIX_ENV = "LOGIX_DOCS_PREFIX";
|
|
@@ -2002,11 +2206,11 @@ var resolveRuntimeProviderFallback = (args) => {
|
|
|
2002
2206
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DefaultRuntimeFallback, { phase: args.phase, policyMode: args.policyMode });
|
|
2003
2207
|
};
|
|
2004
2208
|
var recordFallbackDuration = (args) => {
|
|
2005
|
-
if (!(0, import_Env.isDevEnv)() && !
|
|
2209
|
+
if (!(0, import_Env.isDevEnv)() && !Logix10.Debug.isDevtoolsEnabled()) {
|
|
2006
2210
|
return;
|
|
2007
2211
|
}
|
|
2008
2212
|
void args.runtime.runPromise(
|
|
2009
|
-
|
|
2213
|
+
Logix10.Debug.record({
|
|
2010
2214
|
type: "trace:react.fallback.duration",
|
|
2011
2215
|
data: {
|
|
2012
2216
|
phase: args.phase,
|
|
@@ -2085,7 +2289,7 @@ var FallbackProbeEnabled = ({ runtime, phase, policyMode, blockers, children })
|
|
|
2085
2289
|
};
|
|
2086
2290
|
var FallbackProbeNoop = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
|
|
2087
2291
|
var FallbackProbe = (props) => {
|
|
2088
|
-
const enabled = (0, import_Env.isDevEnv)() ||
|
|
2292
|
+
const enabled = (0, import_Env.isDevEnv)() || Logix10.Debug.isDevtoolsEnabled();
|
|
2089
2293
|
const Impl = enabled ? FallbackProbeEnabled : FallbackProbeNoop;
|
|
2090
2294
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Impl, { ...props });
|
|
2091
2295
|
};
|
|
@@ -2168,6 +2372,9 @@ var RuntimeProvider = ({
|
|
|
2168
2372
|
}) => {
|
|
2169
2373
|
const parent = (0, import_react9.useContext)(RuntimeContext);
|
|
2170
2374
|
const baseRuntime = useRuntimeResolution(runtime, parent);
|
|
2375
|
+
const providerStartedAtRef = import_react9.default.useRef(performance.now());
|
|
2376
|
+
const providerReadyAtRef = import_react9.default.useRef(void 0);
|
|
2377
|
+
const didReportProviderGatingRef = import_react9.default.useRef(false);
|
|
2171
2378
|
const resolvedPolicy = (0, import_react9.useMemo)(
|
|
2172
2379
|
() => resolveRuntimeProviderPolicy({
|
|
2173
2380
|
policy,
|
|
@@ -2179,7 +2386,7 @@ var RuntimeProvider = ({
|
|
|
2179
2386
|
onErrorRef.current = onError;
|
|
2180
2387
|
const hasTickServices = (0, import_react9.useMemo)(() => {
|
|
2181
2388
|
try {
|
|
2182
|
-
|
|
2389
|
+
Logix11.InternalContracts.getRuntimeStore(baseRuntime);
|
|
2183
2390
|
return true;
|
|
2184
2391
|
} catch {
|
|
2185
2392
|
return false;
|
|
@@ -2187,7 +2394,7 @@ var RuntimeProvider = ({
|
|
|
2187
2394
|
}, [baseRuntime]);
|
|
2188
2395
|
const { binding: tickBinding } = useLayerBinding(
|
|
2189
2396
|
baseRuntime,
|
|
2190
|
-
|
|
2397
|
+
Logix11.InternalContracts.tickServicesLayer,
|
|
2191
2398
|
!hasTickServices,
|
|
2192
2399
|
onErrorRef.current
|
|
2193
2400
|
);
|
|
@@ -2198,7 +2405,7 @@ var RuntimeProvider = ({
|
|
|
2198
2405
|
record: (event) => {
|
|
2199
2406
|
const handler = onErrorRef.current;
|
|
2200
2407
|
if (!handler) {
|
|
2201
|
-
return
|
|
2408
|
+
return import_effect10.Effect.void;
|
|
2202
2409
|
}
|
|
2203
2410
|
if (event.type === "lifecycle:error") {
|
|
2204
2411
|
return handler(event.cause, {
|
|
@@ -2207,11 +2414,11 @@ var RuntimeProvider = ({
|
|
|
2207
2414
|
moduleId: event.moduleId,
|
|
2208
2415
|
instanceId: event.instanceId,
|
|
2209
2416
|
runtimeLabel: event.runtimeLabel
|
|
2210
|
-
}).pipe(
|
|
2417
|
+
}).pipe(import_effect10.Effect.catchCause(() => import_effect10.Effect.void));
|
|
2211
2418
|
}
|
|
2212
2419
|
if (event.type === "diagnostic" && event.severity === "error") {
|
|
2213
2420
|
return handler(
|
|
2214
|
-
|
|
2421
|
+
import_effect10.Cause.fail({
|
|
2215
2422
|
code: event.code,
|
|
2216
2423
|
message: event.message,
|
|
2217
2424
|
hint: event.hint
|
|
@@ -2226,9 +2433,9 @@ var RuntimeProvider = ({
|
|
|
2226
2433
|
instanceId: event.instanceId,
|
|
2227
2434
|
runtimeLabel: event.runtimeLabel
|
|
2228
2435
|
}
|
|
2229
|
-
).pipe(
|
|
2436
|
+
).pipe(import_effect10.Effect.catchCause(() => import_effect10.Effect.void));
|
|
2230
2437
|
}
|
|
2231
|
-
return
|
|
2438
|
+
return import_effect10.Effect.void;
|
|
2232
2439
|
}
|
|
2233
2440
|
};
|
|
2234
2441
|
return sink;
|
|
@@ -2241,9 +2448,7 @@ var RuntimeProvider = ({
|
|
|
2241
2448
|
return layerBinding.debugSinks;
|
|
2242
2449
|
}
|
|
2243
2450
|
try {
|
|
2244
|
-
return baseRuntime.runSync(
|
|
2245
|
-
import_effect9.FiberRef.get(Logix10.Debug.internal.currentDebugSinks)
|
|
2246
|
-
);
|
|
2451
|
+
return baseRuntime.runSync(import_effect10.Effect.service(Logix11.Debug.internal.currentDebugSinks).pipe(import_effect10.Effect.orDie));
|
|
2247
2452
|
} catch {
|
|
2248
2453
|
return [];
|
|
2249
2454
|
}
|
|
@@ -2301,7 +2506,7 @@ var RuntimeProvider = ({
|
|
|
2301
2506
|
}
|
|
2302
2507
|
didReportSyncConfigSnapshotRef.current = true;
|
|
2303
2508
|
void runtimeWithBindings.runPromise(
|
|
2304
|
-
|
|
2509
|
+
Logix11.Debug.record({
|
|
2305
2510
|
type: "trace:react.runtime.config.snapshot",
|
|
2306
2511
|
data: {
|
|
2307
2512
|
source: configState.snapshot.source,
|
|
@@ -2332,7 +2537,7 @@ var RuntimeProvider = ({
|
|
|
2332
2537
|
};
|
|
2333
2538
|
});
|
|
2334
2539
|
void runtimeWithBindings.runPromise(
|
|
2335
|
-
|
|
2540
|
+
Logix11.Debug.record({
|
|
2336
2541
|
type: "trace:react.runtime.config.snapshot",
|
|
2337
2542
|
data: {
|
|
2338
2543
|
source: snapshot.source,
|
|
@@ -2370,6 +2575,41 @@ var RuntimeProvider = ({
|
|
|
2370
2575
|
const resolveFallback = (phase) => {
|
|
2371
2576
|
return resolveRuntimeProviderFallback({ fallback, phase, policyMode: resolvedPolicy.mode });
|
|
2372
2577
|
};
|
|
2578
|
+
const preloadCache = (0, import_react9.useMemo)(
|
|
2579
|
+
() => getModuleCache(runtimeWithBindings, configState.snapshot, configState.version),
|
|
2580
|
+
[runtimeWithBindings, configState.snapshot, configState.version]
|
|
2581
|
+
);
|
|
2582
|
+
const syncWarmPreloadReady = (0, import_react9.useMemo)(() => {
|
|
2583
|
+
if (resolvedPolicy.mode !== "defer") return false;
|
|
2584
|
+
if (!resolvedPolicy.preload) return true;
|
|
2585
|
+
if (!isLayerReady || !isConfigReady) return false;
|
|
2586
|
+
const handles = resolvedPolicy.preload.handles;
|
|
2587
|
+
if (handles.length === 0) return true;
|
|
2588
|
+
for (const handle of handles) {
|
|
2589
|
+
if (handle?._tag === "ModuleImpl") {
|
|
2590
|
+
const moduleId = handle.module?.id ?? "ModuleImpl";
|
|
2591
|
+
const key2 = resolvedPolicy.preload.keysByModuleId.get(moduleId) ?? getPreloadKeyForModuleId(moduleId);
|
|
2592
|
+
const factory2 = (scope) => import_effect10.Layer.buildWithScope(handle.layer, scope).pipe(
|
|
2593
|
+
import_effect10.Effect.map((context) => import_effect10.ServiceMap.get(context, handle.module))
|
|
2594
|
+
);
|
|
2595
|
+
const value2 = preloadCache.warmSync(key2, factory2, configState.snapshot.gcTime, moduleId, {
|
|
2596
|
+
entrypoint: "react.runtime.preload.sync-warm",
|
|
2597
|
+
policyMode: "defer"
|
|
2598
|
+
});
|
|
2599
|
+
if (!value2) return false;
|
|
2600
|
+
continue;
|
|
2601
|
+
}
|
|
2602
|
+
const tagId = handle.id ?? "ModuleTag";
|
|
2603
|
+
const key = resolvedPolicy.preload.keysByTagId.get(tagId) ?? getPreloadKeyForTagId(tagId);
|
|
2604
|
+
const factory = (scope) => import_effect10.Scope.provide(scope)(import_effect10.Effect.service(handle).pipe(import_effect10.Effect.orDie));
|
|
2605
|
+
const value = preloadCache.warmSync(key, factory, configState.snapshot.gcTime, tagId, {
|
|
2606
|
+
entrypoint: "react.runtime.preload.sync-warm",
|
|
2607
|
+
policyMode: "defer"
|
|
2608
|
+
});
|
|
2609
|
+
if (!value) return false;
|
|
2610
|
+
}
|
|
2611
|
+
return true;
|
|
2612
|
+
}, [resolvedPolicy, isLayerReady, isConfigReady, preloadCache, configState.snapshot.gcTime]);
|
|
2373
2613
|
const [deferReady, setDeferReady] = (0, import_react9.useState)(false);
|
|
2374
2614
|
(0, import_react9.useEffect)(() => {
|
|
2375
2615
|
if (resolvedPolicy.mode !== "defer") {
|
|
@@ -2383,6 +2623,10 @@ var RuntimeProvider = ({
|
|
|
2383
2623
|
if (resolvedPolicy.mode !== "defer") {
|
|
2384
2624
|
return;
|
|
2385
2625
|
}
|
|
2626
|
+
if (syncWarmPreloadReady) {
|
|
2627
|
+
setDeferReady(true);
|
|
2628
|
+
return;
|
|
2629
|
+
}
|
|
2386
2630
|
setDeferReady(false);
|
|
2387
2631
|
if (!resolvedPolicy.preload) {
|
|
2388
2632
|
setDeferReady(true);
|
|
@@ -2392,7 +2636,7 @@ var RuntimeProvider = ({
|
|
|
2392
2636
|
return;
|
|
2393
2637
|
}
|
|
2394
2638
|
let cancelled = false;
|
|
2395
|
-
const cache =
|
|
2639
|
+
const cache = preloadCache;
|
|
2396
2640
|
const preloadHandles = resolvedPolicy.preload.handles;
|
|
2397
2641
|
if (preloadHandles.length === 0) {
|
|
2398
2642
|
setDeferReady(true);
|
|
@@ -2409,20 +2653,21 @@ var RuntimeProvider = ({
|
|
|
2409
2653
|
if (handle?._tag === "ModuleImpl") {
|
|
2410
2654
|
const moduleId = handle.module?.id ?? "ModuleImpl";
|
|
2411
2655
|
const key2 = resolvedPolicy.preload.keysByModuleId.get(moduleId) ?? getPreloadKeyForModuleId(moduleId);
|
|
2412
|
-
const factory2 = (scope) =>
|
|
2413
|
-
|
|
2656
|
+
const factory2 = (scope) => import_effect10.Layer.buildWithScope(handle.layer, scope).pipe(
|
|
2657
|
+
import_effect10.Effect.map((context) => import_effect10.ServiceMap.get(context, handle.module))
|
|
2414
2658
|
);
|
|
2415
2659
|
const op2 = cache.preload(key2, factory2, {
|
|
2416
2660
|
ownerId: moduleId,
|
|
2417
2661
|
yield: resolvedPolicy.preload.yield,
|
|
2418
2662
|
entrypoint: "react.runtime.preload",
|
|
2419
|
-
policyMode: "defer"
|
|
2663
|
+
policyMode: "defer",
|
|
2664
|
+
optimisticSyncBudgetMs: resolvedPolicy.syncBudgetMs
|
|
2420
2665
|
});
|
|
2421
2666
|
allCancels.add(op2.cancel);
|
|
2422
2667
|
await op2.promise;
|
|
2423
2668
|
const durationMs2 = performance.now() - startedAt;
|
|
2424
2669
|
void runtimeWithBindings.runPromise(
|
|
2425
|
-
|
|
2670
|
+
Logix11.Debug.record({
|
|
2426
2671
|
type: "trace:react.module.preload",
|
|
2427
2672
|
moduleId,
|
|
2428
2673
|
data: {
|
|
@@ -2441,20 +2686,19 @@ var RuntimeProvider = ({
|
|
|
2441
2686
|
}
|
|
2442
2687
|
const tagId = handle.id ?? "ModuleTag";
|
|
2443
2688
|
const key = resolvedPolicy.preload.keysByTagId.get(tagId) ?? getPreloadKeyForTagId(tagId);
|
|
2444
|
-
const factory = (scope) => handle.pipe(
|
|
2445
|
-
import_effect9.Scope.extend(scope)
|
|
2446
|
-
);
|
|
2689
|
+
const factory = (scope) => import_effect10.Scope.provide(scope)(import_effect10.Effect.service(handle).pipe(import_effect10.Effect.orDie));
|
|
2447
2690
|
const op = cache.preload(key, factory, {
|
|
2448
2691
|
ownerId: tagId,
|
|
2449
2692
|
yield: resolvedPolicy.preload.yield,
|
|
2450
2693
|
entrypoint: "react.runtime.preload",
|
|
2451
|
-
policyMode: "defer"
|
|
2694
|
+
policyMode: "defer",
|
|
2695
|
+
optimisticSyncBudgetMs: resolvedPolicy.syncBudgetMs
|
|
2452
2696
|
});
|
|
2453
2697
|
allCancels.add(op.cancel);
|
|
2454
2698
|
await op.promise;
|
|
2455
2699
|
const durationMs = performance.now() - startedAt;
|
|
2456
2700
|
void runtimeWithBindings.runPromise(
|
|
2457
|
-
|
|
2701
|
+
Logix11.Debug.record({
|
|
2458
2702
|
type: "trace:react.module.preload",
|
|
2459
2703
|
data: {
|
|
2460
2704
|
mode: "defer",
|
|
@@ -2486,7 +2730,7 @@ var RuntimeProvider = ({
|
|
|
2486
2730
|
if (cancelled) return;
|
|
2487
2731
|
if (onErrorRef.current) {
|
|
2488
2732
|
runtimeWithBindings.runFork(
|
|
2489
|
-
onErrorRef.current(
|
|
2733
|
+
onErrorRef.current(import_effect10.Cause.die(error), { source: "provider", phase: "provider.layer.build" }).pipe(import_effect10.Effect.catchCause(() => import_effect10.Effect.void))
|
|
2490
2734
|
);
|
|
2491
2735
|
}
|
|
2492
2736
|
setDeferReady(true);
|
|
@@ -2519,13 +2763,54 @@ var RuntimeProvider = ({
|
|
|
2519
2763
|
release();
|
|
2520
2764
|
};
|
|
2521
2765
|
}, [resolvedPolicy.mode, deferReady]);
|
|
2522
|
-
const isReady = isTickServicesReady && isLayerReady && isConfigReady && (resolvedPolicy.mode !== "defer" || deferReady);
|
|
2766
|
+
const isReady = isTickServicesReady && isLayerReady && isConfigReady && (resolvedPolicy.mode !== "defer" || deferReady || syncWarmPreloadReady);
|
|
2767
|
+
if (isReady && providerReadyAtRef.current === void 0) {
|
|
2768
|
+
providerReadyAtRef.current = performance.now();
|
|
2769
|
+
}
|
|
2770
|
+
(0, import_react9.useEffect)(() => {
|
|
2771
|
+
if (!isReady) {
|
|
2772
|
+
return;
|
|
2773
|
+
}
|
|
2774
|
+
if (didReportProviderGatingRef.current) {
|
|
2775
|
+
return;
|
|
2776
|
+
}
|
|
2777
|
+
let diagnosticsLevel = "off";
|
|
2778
|
+
try {
|
|
2779
|
+
diagnosticsLevel = runtimeWithBindings.runSync(
|
|
2780
|
+
import_effect10.Effect.service(Logix11.Debug.internal.currentDiagnosticsLevel).pipe(import_effect10.Effect.orDie)
|
|
2781
|
+
);
|
|
2782
|
+
} catch {
|
|
2783
|
+
diagnosticsLevel = (0, import_Env.isDevEnv)() ? "light" : "off";
|
|
2784
|
+
}
|
|
2785
|
+
if (diagnosticsLevel === "off") {
|
|
2786
|
+
return;
|
|
2787
|
+
}
|
|
2788
|
+
didReportProviderGatingRef.current = true;
|
|
2789
|
+
const readyAt = providerReadyAtRef.current ?? performance.now();
|
|
2790
|
+
const durationMs = Math.round((readyAt - providerStartedAtRef.current) * 100) / 100;
|
|
2791
|
+
const effectDelayMs = Math.round((performance.now() - readyAt) * 100) / 100;
|
|
2792
|
+
void runtimeWithBindings.runPromise(
|
|
2793
|
+
Logix11.Debug.record({
|
|
2794
|
+
type: "trace:react.provider.gating",
|
|
2795
|
+
data: {
|
|
2796
|
+
event: "ready",
|
|
2797
|
+
policyMode: resolvedPolicy.mode,
|
|
2798
|
+
durationMs,
|
|
2799
|
+
effectDelayMs,
|
|
2800
|
+
configLoadMode: configState.loadMode,
|
|
2801
|
+
syncOverBudget: Boolean(configState.syncOverBudget),
|
|
2802
|
+
syncDurationMs: configState.syncDurationMs !== void 0 ? Math.round(configState.syncDurationMs * 100) / 100 : void 0
|
|
2803
|
+
}
|
|
2804
|
+
})
|
|
2805
|
+
).catch(() => {
|
|
2806
|
+
});
|
|
2807
|
+
}, [configState.loadMode, configState.syncDurationMs, configState.syncOverBudget, isReady, resolvedPolicy.mode, runtimeWithBindings]);
|
|
2523
2808
|
if (!isReady) {
|
|
2524
2809
|
const blockersList = [
|
|
2525
2810
|
isTickServicesReady ? null : "tick",
|
|
2526
2811
|
isLayerReady ? null : "layer",
|
|
2527
2812
|
isConfigReady ? null : "config",
|
|
2528
|
-
resolvedPolicy.mode !== "defer" || deferReady ? null : "preload"
|
|
2813
|
+
resolvedPolicy.mode !== "defer" || deferReady || syncWarmPreloadReady ? null : "preload"
|
|
2529
2814
|
].filter((x) => x !== null);
|
|
2530
2815
|
const blockers = blockersList.length > 0 ? blockersList.join("+") : void 0;
|
|
2531
2816
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
@@ -2560,14 +2845,16 @@ var useRuntimeResolution = (runtimeProp, parent) => {
|
|
|
2560
2845
|
|
|
2561
2846
|
// src/ModuleScope.ts
|
|
2562
2847
|
var makeModuleScope = (handle, defaults) => {
|
|
2563
|
-
const
|
|
2848
|
+
const Context = import_react10.default.createContext(null);
|
|
2564
2849
|
const toUseModuleOptions = (options) => {
|
|
2565
2850
|
const { scopeId, ...rest } = options;
|
|
2566
2851
|
return scopeId != null ? { ...rest, key: scopeId } : rest;
|
|
2567
2852
|
};
|
|
2568
2853
|
const getRegistryOrThrow = (runtime, where) => {
|
|
2569
2854
|
try {
|
|
2570
|
-
const registry = runtime.runSync(
|
|
2855
|
+
const registry = runtime.runSync(
|
|
2856
|
+
import_effect11.Effect.service(Logix12.ScopeRegistry.ScopeRegistryTag).pipe(import_effect11.Effect.orDie)
|
|
2857
|
+
);
|
|
2571
2858
|
if (!registry) {
|
|
2572
2859
|
throw new Error("ScopeRegistry service is undefined");
|
|
2573
2860
|
}
|
|
@@ -2578,7 +2865,7 @@ var makeModuleScope = (handle, defaults) => {
|
|
|
2578
2865
|
);
|
|
2579
2866
|
}
|
|
2580
2867
|
};
|
|
2581
|
-
const moduleToken =
|
|
2868
|
+
const moduleToken = Logix12.Module.hasImpl(handle) ? handle.tag : handle.module;
|
|
2582
2869
|
const Provider = ({ children, options }) => {
|
|
2583
2870
|
const runtime = useRuntime();
|
|
2584
2871
|
const merged = defaults || options ? { ...defaults ?? {}, ...options ?? {} } : void 0;
|
|
@@ -2587,17 +2874,17 @@ var makeModuleScope = (handle, defaults) => {
|
|
|
2587
2874
|
import_react10.default.useEffect(() => {
|
|
2588
2875
|
if (!scopeId) return;
|
|
2589
2876
|
const registry = getRegistryOrThrow(runtime, "[ModuleScope]");
|
|
2590
|
-
const leaseRuntime = registry.register(scopeId,
|
|
2877
|
+
const leaseRuntime = registry.register(scopeId, Logix12.ScopeRegistry.ScopedRuntimeTag, runtime);
|
|
2591
2878
|
const leaseModule = registry.register(scopeId, moduleToken, ref.runtime);
|
|
2592
2879
|
return () => {
|
|
2593
2880
|
leaseModule.release();
|
|
2594
2881
|
leaseRuntime.release();
|
|
2595
2882
|
};
|
|
2596
2883
|
}, [runtime, scopeId, ref.runtime]);
|
|
2597
|
-
return import_react10.default.createElement(
|
|
2884
|
+
return import_react10.default.createElement(Context.Provider, { value: ref }, children);
|
|
2598
2885
|
};
|
|
2599
2886
|
const use = () => {
|
|
2600
|
-
const ref = import_react10.default.useContext(
|
|
2887
|
+
const ref = import_react10.default.useContext(Context);
|
|
2601
2888
|
if (!ref) {
|
|
2602
2889
|
throw new Error("[ModuleScope] Provider not found");
|
|
2603
2890
|
}
|
|
@@ -2610,7 +2897,7 @@ var makeModuleScope = (handle, defaults) => {
|
|
|
2610
2897
|
const Bridge = ({ scopeId, children }) => {
|
|
2611
2898
|
const runtime = useRuntime();
|
|
2612
2899
|
const registry = getRegistryOrThrow(runtime, "[ModuleScope.Bridge]");
|
|
2613
|
-
const scopedRuntime = registry.get(scopeId,
|
|
2900
|
+
const scopedRuntime = registry.get(scopeId, Logix12.ScopeRegistry.ScopedRuntimeTag);
|
|
2614
2901
|
const moduleRuntime = registry.get(scopeId, moduleToken);
|
|
2615
2902
|
if (!scopedRuntime || !moduleRuntime) {
|
|
2616
2903
|
throw new Error(
|
|
@@ -2620,18 +2907,18 @@ var makeModuleScope = (handle, defaults) => {
|
|
|
2620
2907
|
return import_react10.default.createElement(
|
|
2621
2908
|
RuntimeProvider,
|
|
2622
2909
|
{ runtime: scopedRuntime },
|
|
2623
|
-
import_react10.default.createElement(BridgeInner, { moduleRuntime, Context
|
|
2910
|
+
import_react10.default.createElement(BridgeInner, { moduleRuntime, Context }, children)
|
|
2624
2911
|
);
|
|
2625
2912
|
};
|
|
2626
2913
|
const BridgeInner = ({
|
|
2627
2914
|
moduleRuntime,
|
|
2628
|
-
Context:
|
|
2915
|
+
Context: Context2,
|
|
2629
2916
|
children
|
|
2630
2917
|
}) => {
|
|
2631
2918
|
const ref = useModule(moduleRuntime);
|
|
2632
|
-
return import_react10.default.createElement(
|
|
2919
|
+
return import_react10.default.createElement(Context2.Provider, { value: ref }, children);
|
|
2633
2920
|
};
|
|
2634
|
-
return { Provider, use, useImported, Context
|
|
2921
|
+
return { Provider, use, useImported, Context, Bridge };
|
|
2635
2922
|
};
|
|
2636
2923
|
var ModuleScope = {
|
|
2637
2924
|
make: makeModuleScope
|