@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.
Files changed (36) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +1 -1
  3. package/dist/Hooks.cjs +462 -325
  4. package/dist/Hooks.d.cts +6 -6
  5. package/dist/Hooks.d.ts +6 -6
  6. package/dist/Hooks.js +3 -3
  7. package/dist/{ModuleRef-wZSQ3Wwo.d.cts → ModuleRef-gZmL6Zvb.d.cts} +8 -3
  8. package/dist/{ModuleRef-wZSQ3Wwo.d.ts → ModuleRef-gZmL6Zvb.d.ts} +8 -3
  9. package/dist/ModuleScope.cjs +596 -362
  10. package/dist/ModuleScope.d.cts +4 -4
  11. package/dist/ModuleScope.d.ts +4 -4
  12. package/dist/ModuleScope.js +4 -4
  13. package/dist/Platform.cjs +1 -4
  14. package/dist/Platform.d.cts +1 -2
  15. package/dist/Platform.d.ts +1 -2
  16. package/dist/Platform.js +1 -1
  17. package/dist/ReactPlatform.cjs +543 -309
  18. package/dist/ReactPlatform.d.cts +2 -2
  19. package/dist/ReactPlatform.d.ts +2 -2
  20. package/dist/ReactPlatform.js +5 -5
  21. package/dist/RuntimeProvider.cjs +276 -56
  22. package/dist/RuntimeProvider.js +2 -2
  23. package/dist/{chunk-PYWHL7TA.js → chunk-6NLXTHZ7.js} +8 -8
  24. package/dist/{chunk-UFFCJGSZ.js → chunk-E3ZXST5F.js} +256 -240
  25. package/dist/{chunk-4G7H66OY.js → chunk-KYWW4KMQ.js} +3 -3
  26. package/dist/{chunk-2WFULYPJ.js → chunk-L7KTYBXN.js} +155 -32
  27. package/dist/{chunk-ZANGOPUQ.js → chunk-NKYV44OG.js} +1 -4
  28. package/dist/{chunk-G5MRIFKK.js → chunk-SDQF3WRT.js} +7 -7
  29. package/dist/{chunk-JXAJTWSZ.js → chunk-XSGDBJXD.js} +122 -25
  30. package/dist/index.cjs +564 -333
  31. package/dist/index.d.cts +2 -2
  32. package/dist/index.d.ts +2 -2
  33. package/dist/index.js +7 -7
  34. package/dist/{useDispatch-BnzYVkRE.d.ts → useDispatch-CiDimIYZ.d.ts} +13 -15
  35. package/dist/{useDispatch-CnO5-66H.d.cts → useDispatch-DiwQQAfC.d.cts} +13 -15
  36. package/package.json +12 -4
@@ -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 Logix10 = __toESM(require("@logixjs/core"), 1);
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 Logix7 = __toESM(require("@logixjs/core"), 1);
42
+ var Logix9 = __toESM(require("@logixjs/core"), 1);
42
43
  var import_effect8 = require("effect");
43
44
 
44
45
  // src/internal/hooks/useModuleRuntime.ts
45
46
  var import_react4 = require("react");
46
- var Logix4 = __toESM(require("@logixjs/core"), 1);
47
- var import_effect5 = require("effect");
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.mapInputContext(
132
- import_effect.Scope.extend(effect, newScope),
133
- (parent) => import_effect.Context.merge(parent, context)
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.FiberRef.get(Logix.Debug.internal.currentDebugSinks)
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.catchAllCause(() => import_effect.Effect.void)
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
- // First inherit Provider scopes via scope.extend (preserving FiberRef/Logger changes),
223
- // then merge Context via mapInputContext (inner overrides outer).
224
- contexts.reduceRight(
225
- (acc, ctx) => import_effect.Effect.mapInputContext(
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.locally(import_effect.FiberRef.currentLoggers, last)(result);
232
+ result = import_effect.Effect.provideService(result, import_effect.Logger.CurrentLoggers, last);
242
233
  }
243
234
  if (logLevel) {
244
- result = import_effect.Effect.locally(import_effect.FiberRef.currentLogLevel, logLevel)(result);
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.locally(
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 Logix3 = __toESM(require("@logixjs/core"), 1);
431
- var import_effect4 = require("effect");
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 Logix2 = __toESM(require("@logixjs/core"), 1);
435
- var import_effect3 = require("effect");
436
- var PerfCounterStateSchema = import_effect3.Schema.Struct({
437
- value: import_effect3.Schema.Number
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: import_effect3.Schema.Void
442
+ inc: import_effect4.Schema.Void
441
443
  };
442
- var PerfListScopeRowSchema = import_effect3.Schema.Struct({
443
- id: import_effect3.Schema.String,
444
- warehouseId: import_effect3.Schema.String
444
+ var PerfListScopeRowSchema = import_effect4.Schema.Struct({
445
+ id: import_effect4.Schema.String,
446
+ warehouseId: import_effect4.Schema.String
445
447
  });
446
- var PerfListScopeStateSchema = import_effect3.Schema.Struct({
447
- items: import_effect3.Schema.Array(PerfListScopeRowSchema),
448
- digest: import_effect3.Schema.String,
449
- errors: import_effect3.Schema.Any
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 = import_effect4.Option.getOrUndefined(import_effect4.Cause.failureOption(cause));
546
+ const failure = import_effect5.Option.getOrUndefined(import_effect5.Cause.findErrorOption(cause));
545
547
  if (failure !== void 0) return failure;
546
- const defect = import_effect4.Option.getOrUndefined(import_effect4.Cause.dieOption(cause));
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 import_effect4.Effect.void;
555
+ return import_effect5.Effect.void;
554
556
  case "microtask":
555
- return import_effect4.Effect.yieldNow();
557
+ return import_effect5.Effect.yieldNow;
556
558
  case "macrotask":
557
- return import_effect4.Effect.promise(
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(import_effect4.Scope.close(current.scope, import_effect4.Exit.void)).catch((error) => {
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
- Logix3.Debug.record({
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 = import_effect4.Effect.runSync(import_effect4.Scope.make());
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(import_effect4.Effect.zipRight(factory(scope)));
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(import_effect4.Fiber.await(fiber)).then((exit) => {
667
- if (import_effect4.Exit.isSuccess(exit)) return exit.value;
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)() || Logix3.Debug.isDevtoolsEnabled()) {
738
+ if ((0, import_Env.isDevEnv)() || Logix4.Debug.isDevtoolsEnabled()) {
676
739
  void this.runtime.runPromise(
677
- Logix3.Debug.record({
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
- Logix3.Debug.record({
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(import_effect4.Scope.close(scope, import_effect4.Exit.fail(error))).catch((closeError) => {
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(import_effect4.Scope.make());
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)() || Logix3.Debug.isDevtoolsEnabled()) {
867
+ if ((0, import_Env.isDevEnv)() || Logix4.Debug.isDevtoolsEnabled()) {
805
868
  void this.runtime.runPromise(
806
- Logix3.Debug.record({
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
- Logix3.Debug.record({
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(import_effect4.Scope.close(scope, import_effect4.Exit.fail(error))).catch((closeError) => {
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 = import_effect4.Effect.runSync(import_effect4.Scope.make());
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(import_effect4.Effect.zipRight(factory(scope)));
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(import_effect4.Fiber.await(fiber)).then((exit) => {
907
- if (import_effect4.Exit.isSuccess(exit)) return exit.value;
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(import_effect4.Scope.close(scope, import_effect4.Exit.fail(error))).catch((closeError) => {
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(import_effect4.Fiber.interrupt(running));
1103
+ this.runtime.runFork(import_effect5.Fiber.interrupt(running));
966
1104
  }
967
- void this.runtime.runPromise(import_effect4.Scope.close(entry.scope, import_effect4.Exit.void)).catch((closeError) => {
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(import_effect4.Scope.close(entry.scope, import_effect4.Exit.void)).catch((error) => {
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 factory = (scope) => tag.pipe(import_effect5.Scope.extend(scope));
1090
- return mode === "suspend" ? cache.read(key, factory, void 0, tokenId, {
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
- if (!(0, import_Env.isDevEnv)() && !Logix4.Debug.isDevtoolsEnabled()) {
1251
+ const diagnosticsLevel = readRuntimeDiagnosticsLevel(runtime);
1252
+ if (diagnosticsLevel === "off") {
1105
1253
  return;
1106
1254
  }
1107
1255
  const tokenId = handle?.id ?? "ModuleTag";
1108
- const effect = Logix4.Debug.record({
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.runFork(effect);
1269
+ emitRuntimeDebugEventBestEffort(runtime, effect);
1119
1270
  }, [runtime, runtimeContext.policy, resolved, handle, isTagHandle]);
1120
1271
  return resolved;
1121
1272
  }
@@ -1123,55 +1274,73 @@ 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 Logix5 = __toESM(require("@logixjs/core"), 1);
1277
+ var Logix7 = __toESM(require("@logixjs/core"), 1);
1127
1278
 
1128
- // src/internal/store/ModuleRuntimeExternalStore.ts
1129
- var import_effect6 = require("effect");
1279
+ // src/internal/store/RuntimeExternalStore.ts
1280
+ var Logix6 = __toESM(require("@logixjs/core"), 1);
1281
+ var import_effect7 = require("effect");
1130
1282
  var storesByRuntime = /* @__PURE__ */ new WeakMap();
1131
1283
  var getStoreMapForRuntime = (runtime) => {
1132
1284
  const cached = storesByRuntime.get(runtime);
1133
1285
  if (cached) return cached;
1134
- const next = /* @__PURE__ */ new WeakMap();
1286
+ const next = /* @__PURE__ */ new Map();
1135
1287
  storesByRuntime.set(runtime, next);
1136
1288
  return next;
1137
1289
  };
1138
- var getModuleRuntimeExternalStore = (runtime, moduleRuntime, options) => {
1139
- const byModule = getStoreMapForRuntime(runtime);
1140
- const cached = byModule.get(moduleRuntime);
1290
+ var makeModuleInstanceKey = (moduleId, instanceId) => `${moduleId}::${instanceId}`;
1291
+ var makeReadQueryTopicKey = (moduleInstanceKey, selectorId) => `${moduleInstanceKey}::rq:${selectorId}`;
1292
+ var getRuntimeStore = (runtime) => Logix6.InternalContracts.getRuntimeStore(runtime);
1293
+ var getHostScheduler = (runtime) => Logix6.InternalContracts.getHostScheduler(runtime);
1294
+ var getOrCreateStore = (runtime, topicKey, make) => {
1295
+ const map = getStoreMapForRuntime(runtime);
1296
+ const cached = map.get(topicKey);
1141
1297
  if (cached) {
1142
1298
  return cached;
1143
1299
  }
1144
- let currentState;
1300
+ const created = make();
1301
+ map.set(topicKey, created);
1302
+ return created;
1303
+ };
1304
+ var removeStore = (runtime, topicKey) => {
1305
+ const map = storesByRuntime.get(runtime);
1306
+ if (!map) return;
1307
+ map.delete(topicKey);
1308
+ };
1309
+ var makeTopicExternalStore = (args) => {
1310
+ const { runtime, runtimeStore, topicKey } = args;
1311
+ const hostScheduler = getHostScheduler(runtime);
1312
+ let currentVersion;
1313
+ let hasSnapshot = false;
1314
+ let currentSnapshot;
1145
1315
  const listeners = /* @__PURE__ */ new Set();
1146
- const lowPriorityDelayMs = options?.lowPriorityDelayMs ?? 16;
1147
- const lowPriorityMaxDelayMs = options?.lowPriorityMaxDelayMs ?? 50;
1316
+ let unsubscribeFromRuntimeStore;
1317
+ let teardownScheduled = false;
1318
+ let teardownToken = 0;
1319
+ const lowPriorityDelayMs = args.options?.lowPriorityDelayMs ?? 16;
1320
+ const lowPriorityMaxDelayMs = args.options?.lowPriorityMaxDelayMs ?? 50;
1148
1321
  let notifyScheduled = false;
1149
1322
  let notifyScheduledLow = false;
1150
- let lowTimeoutId;
1151
- let lowMaxTimeoutId;
1152
- let lowRafId;
1323
+ let lowCancelDelay;
1324
+ let lowCancelMaxDelay;
1325
+ let lowCancelRaf;
1153
1326
  const cancelLow = () => {
1154
1327
  if (!notifyScheduledLow) return;
1155
1328
  notifyScheduledLow = false;
1156
- if (lowTimeoutId != null) {
1157
- clearTimeout(lowTimeoutId);
1158
- lowTimeoutId = void 0;
1159
- }
1160
- if (lowMaxTimeoutId != null) {
1161
- clearTimeout(lowMaxTimeoutId);
1162
- lowMaxTimeoutId = void 0;
1163
- }
1164
- const cancel = globalThis.cancelAnimationFrame;
1165
- if (cancel && typeof lowRafId === "number") {
1166
- cancel(lowRafId);
1167
- lowRafId = void 0;
1168
- }
1329
+ lowCancelDelay?.();
1330
+ lowCancelDelay = void 0;
1331
+ lowCancelMaxDelay?.();
1332
+ lowCancelMaxDelay = void 0;
1333
+ lowCancelRaf?.();
1334
+ lowCancelRaf = void 0;
1169
1335
  };
1170
1336
  const flushNotify = () => {
1171
1337
  notifyScheduled = false;
1172
1338
  cancelLow();
1173
1339
  for (const listener of listeners) {
1174
- listener();
1340
+ try {
1341
+ listener();
1342
+ } catch {
1343
+ }
1175
1344
  }
1176
1345
  };
1177
1346
  const scheduleNotify = (priority) => {
@@ -1183,72 +1352,155 @@ var getModuleRuntimeExternalStore = (runtime, moduleRuntime, options) => {
1183
1352
  if (!notifyScheduledLow) return;
1184
1353
  flushNotify();
1185
1354
  };
1186
- const raf = globalThis.requestAnimationFrame;
1187
- if (raf) {
1188
- lowRafId = raf(flush);
1355
+ const scheduleRaf = () => {
1356
+ if (!notifyScheduledLow) return;
1357
+ lowCancelRaf = hostScheduler.scheduleAnimationFrame(flush);
1358
+ };
1359
+ if (lowPriorityDelayMs <= 0) {
1360
+ scheduleRaf();
1189
1361
  } else {
1190
- lowTimeoutId = setTimeout(flush, lowPriorityDelayMs);
1362
+ lowCancelDelay = hostScheduler.scheduleTimeout(lowPriorityDelayMs, scheduleRaf);
1191
1363
  }
1192
- lowMaxTimeoutId = setTimeout(flush, lowPriorityMaxDelayMs);
1364
+ lowCancelMaxDelay = hostScheduler.scheduleTimeout(lowPriorityMaxDelayMs, flush);
1193
1365
  return;
1194
1366
  }
1195
1367
  cancelLow();
1196
1368
  if (notifyScheduled) return;
1197
1369
  notifyScheduled = true;
1198
- queueMicrotask(flushNotify);
1370
+ hostScheduler.scheduleMicrotask(flushNotify);
1371
+ };
1372
+ const onRuntimeStoreChange = () => {
1373
+ try {
1374
+ scheduleNotify(runtimeStore.getTopicPriority(topicKey));
1375
+ } catch {
1376
+ }
1199
1377
  };
1200
- let fiber;
1201
1378
  const ensureSubscription = () => {
1202
- if (fiber) return;
1203
- fiber = runtime.runFork(
1204
- import_effect6.Stream.runForEach(
1205
- moduleRuntime.changesWithMeta((state) => state),
1206
- ({ value: state, meta }) => import_effect6.Effect.sync(() => {
1207
- currentState = state;
1208
- scheduleNotify(meta.priority);
1209
- })
1210
- )
1211
- );
1379
+ if (unsubscribeFromRuntimeStore) return;
1380
+ unsubscribeFromRuntimeStore = runtimeStore.subscribeTopic(topicKey, onRuntimeStoreChange);
1212
1381
  };
1213
1382
  const refreshSnapshotIfStale = () => {
1214
- if (currentState === void 0) {
1215
- return;
1216
- }
1383
+ if (!hasSnapshot) return;
1217
1384
  try {
1218
- const latest = runtime.runSync(moduleRuntime.getState);
1219
- if (currentState === void 0 || !Object.is(currentState, latest)) {
1220
- currentState = latest;
1221
- scheduleNotify("normal");
1385
+ const version = runtimeStore.getTopicVersion(topicKey);
1386
+ if (currentVersion !== version) {
1387
+ scheduleNotify(runtimeStore.getTopicPriority(topicKey));
1222
1388
  }
1223
1389
  } catch {
1224
1390
  }
1225
1391
  };
1226
1392
  const getSnapshot = () => {
1227
- if (currentState !== void 0) return currentState;
1228
- currentState = runtime.runSync(moduleRuntime.getState);
1229
- return currentState;
1393
+ const version = runtimeStore.getTopicVersion(topicKey);
1394
+ if (hasSnapshot && currentVersion === version) {
1395
+ return currentSnapshot;
1396
+ }
1397
+ const next = args.readSnapshot();
1398
+ currentVersion = version;
1399
+ hasSnapshot = true;
1400
+ currentSnapshot = next;
1401
+ return next;
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
+ });
1230
1432
  };
1231
1433
  const subscribe = (listener) => {
1434
+ cancelScheduledTeardown();
1435
+ const isFirst = listeners.size === 0;
1232
1436
  listeners.add(listener);
1233
1437
  ensureSubscription();
1234
1438
  refreshSnapshotIfStale();
1439
+ if (isFirst) {
1440
+ try {
1441
+ args.onFirstListener?.();
1442
+ } catch {
1443
+ }
1444
+ }
1235
1445
  return () => {
1236
1446
  listeners.delete(listener);
1237
1447
  if (listeners.size > 0) return;
1238
- const running = fiber;
1239
- if (!running) return;
1240
- fiber = void 0;
1241
- cancelLow();
1242
- runtime.runFork(import_effect6.Fiber.interrupt(running));
1448
+ scheduleTeardown();
1243
1449
  };
1244
1450
  };
1245
- const store = { getSnapshot, subscribe };
1246
- byModule.set(moduleRuntime, store);
1247
- return store;
1451
+ return { getSnapshot, getServerSnapshot: getSnapshot, subscribe };
1452
+ };
1453
+ var getRuntimeModuleExternalStore = (runtime, moduleRuntime, options) => {
1454
+ const moduleInstanceKey = makeModuleInstanceKey(moduleRuntime.moduleId, moduleRuntime.instanceId);
1455
+ const runtimeStore = getRuntimeStore(runtime);
1456
+ return getOrCreateStore(
1457
+ runtime,
1458
+ moduleInstanceKey,
1459
+ () => makeTopicExternalStore({
1460
+ runtime,
1461
+ runtimeStore,
1462
+ topicKey: moduleInstanceKey,
1463
+ readSnapshot: () => {
1464
+ const state = runtimeStore.getModuleState(moduleInstanceKey);
1465
+ if (state !== void 0) return state;
1466
+ return runtime.runSync(moduleRuntime.getState);
1467
+ },
1468
+ options
1469
+ })
1470
+ );
1471
+ };
1472
+ var getRuntimeReadQueryExternalStore = (runtime, moduleRuntime, selectorReadQuery, options) => {
1473
+ const moduleInstanceKey = makeModuleInstanceKey(moduleRuntime.moduleId, moduleRuntime.instanceId);
1474
+ const topicKey = makeReadQueryTopicKey(moduleInstanceKey, selectorReadQuery.selectorId);
1475
+ const runtimeStore = getRuntimeStore(runtime);
1476
+ let readQueryDrainFiber;
1477
+ return getOrCreateStore(
1478
+ runtime,
1479
+ topicKey,
1480
+ () => makeTopicExternalStore({
1481
+ runtime,
1482
+ runtimeStore,
1483
+ topicKey,
1484
+ readSnapshot: () => {
1485
+ const state = runtimeStore.getModuleState(moduleInstanceKey);
1486
+ const current = state ?? runtime.runSync(moduleRuntime.getState);
1487
+ return selectorReadQuery.select(current);
1488
+ },
1489
+ options,
1490
+ onFirstListener: () => {
1491
+ if (readQueryDrainFiber) return;
1492
+ const effect = import_effect7.Stream.runDrain(moduleRuntime.changesReadQueryWithMeta(selectorReadQuery));
1493
+ readQueryDrainFiber = runtime.runFork(effect);
1494
+ },
1495
+ onLastListener: () => {
1496
+ const fiber = readQueryDrainFiber;
1497
+ if (!fiber) return;
1498
+ readQueryDrainFiber = void 0;
1499
+ runtime.runFork(import_effect7.Fiber.interrupt(fiber));
1500
+ }
1501
+ })
1502
+ );
1248
1503
  };
1249
-
1250
- // src/internal/store/ModuleRuntimeSelectorExternalStore.ts
1251
- var import_effect7 = require("effect");
1252
1504
 
1253
1505
  // src/internal/hooks/shallow.ts
1254
1506
  var hasObjectShape = (value) => typeof value === "object" && value !== null;
@@ -1300,146 +1552,6 @@ var shallow = (previous, next) => {
1300
1552
  return true;
1301
1553
  };
1302
1554
 
1303
- // src/internal/store/ModuleRuntimeSelectorExternalStore.ts
1304
- var storesByRuntime2 = /* @__PURE__ */ new WeakMap();
1305
- var getStoreMapForRuntime2 = (runtime) => {
1306
- const cached = storesByRuntime2.get(runtime);
1307
- if (cached) return cached;
1308
- const next = /* @__PURE__ */ new WeakMap();
1309
- storesByRuntime2.set(runtime, next);
1310
- return next;
1311
- };
1312
- var getOrCreateSelectorMapForModule = (byModule, moduleRuntime) => {
1313
- const cached = byModule.get(moduleRuntime);
1314
- if (cached) return cached;
1315
- const next = /* @__PURE__ */ new Map();
1316
- byModule.set(moduleRuntime, next);
1317
- return next;
1318
- };
1319
- var equalsValue = (readQuery, a, b) => {
1320
- if (readQuery.equalsKind === "custom" && typeof readQuery.equals === "function") {
1321
- return readQuery.equals(a, b);
1322
- }
1323
- if (readQuery.equalsKind === "shallowStruct") {
1324
- return shallow(a, b);
1325
- }
1326
- return Object.is(a, b);
1327
- };
1328
- var getModuleRuntimeSelectorExternalStore = (runtime, moduleRuntime, selectorReadQuery, options) => {
1329
- const byModule = getStoreMapForRuntime2(runtime);
1330
- const bySelector = getOrCreateSelectorMapForModule(byModule, moduleRuntime);
1331
- const cached = bySelector.get(selectorReadQuery.selectorId);
1332
- if (cached) {
1333
- return cached;
1334
- }
1335
- let currentValue;
1336
- const listeners = /* @__PURE__ */ new Set();
1337
- const lowPriorityDelayMs = options?.lowPriorityDelayMs ?? 16;
1338
- const lowPriorityMaxDelayMs = options?.lowPriorityMaxDelayMs ?? 50;
1339
- let notifyScheduled = false;
1340
- let notifyScheduledLow = false;
1341
- let lowTimeoutId;
1342
- let lowMaxTimeoutId;
1343
- let lowRafId;
1344
- const cancelLow = () => {
1345
- if (!notifyScheduledLow) return;
1346
- notifyScheduledLow = false;
1347
- if (lowTimeoutId != null) {
1348
- clearTimeout(lowTimeoutId);
1349
- lowTimeoutId = void 0;
1350
- }
1351
- if (lowMaxTimeoutId != null) {
1352
- clearTimeout(lowMaxTimeoutId);
1353
- lowMaxTimeoutId = void 0;
1354
- }
1355
- const cancel = globalThis.cancelAnimationFrame;
1356
- if (cancel && typeof lowRafId === "number") {
1357
- cancel(lowRafId);
1358
- lowRafId = void 0;
1359
- }
1360
- };
1361
- const flushNotify = () => {
1362
- notifyScheduled = false;
1363
- cancelLow();
1364
- for (const listener of listeners) {
1365
- listener();
1366
- }
1367
- };
1368
- const scheduleNotify = (priority) => {
1369
- if (priority === "low") {
1370
- if (notifyScheduled) return;
1371
- if (notifyScheduledLow) return;
1372
- notifyScheduledLow = true;
1373
- const flush = () => {
1374
- if (!notifyScheduledLow) return;
1375
- flushNotify();
1376
- };
1377
- const raf = globalThis.requestAnimationFrame;
1378
- if (raf) {
1379
- lowRafId = raf(flush);
1380
- } else {
1381
- lowTimeoutId = setTimeout(flush, lowPriorityDelayMs);
1382
- }
1383
- lowMaxTimeoutId = setTimeout(flush, lowPriorityMaxDelayMs);
1384
- return;
1385
- }
1386
- cancelLow();
1387
- if (notifyScheduled) return;
1388
- notifyScheduled = true;
1389
- queueMicrotask(flushNotify);
1390
- };
1391
- let fiber;
1392
- const ensureSubscription = () => {
1393
- if (fiber) return;
1394
- fiber = runtime.runFork(
1395
- import_effect7.Stream.runForEach(
1396
- moduleRuntime.changesReadQueryWithMeta(selectorReadQuery),
1397
- ({ value, meta }) => import_effect7.Effect.sync(() => {
1398
- currentValue = value;
1399
- scheduleNotify(meta.priority);
1400
- })
1401
- )
1402
- );
1403
- };
1404
- const refreshSnapshotIfStale = () => {
1405
- if (currentValue === void 0) {
1406
- return;
1407
- }
1408
- try {
1409
- const state = runtime.runSync(moduleRuntime.getState);
1410
- const next = selectorReadQuery.select(state);
1411
- if (currentValue === void 0 || !equalsValue(selectorReadQuery, currentValue, next)) {
1412
- currentValue = next;
1413
- scheduleNotify("normal");
1414
- }
1415
- } catch {
1416
- }
1417
- };
1418
- const getSnapshot = () => {
1419
- if (currentValue !== void 0) return currentValue;
1420
- const state = runtime.runSync(moduleRuntime.getState);
1421
- currentValue = selectorReadQuery.select(state);
1422
- return currentValue;
1423
- };
1424
- const subscribe = (listener) => {
1425
- listeners.add(listener);
1426
- ensureSubscription();
1427
- refreshSnapshotIfStale();
1428
- return () => {
1429
- listeners.delete(listener);
1430
- if (listeners.size > 0) return;
1431
- const running = fiber;
1432
- if (!running) return;
1433
- fiber = void 0;
1434
- cancelLow();
1435
- runtime.runFork(import_effect7.Fiber.interrupt(running));
1436
- };
1437
- };
1438
- const store = { getSnapshot, subscribe };
1439
- bySelector.set(selectorReadQuery.selectorId, store);
1440
- return store;
1441
- };
1442
-
1443
1555
  // src/internal/hooks/useSelector.ts
1444
1556
  function useSelector(handle, selector, equalityFn) {
1445
1557
  const runtimeContext = (0, import_react5.useContext)(RuntimeContext);
@@ -1450,7 +1562,7 @@ function useSelector(handle, selector, equalityFn) {
1450
1562
  const moduleRuntime = useModuleRuntime(handle);
1451
1563
  const actualSelector = selector ?? ((state) => state);
1452
1564
  const selectorReadQuery = (0, import_react5.useMemo)(
1453
- () => typeof selector === "function" ? Logix5.ReadQuery.compile(selector) : void 0,
1565
+ () => typeof selector === "function" ? Logix7.ReadQuery.compile(selector) : void 0,
1454
1566
  [selector]
1455
1567
  );
1456
1568
  const actualEqualityFn = (0, import_react5.useMemo)(() => {
@@ -1458,17 +1570,12 @@ function useSelector(handle, selector, equalityFn) {
1458
1570
  if (typeof selector !== "function") return Object.is;
1459
1571
  return selectorReadQuery?.equalsKind === "shallowStruct" ? shallow : Object.is;
1460
1572
  }, [equalityFn, selector, selectorReadQuery?.equalsKind]);
1461
- const useStaticLane = typeof selector === "function" && selectorReadQuery?.lane === "static";
1573
+ const selectorTopicEligible = typeof selector === "function" && selectorReadQuery?.lane === "static" && selectorReadQuery.readsDigest != null && selectorReadQuery.fallbackReason == null;
1462
1574
  const store = (0, import_react5.useMemo)(
1463
- () => useStaticLane && selectorReadQuery ? getModuleRuntimeSelectorExternalStore(
1464
- runtime,
1465
- moduleRuntime,
1466
- selectorReadQuery,
1467
- {
1468
- lowPriorityDelayMs: runtimeContext.reactConfigSnapshot.lowPriorityDelayMs,
1469
- lowPriorityMaxDelayMs: runtimeContext.reactConfigSnapshot.lowPriorityMaxDelayMs
1470
- }
1471
- ) : getModuleRuntimeExternalStore(
1575
+ () => selectorTopicEligible && selectorReadQuery ? getRuntimeReadQueryExternalStore(runtime, moduleRuntime, selectorReadQuery, {
1576
+ lowPriorityDelayMs: runtimeContext.reactConfigSnapshot.lowPriorityDelayMs,
1577
+ lowPriorityMaxDelayMs: runtimeContext.reactConfigSnapshot.lowPriorityMaxDelayMs
1578
+ }) : getRuntimeModuleExternalStore(
1472
1579
  runtime,
1473
1580
  moduleRuntime,
1474
1581
  {
@@ -1482,18 +1589,18 @@ function useSelector(handle, selector, equalityFn) {
1482
1589
  runtimeContext.reactConfigSnapshot.lowPriorityDelayMs,
1483
1590
  runtimeContext.reactConfigSnapshot.lowPriorityMaxDelayMs,
1484
1591
  selectorReadQuery,
1485
- useStaticLane
1592
+ selectorTopicEligible
1486
1593
  ]
1487
1594
  );
1488
1595
  const selected = (0, import_with_selector.useSyncExternalStoreWithSelector)(
1489
1596
  store.subscribe,
1490
1597
  store.getSnapshot,
1491
- store.getSnapshot,
1492
- useStaticLane ? (snapshot) => snapshot : (snapshot) => actualSelector(snapshot),
1598
+ store.getServerSnapshot ?? store.getSnapshot,
1599
+ selectorTopicEligible ? (snapshot) => snapshot : (snapshot) => actualSelector(snapshot),
1493
1600
  actualEqualityFn
1494
1601
  );
1495
1602
  (0, import_react5.useEffect)(() => {
1496
- if (!(0, import_Env.isDevEnv)() && !Logix5.Debug.isDevtoolsEnabled()) {
1603
+ if (!(0, import_Env.isDevEnv)() && !Logix7.Debug.isDevtoolsEnabled()) {
1497
1604
  return;
1498
1605
  }
1499
1606
  const instanceId = moduleRuntime.instanceId;
@@ -1509,7 +1616,7 @@ function useSelector(handle, selector, equalityFn) {
1509
1616
  const rawDebugKey = meta.debugKey;
1510
1617
  selectorKey = typeof rawDebugKey === "string" && rawDebugKey.length > 0 ? rawDebugKey : typeof selector.name === "string" && selector.name.length > 0 ? selector.name : void 0;
1511
1618
  }
1512
- const effect = Logix5.Debug.record({
1619
+ const effect = Logix7.Debug.record({
1513
1620
  type: "trace:react-selector",
1514
1621
  moduleId: moduleRuntime.moduleId,
1515
1622
  instanceId,
@@ -1532,7 +1639,7 @@ function useSelector(handle, selector, equalityFn) {
1532
1639
  }
1533
1640
 
1534
1641
  // src/internal/store/resolveImportedModuleRef.ts
1535
- var Logix6 = __toESM(require("@logixjs/core"), 1);
1642
+ var Logix8 = __toESM(require("@logixjs/core"), 1);
1536
1643
  var getOrCreateWeakMap = (map, key, make) => {
1537
1644
  const cached = map.get(key);
1538
1645
  if (cached) return cached;
@@ -1556,7 +1663,7 @@ var resolveImportedModuleRef = (runtime, parentRuntime, module2) => {
1556
1663
  if (cached) {
1557
1664
  return cached;
1558
1665
  }
1559
- const importsScope = Logix6.InternalContracts.getImportsScope(parentRuntime);
1666
+ const importsScope = Logix8.InternalContracts.getImportsScope(parentRuntime);
1560
1667
  const childRuntime = importsScope.get(module2);
1561
1668
  if (childRuntime) {
1562
1669
  const dispatch = Object.assign(
@@ -1642,8 +1749,8 @@ var useStableId = () => {
1642
1749
 
1643
1750
  // src/internal/hooks/useModule.ts
1644
1751
  var isModuleImpl = (handle) => Boolean(handle) && typeof handle === "object" && handle._tag === "ModuleImpl";
1645
- var isModule = (handle) => Logix7.Module.hasImpl(handle);
1646
- var isModuleDef = (handle) => Logix7.Module.is(handle) && handle._kind === "ModuleDef";
1752
+ var isModule = (handle) => Logix9.Module.hasImpl(handle);
1753
+ var isModuleDef = (handle) => Logix9.Module.is(handle) && handle._kind === "ModuleDef";
1647
1754
  function useModule(handle, selectorOrOptions, equalityFn) {
1648
1755
  const runtimeBase = useRuntime();
1649
1756
  const runtimeContext = import_react7.default.useContext(RuntimeContext);
@@ -1667,6 +1774,7 @@ function useModule(handle, selectorOrOptions, equalityFn) {
1667
1774
  }
1668
1775
  }
1669
1776
  let runtime;
1777
+ const moduleImplResolveTraceRef = import_react7.default.useRef(void 0);
1670
1778
  if (isModuleImpl(normalizedHandle)) {
1671
1779
  const cache = import_react7.default.useMemo(
1672
1780
  () => getModuleCache(runtimeBase, runtimeContext.reactConfigSnapshot, runtimeContext.configVersion),
@@ -1695,9 +1803,9 @@ function useModule(handle, selectorOrOptions, equalityFn) {
1695
1803
  const key = depsHash ? `${baseKey}:${depsHash}` : baseKey;
1696
1804
  const ownerId = moduleId;
1697
1805
  const baseFactory = import_react7.default.useMemo(
1698
- () => (scope) => import_effect8.Layer.buildWithScope(normalizedHandle.layer, scope).pipe(
1806
+ () => (scope) => import_effect8.Layer.buildWithScope(import_effect8.Layer.fresh(normalizedHandle.layer), scope).pipe(
1699
1807
  import_effect8.Effect.map(
1700
- (context) => import_effect8.Context.get(context, normalizedHandle.module)
1808
+ (context) => import_effect8.ServiceMap.get(context, normalizedHandle.module)
1701
1809
  )
1702
1810
  ),
1703
1811
  [normalizedHandle]
@@ -1707,26 +1815,56 @@ function useModule(handle, selectorOrOptions, equalityFn) {
1707
1815
  return baseFactory;
1708
1816
  }
1709
1817
  return (scope) => baseFactory(scope).pipe(
1710
- import_effect8.Effect.timeoutFail({
1711
- duration: initTimeoutMs,
1712
- onTimeout: () => new Error(`[useModule] Module "${ownerId}" initialization timed out after ${initTimeoutMs}ms`)
1713
- })
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
+ )
1714
1822
  );
1715
1823
  }, [baseFactory, suspend, initTimeoutMs, ownerId]);
1824
+ const moduleResolveStartedAt = performance.now();
1716
1825
  const moduleRuntime = suspend ? cache.read(key, factory, gcTime, ownerId, {
1717
1826
  entrypoint: "react.useModule",
1718
1827
  policyMode: runtimeContext.policy.mode,
1719
- yield: runtimeContext.policy.yield
1828
+ yield: runtimeContext.policy.yield,
1829
+ optimisticSyncBudgetMs: runtimeContext.policy.syncBudgetMs
1720
1830
  }) : cache.readSync(key, factory, gcTime, ownerId, {
1721
1831
  entrypoint: "react.useModule",
1722
1832
  policyMode: runtimeContext.policy.mode,
1723
1833
  warnSyncBlockingThresholdMs: 5
1724
1834
  });
1835
+ moduleImplResolveTraceRef.current = {
1836
+ moduleId,
1837
+ cacheMode: suspend ? "suspend" : "sync",
1838
+ durationMs: Math.round((performance.now() - moduleResolveStartedAt) * 100) / 100
1839
+ };
1725
1840
  import_react7.default.useEffect(() => cache.retain(key), [cache, key]);
1726
1841
  runtime = moduleRuntime;
1727
1842
  } else {
1728
1843
  runtime = useModuleRuntime(normalizedHandle);
1729
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]);
1730
1868
  import_react7.default.useEffect(() => {
1731
1869
  if (!isModuleImpl(normalizedHandle)) {
1732
1870
  return;
@@ -1736,22 +1874,22 @@ function useModule(handle, selectorOrOptions, equalityFn) {
1736
1874
  if (!label) {
1737
1875
  return;
1738
1876
  }
1739
- const effect = Logix7.Debug.record({
1877
+ const effect = Logix9.Debug.record({
1740
1878
  type: "trace:instanceLabel",
1741
1879
  moduleId: normalizedHandle.module.id,
1742
1880
  instanceId: runtime.instanceId,
1743
1881
  data: { label }
1744
1882
  });
1745
- runtimeBase.runFork(effect);
1883
+ emitRuntimeDebugEventBestEffort(runtimeBase, effect);
1746
1884
  }, [runtimeBase, runtime, normalizedHandle, options]);
1747
1885
  import_react7.default.useEffect(() => {
1748
- if (!(0, import_Env.isDevEnv)() && !Logix7.Debug.isDevtoolsEnabled()) {
1886
+ if (!(0, import_Env.isDevEnv)() && !Logix9.Debug.isDevtoolsEnabled()) {
1749
1887
  return;
1750
1888
  }
1751
1889
  if (!runtime.instanceId) {
1752
1890
  return;
1753
1891
  }
1754
- const effect = Logix7.Debug.record({
1892
+ const effect = Logix9.Debug.record({
1755
1893
  type: "trace:react-render",
1756
1894
  moduleId: runtime.moduleId,
1757
1895
  instanceId: runtime.instanceId,
@@ -1761,7 +1899,7 @@ function useModule(handle, selectorOrOptions, equalityFn) {
1761
1899
  }
1762
1900
  });
1763
1901
  runtimeBase.runFork(effect);
1764
- }, [runtimeBase, runtime]);
1902
+ });
1765
1903
  if (selector) {
1766
1904
  if (isModuleImpl(normalizedHandle)) {
1767
1905
  return useSelector(runtime, selector, equalityFn);
@@ -1849,11 +1987,11 @@ function useModule(handle, selectorOrOptions, equalityFn) {
1849
1987
  // src/internal/provider/RuntimeProvider.tsx
1850
1988
  var import_react9 = __toESM(require("react"), 1);
1851
1989
  var import_effect10 = require("effect");
1852
- var Logix9 = __toESM(require("@logixjs/core"), 1);
1990
+ var Logix11 = __toESM(require("@logixjs/core"), 1);
1853
1991
 
1854
1992
  // src/internal/provider/config.ts
1855
1993
  var import_effect9 = require("effect");
1856
- var ReactRuntimeConfigTag = class extends import_effect9.Context.Tag("@logixjs/react/RuntimeConfig")() {
1994
+ var ReactRuntimeConfigTag = class extends import_effect9.ServiceMap.Service()("@logixjs/react/RuntimeConfig") {
1857
1995
  };
1858
1996
  var DEFAULT_CONFIG = {
1859
1997
  gcTime: 500,
@@ -1965,7 +2103,7 @@ var ReactRuntimeConfigSnapshot = {
1965
2103
 
1966
2104
  // src/internal/provider/fallback.tsx
1967
2105
  var import_react8 = require("react");
1968
- var Logix8 = __toESM(require("@logixjs/core"), 1);
2106
+ var Logix10 = __toESM(require("@logixjs/core"), 1);
1969
2107
 
1970
2108
  // src/internal/provider/docs.ts
1971
2109
  var LOGIX_DOCS_PREFIX_ENV = "LOGIX_DOCS_PREFIX";
@@ -2068,11 +2206,11 @@ var resolveRuntimeProviderFallback = (args) => {
2068
2206
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DefaultRuntimeFallback, { phase: args.phase, policyMode: args.policyMode });
2069
2207
  };
2070
2208
  var recordFallbackDuration = (args) => {
2071
- if (!(0, import_Env.isDevEnv)() && !Logix8.Debug.isDevtoolsEnabled()) {
2209
+ if (!(0, import_Env.isDevEnv)() && !Logix10.Debug.isDevtoolsEnabled()) {
2072
2210
  return;
2073
2211
  }
2074
2212
  void args.runtime.runPromise(
2075
- Logix8.Debug.record({
2213
+ Logix10.Debug.record({
2076
2214
  type: "trace:react.fallback.duration",
2077
2215
  data: {
2078
2216
  phase: args.phase,
@@ -2151,7 +2289,7 @@ var FallbackProbeEnabled = ({ runtime, phase, policyMode, blockers, children })
2151
2289
  };
2152
2290
  var FallbackProbeNoop = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
2153
2291
  var FallbackProbe = (props) => {
2154
- const enabled = (0, import_Env.isDevEnv)() || Logix8.Debug.isDevtoolsEnabled();
2292
+ const enabled = (0, import_Env.isDevEnv)() || Logix10.Debug.isDevtoolsEnabled();
2155
2293
  const Impl = enabled ? FallbackProbeEnabled : FallbackProbeNoop;
2156
2294
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Impl, { ...props });
2157
2295
  };
@@ -2234,6 +2372,9 @@ var RuntimeProvider = ({
2234
2372
  }) => {
2235
2373
  const parent = (0, import_react9.useContext)(RuntimeContext);
2236
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);
2237
2378
  const resolvedPolicy = (0, import_react9.useMemo)(
2238
2379
  () => resolveRuntimeProviderPolicy({
2239
2380
  policy,
@@ -2243,6 +2384,20 @@ var RuntimeProvider = ({
2243
2384
  );
2244
2385
  const onErrorRef = import_react9.default.useRef(onError);
2245
2386
  onErrorRef.current = onError;
2387
+ const hasTickServices = (0, import_react9.useMemo)(() => {
2388
+ try {
2389
+ Logix11.InternalContracts.getRuntimeStore(baseRuntime);
2390
+ return true;
2391
+ } catch {
2392
+ return false;
2393
+ }
2394
+ }, [baseRuntime]);
2395
+ const { binding: tickBinding } = useLayerBinding(
2396
+ baseRuntime,
2397
+ Logix11.InternalContracts.tickServicesLayer,
2398
+ !hasTickServices,
2399
+ onErrorRef.current
2400
+ );
2246
2401
  const { binding: layerBinding } = useLayerBinding(baseRuntime, layer, Boolean(layer), onErrorRef.current);
2247
2402
  const onErrorSink = (0, import_react9.useMemo)(() => {
2248
2403
  if (!onError) return null;
@@ -2259,7 +2414,7 @@ var RuntimeProvider = ({
2259
2414
  moduleId: event.moduleId,
2260
2415
  instanceId: event.instanceId,
2261
2416
  runtimeLabel: event.runtimeLabel
2262
- }).pipe(import_effect10.Effect.catchAllCause(() => import_effect10.Effect.void));
2417
+ }).pipe(import_effect10.Effect.catchCause(() => import_effect10.Effect.void));
2263
2418
  }
2264
2419
  if (event.type === "diagnostic" && event.severity === "error") {
2265
2420
  return handler(
@@ -2278,7 +2433,7 @@ var RuntimeProvider = ({
2278
2433
  instanceId: event.instanceId,
2279
2434
  runtimeLabel: event.runtimeLabel
2280
2435
  }
2281
- ).pipe(import_effect10.Effect.catchAllCause(() => import_effect10.Effect.void));
2436
+ ).pipe(import_effect10.Effect.catchCause(() => import_effect10.Effect.void));
2282
2437
  }
2283
2438
  return import_effect10.Effect.void;
2284
2439
  }
@@ -2293,25 +2448,23 @@ var RuntimeProvider = ({
2293
2448
  return layerBinding.debugSinks;
2294
2449
  }
2295
2450
  try {
2296
- return baseRuntime.runSync(
2297
- import_effect10.FiberRef.get(Logix9.Debug.internal.currentDebugSinks)
2298
- );
2451
+ return baseRuntime.runSync(import_effect10.Effect.service(Logix11.Debug.internal.currentDebugSinks).pipe(import_effect10.Effect.orDie));
2299
2452
  } catch {
2300
2453
  return [];
2301
2454
  }
2302
2455
  }, [baseRuntime, layerBinding, onErrorSink]);
2303
2456
  const runtimeWithBindings = (0, import_react9.useMemo)(
2304
- () => layerBinding || onErrorSink ? createRuntimeAdapter(
2457
+ () => tickBinding || layerBinding || onErrorSink ? createRuntimeAdapter(
2305
2458
  baseRuntime,
2306
- layerBinding ? [layerBinding.context] : [],
2307
- layerBinding ? [layerBinding.scope] : [],
2308
- layerBinding ? [layerBinding.loggers] : [],
2309
- layerBinding ? [layerBinding.logLevel] : [],
2459
+ [...tickBinding ? [tickBinding.context] : [], ...layerBinding ? [layerBinding.context] : []],
2460
+ [...tickBinding ? [tickBinding.scope] : [], ...layerBinding ? [layerBinding.scope] : []],
2461
+ layerBinding ? [layerBinding.loggers] : tickBinding ? [tickBinding.loggers] : [],
2462
+ layerBinding ? [layerBinding.logLevel] : tickBinding ? [tickBinding.logLevel] : [],
2310
2463
  [
2311
2464
  onErrorSink ? [onErrorSink, ...inheritedDebugSinks] : layerBinding ? layerBinding.debugSinks : []
2312
2465
  ]
2313
2466
  ) : baseRuntime,
2314
- [baseRuntime, inheritedDebugSinks, layerBinding, onErrorSink]
2467
+ [baseRuntime, inheritedDebugSinks, layerBinding, onErrorSink, tickBinding]
2315
2468
  );
2316
2469
  const didReportSyncConfigSnapshotRef = import_react9.default.useRef(false);
2317
2470
  const [configState, setConfigState] = (0, import_react9.useState)(() => {
@@ -2353,7 +2506,7 @@ var RuntimeProvider = ({
2353
2506
  }
2354
2507
  didReportSyncConfigSnapshotRef.current = true;
2355
2508
  void runtimeWithBindings.runPromise(
2356
- Logix9.Debug.record({
2509
+ Logix11.Debug.record({
2357
2510
  type: "trace:react.runtime.config.snapshot",
2358
2511
  data: {
2359
2512
  source: configState.snapshot.source,
@@ -2384,7 +2537,7 @@ var RuntimeProvider = ({
2384
2537
  };
2385
2538
  });
2386
2539
  void runtimeWithBindings.runPromise(
2387
- Logix9.Debug.record({
2540
+ Logix11.Debug.record({
2388
2541
  type: "trace:react.runtime.config.snapshot",
2389
2542
  data: {
2390
2543
  source: snapshot.source,
@@ -2416,11 +2569,47 @@ var RuntimeProvider = ({
2416
2569
  }),
2417
2570
  [runtimeWithBindings, configState, resolvedPolicy]
2418
2571
  );
2572
+ const isTickServicesReady = hasTickServices || tickBinding !== null;
2419
2573
  const isLayerReady = !layer || layerBinding !== null;
2420
2574
  const isConfigReady = configState.loaded;
2421
2575
  const resolveFallback = (phase) => {
2422
2576
  return resolveRuntimeProviderFallback({ fallback, phase, policyMode: resolvedPolicy.mode });
2423
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]);
2424
2613
  const [deferReady, setDeferReady] = (0, import_react9.useState)(false);
2425
2614
  (0, import_react9.useEffect)(() => {
2426
2615
  if (resolvedPolicy.mode !== "defer") {
@@ -2434,6 +2623,10 @@ var RuntimeProvider = ({
2434
2623
  if (resolvedPolicy.mode !== "defer") {
2435
2624
  return;
2436
2625
  }
2626
+ if (syncWarmPreloadReady) {
2627
+ setDeferReady(true);
2628
+ return;
2629
+ }
2437
2630
  setDeferReady(false);
2438
2631
  if (!resolvedPolicy.preload) {
2439
2632
  setDeferReady(true);
@@ -2443,7 +2636,7 @@ var RuntimeProvider = ({
2443
2636
  return;
2444
2637
  }
2445
2638
  let cancelled = false;
2446
- const cache = getModuleCache(runtimeWithBindings, configState.snapshot, configState.version);
2639
+ const cache = preloadCache;
2447
2640
  const preloadHandles = resolvedPolicy.preload.handles;
2448
2641
  if (preloadHandles.length === 0) {
2449
2642
  setDeferReady(true);
@@ -2461,19 +2654,20 @@ var RuntimeProvider = ({
2461
2654
  const moduleId = handle.module?.id ?? "ModuleImpl";
2462
2655
  const key2 = resolvedPolicy.preload.keysByModuleId.get(moduleId) ?? getPreloadKeyForModuleId(moduleId);
2463
2656
  const factory2 = (scope) => import_effect10.Layer.buildWithScope(handle.layer, scope).pipe(
2464
- import_effect10.Effect.map((context) => import_effect10.Context.get(context, handle.module))
2657
+ import_effect10.Effect.map((context) => import_effect10.ServiceMap.get(context, handle.module))
2465
2658
  );
2466
2659
  const op2 = cache.preload(key2, factory2, {
2467
2660
  ownerId: moduleId,
2468
2661
  yield: resolvedPolicy.preload.yield,
2469
2662
  entrypoint: "react.runtime.preload",
2470
- policyMode: "defer"
2663
+ policyMode: "defer",
2664
+ optimisticSyncBudgetMs: resolvedPolicy.syncBudgetMs
2471
2665
  });
2472
2666
  allCancels.add(op2.cancel);
2473
2667
  await op2.promise;
2474
2668
  const durationMs2 = performance.now() - startedAt;
2475
2669
  void runtimeWithBindings.runPromise(
2476
- Logix9.Debug.record({
2670
+ Logix11.Debug.record({
2477
2671
  type: "trace:react.module.preload",
2478
2672
  moduleId,
2479
2673
  data: {
@@ -2492,20 +2686,19 @@ var RuntimeProvider = ({
2492
2686
  }
2493
2687
  const tagId = handle.id ?? "ModuleTag";
2494
2688
  const key = resolvedPolicy.preload.keysByTagId.get(tagId) ?? getPreloadKeyForTagId(tagId);
2495
- const factory = (scope) => handle.pipe(
2496
- import_effect10.Scope.extend(scope)
2497
- );
2689
+ const factory = (scope) => import_effect10.Scope.provide(scope)(import_effect10.Effect.service(handle).pipe(import_effect10.Effect.orDie));
2498
2690
  const op = cache.preload(key, factory, {
2499
2691
  ownerId: tagId,
2500
2692
  yield: resolvedPolicy.preload.yield,
2501
2693
  entrypoint: "react.runtime.preload",
2502
- policyMode: "defer"
2694
+ policyMode: "defer",
2695
+ optimisticSyncBudgetMs: resolvedPolicy.syncBudgetMs
2503
2696
  });
2504
2697
  allCancels.add(op.cancel);
2505
2698
  await op.promise;
2506
2699
  const durationMs = performance.now() - startedAt;
2507
2700
  void runtimeWithBindings.runPromise(
2508
- Logix9.Debug.record({
2701
+ Logix11.Debug.record({
2509
2702
  type: "trace:react.module.preload",
2510
2703
  data: {
2511
2704
  mode: "defer",
@@ -2537,7 +2730,7 @@ var RuntimeProvider = ({
2537
2730
  if (cancelled) return;
2538
2731
  if (onErrorRef.current) {
2539
2732
  runtimeWithBindings.runFork(
2540
- onErrorRef.current(import_effect10.Cause.die(error), { source: "provider", phase: "provider.layer.build" }).pipe(import_effect10.Effect.catchAllCause(() => import_effect10.Effect.void))
2733
+ onErrorRef.current(import_effect10.Cause.die(error), { source: "provider", phase: "provider.layer.build" }).pipe(import_effect10.Effect.catchCause(() => import_effect10.Effect.void))
2541
2734
  );
2542
2735
  }
2543
2736
  setDeferReady(true);
@@ -2570,12 +2763,54 @@ var RuntimeProvider = ({
2570
2763
  release();
2571
2764
  };
2572
2765
  }, [resolvedPolicy.mode, deferReady]);
2573
- const isReady = 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]);
2574
2808
  if (!isReady) {
2575
2809
  const blockersList = [
2810
+ isTickServicesReady ? null : "tick",
2576
2811
  isLayerReady ? null : "layer",
2577
2812
  isConfigReady ? null : "config",
2578
- resolvedPolicy.mode !== "defer" || deferReady ? null : "preload"
2813
+ resolvedPolicy.mode !== "defer" || deferReady || syncWarmPreloadReady ? null : "preload"
2579
2814
  ].filter((x) => x !== null);
2580
2815
  const blockers = blockersList.length > 0 ? blockersList.join("+") : void 0;
2581
2816
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
@@ -2610,14 +2845,16 @@ var useRuntimeResolution = (runtimeProp, parent) => {
2610
2845
 
2611
2846
  // src/ModuleScope.ts
2612
2847
  var makeModuleScope = (handle, defaults) => {
2613
- const Context5 = import_react10.default.createContext(null);
2848
+ const Context = import_react10.default.createContext(null);
2614
2849
  const toUseModuleOptions = (options) => {
2615
2850
  const { scopeId, ...rest } = options;
2616
2851
  return scopeId != null ? { ...rest, key: scopeId } : rest;
2617
2852
  };
2618
2853
  const getRegistryOrThrow = (runtime, where) => {
2619
2854
  try {
2620
- const registry = runtime.runSync(Logix10.ScopeRegistry.ScopeRegistryTag);
2855
+ const registry = runtime.runSync(
2856
+ import_effect11.Effect.service(Logix12.ScopeRegistry.ScopeRegistryTag).pipe(import_effect11.Effect.orDie)
2857
+ );
2621
2858
  if (!registry) {
2622
2859
  throw new Error("ScopeRegistry service is undefined");
2623
2860
  }
@@ -2628,7 +2865,7 @@ var makeModuleScope = (handle, defaults) => {
2628
2865
  );
2629
2866
  }
2630
2867
  };
2631
- const moduleToken = Logix10.Module.hasImpl(handle) ? handle.tag : handle.module;
2868
+ const moduleToken = Logix12.Module.hasImpl(handle) ? handle.tag : handle.module;
2632
2869
  const Provider = ({ children, options }) => {
2633
2870
  const runtime = useRuntime();
2634
2871
  const merged = defaults || options ? { ...defaults ?? {}, ...options ?? {} } : void 0;
@@ -2637,17 +2874,17 @@ var makeModuleScope = (handle, defaults) => {
2637
2874
  import_react10.default.useEffect(() => {
2638
2875
  if (!scopeId) return;
2639
2876
  const registry = getRegistryOrThrow(runtime, "[ModuleScope]");
2640
- const leaseRuntime = registry.register(scopeId, Logix10.ScopeRegistry.ScopedRuntimeTag, runtime);
2877
+ const leaseRuntime = registry.register(scopeId, Logix12.ScopeRegistry.ScopedRuntimeTag, runtime);
2641
2878
  const leaseModule = registry.register(scopeId, moduleToken, ref.runtime);
2642
2879
  return () => {
2643
2880
  leaseModule.release();
2644
2881
  leaseRuntime.release();
2645
2882
  };
2646
2883
  }, [runtime, scopeId, ref.runtime]);
2647
- return import_react10.default.createElement(Context5.Provider, { value: ref }, children);
2884
+ return import_react10.default.createElement(Context.Provider, { value: ref }, children);
2648
2885
  };
2649
2886
  const use = () => {
2650
- const ref = import_react10.default.useContext(Context5);
2887
+ const ref = import_react10.default.useContext(Context);
2651
2888
  if (!ref) {
2652
2889
  throw new Error("[ModuleScope] Provider not found");
2653
2890
  }
@@ -2660,11 +2897,8 @@ var makeModuleScope = (handle, defaults) => {
2660
2897
  const Bridge = ({ scopeId, children }) => {
2661
2898
  const runtime = useRuntime();
2662
2899
  const registry = getRegistryOrThrow(runtime, "[ModuleScope.Bridge]");
2663
- const scopedRuntime = registry.get(scopeId, Logix10.ScopeRegistry.ScopedRuntimeTag);
2664
- const moduleRuntime = registry.get(
2665
- scopeId,
2666
- moduleToken
2667
- );
2900
+ const scopedRuntime = registry.get(scopeId, Logix12.ScopeRegistry.ScopedRuntimeTag);
2901
+ const moduleRuntime = registry.get(scopeId, moduleToken);
2668
2902
  if (!scopedRuntime || !moduleRuntime) {
2669
2903
  throw new Error(
2670
2904
  `[ModuleScope.Bridge] Scope "${scopeId}" is not registered (or has been disposed). Ensure you have a corresponding <ModuleScope.Provider options={{ scopeId }}> mounted.`
@@ -2673,18 +2907,18 @@ var makeModuleScope = (handle, defaults) => {
2673
2907
  return import_react10.default.createElement(
2674
2908
  RuntimeProvider,
2675
2909
  { runtime: scopedRuntime },
2676
- import_react10.default.createElement(BridgeInner, { moduleRuntime, Context: Context5 }, children)
2910
+ import_react10.default.createElement(BridgeInner, { moduleRuntime, Context }, children)
2677
2911
  );
2678
2912
  };
2679
2913
  const BridgeInner = ({
2680
2914
  moduleRuntime,
2681
- Context: Context6,
2915
+ Context: Context2,
2682
2916
  children
2683
2917
  }) => {
2684
2918
  const ref = useModule(moduleRuntime);
2685
- return import_react10.default.createElement(Context6.Provider, { value: ref }, children);
2919
+ return import_react10.default.createElement(Context2.Provider, { value: ref }, children);
2686
2920
  };
2687
- return { Provider, use, useImported, Context: Context5, Bridge };
2921
+ return { Provider, use, useImported, Context, Bridge };
2688
2922
  };
2689
2923
  var ModuleScope = {
2690
2924
  make: makeModuleScope