@logixjs/react 0.1.1 → 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.
@@ -45,7 +45,7 @@ var RuntimeContext = (0, import_react.createContext)(null);
45
45
 
46
46
  // src/internal/provider/config.ts
47
47
  var import_effect = require("effect");
48
- var ReactRuntimeConfigTag = class extends import_effect.Context.Tag("@logixjs/react/RuntimeConfig")() {
48
+ var ReactRuntimeConfigTag = class extends import_effect.ServiceMap.Service()("@logixjs/react/RuntimeConfig") {
49
49
  };
50
50
  var DEFAULT_CONFIG = {
51
51
  gcTime: 500,
@@ -155,13 +155,13 @@ var ReactRuntimeConfigSnapshot = {
155
155
  })
156
156
  };
157
157
 
158
+ // src/internal/provider/env.ts
159
+ var import_Env = require("@logixjs/core/Env");
160
+
158
161
  // src/internal/provider/fallback.tsx
159
162
  var import_react2 = require("react");
160
163
  var Logix = __toESM(require("@logixjs/core"), 1);
161
164
 
162
- // src/internal/provider/env.ts
163
- var import_Env = require("@logixjs/core/Env");
164
-
165
165
  // src/internal/provider/docs.ts
166
166
  var LOGIX_DOCS_PREFIX_ENV = "LOGIX_DOCS_PREFIX";
167
167
  var stripTrailingSlashes = (value) => value.replace(/\/+$/, "");
@@ -422,14 +422,11 @@ var useLayerBinding = (runtime, layer, enabled, onError) => {
422
422
  const newScope = import_effect2.Effect.runSync(import_effect2.Scope.make());
423
423
  const buildEffect = import_effect2.Effect.gen(function* () {
424
424
  const context = yield* import_effect2.Layer.buildWithScope(layer, newScope);
425
- const applyEnv = (effect) => import_effect2.Effect.mapInputContext(
426
- import_effect2.Scope.extend(effect, newScope),
427
- (parent) => import_effect2.Context.merge(parent, context)
428
- );
429
- const loggers = yield* applyEnv(import_effect2.FiberRef.get(import_effect2.FiberRef.currentLoggers));
430
- const logLevel = yield* applyEnv(import_effect2.FiberRef.get(import_effect2.FiberRef.currentLogLevel));
425
+ const applyEnv = (effect) => import_effect2.Scope.provide(newScope)(import_effect2.Effect.provideServices(effect, context));
426
+ const loggers = yield* applyEnv(import_effect2.Effect.service(import_effect2.Logger.CurrentLoggers)).pipe(import_effect2.Effect.orDie);
427
+ const logLevel = yield* applyEnv(import_effect2.Effect.service(import_effect2.References.MinimumLogLevel)).pipe(import_effect2.Effect.orDie);
431
428
  const debugSinks = yield* applyEnv(
432
- import_effect2.FiberRef.get(Logix2.Debug.internal.currentDebugSinks)
429
+ import_effect2.Effect.service(Logix2.Debug.internal.currentDebugSinks).pipe(import_effect2.Effect.orDie)
433
430
  );
434
431
  return { context, loggers, logLevel, debugSinks };
435
432
  });
@@ -474,7 +471,7 @@ var useLayerBinding = (runtime, layer, enabled, onError) => {
474
471
  const cause = import_effect2.Cause.die(error);
475
472
  runtime.runFork(
476
473
  onError(cause, { source: "provider", phase: "provider.layer.build" }).pipe(
477
- import_effect2.Effect.catchAllCause(() => import_effect2.Effect.void)
474
+ import_effect2.Effect.catchCause(() => import_effect2.Effect.void)
478
475
  )
479
476
  );
480
477
  }
@@ -512,18 +509,11 @@ var createRuntimeAdapter = (runtime, contexts, scopes, loggerSets, logLevels, de
512
509
  if (contexts.length === 0 && scopes.length === 0 && loggerSets.length === 0 && logLevels.length === 0 && debugSinks.length === 0) {
513
510
  return runtime;
514
511
  }
515
- const applyContexts = (effect) => (
516
- // First inherit Provider scopes via scope.extend (preserving FiberRef/Logger changes),
517
- // then merge Context via mapInputContext (inner overrides outer).
518
- contexts.reduceRight(
519
- (acc, ctx) => import_effect2.Effect.mapInputContext(
520
- acc,
521
- (parent) => import_effect2.Context.merge(parent, ctx)
522
- ),
523
- scopes.reduceRight(
524
- (acc, scope) => import_effect2.Scope.extend(acc, scope),
525
- effect
526
- )
512
+ const applyContexts = (effect) => contexts.reduceRight(
513
+ (acc, ctx) => import_effect2.Effect.provideServices(acc, ctx),
514
+ scopes.reduceRight(
515
+ (acc, scope) => import_effect2.Scope.provide(scope)(acc),
516
+ effect
527
517
  )
528
518
  );
529
519
  const applyLoggers = (effect) => {
@@ -532,16 +522,13 @@ var createRuntimeAdapter = (runtime, contexts, scopes, loggerSets, logLevels, de
532
522
  const sinks = debugSinks.length > 0 ? debugSinks[debugSinks.length - 1] : null;
533
523
  let result = effect;
534
524
  if (last) {
535
- result = import_effect2.Effect.locally(import_effect2.FiberRef.currentLoggers, last)(result);
525
+ result = import_effect2.Effect.provideService(result, import_effect2.Logger.CurrentLoggers, last);
536
526
  }
537
527
  if (logLevel) {
538
- result = import_effect2.Effect.locally(import_effect2.FiberRef.currentLogLevel, logLevel)(result);
528
+ result = import_effect2.Effect.provideService(result, import_effect2.References.MinimumLogLevel, logLevel);
539
529
  }
540
530
  if (sinks && sinks.length > 0) {
541
- result = import_effect2.Effect.locally(
542
- Logix2.Debug.internal.currentDebugSinks,
543
- sinks
544
- )(result);
531
+ result = import_effect2.Effect.provideService(result, Logix2.Debug.internal.currentDebugSinks, sinks);
545
532
  }
546
533
  return result;
547
534
  };
@@ -672,9 +659,9 @@ ${message}`;
672
659
  console.debug(label, message);
673
660
  };
674
661
  var causeToUnknown = (cause) => {
675
- const failure = import_effect4.Option.getOrUndefined(import_effect4.Cause.failureOption(cause));
662
+ const failure = import_effect4.Option.getOrUndefined(import_effect4.Cause.findErrorOption(cause));
676
663
  if (failure !== void 0) return failure;
677
- const defect = import_effect4.Option.getOrUndefined(import_effect4.Cause.dieOption(cause));
664
+ const defect = cause.reasons.filter(import_effect4.Cause.isDieReason).map((reason) => reason.defect)[0];
678
665
  if (defect !== void 0) return defect;
679
666
  return cause;
680
667
  };
@@ -683,7 +670,7 @@ var yieldEffect = (strategy) => {
683
670
  case "none":
684
671
  return import_effect4.Effect.void;
685
672
  case "microtask":
686
- return import_effect4.Effect.yieldNow();
673
+ return import_effect4.Effect.yieldNow;
687
674
  case "macrotask":
688
675
  return import_effect4.Effect.promise(
689
676
  () => new Promise((resolve) => {
@@ -776,6 +763,67 @@ var ModuleCache = class {
776
763
  const scope = import_effect4.Effect.runSync(import_effect4.Scope.make());
777
764
  const workloadKey = `${options?.entrypoint ?? "unknown"}::${ownerId ?? "unknown"}`;
778
765
  const yieldDecision = decideYieldStrategy(this.runtime, workloadKey, options?.yield);
766
+ const optimisticSyncBudgetMs = options?.optimisticSyncBudgetMs ?? 0;
767
+ const shouldTryOptimisticSync = options?.policyMode === "suspend" && optimisticSyncBudgetMs > 0;
768
+ if (shouldTryOptimisticSync) {
769
+ const startedAt2 = performance.now();
770
+ try {
771
+ const value = this.runtime.runSync(factory(scope));
772
+ const durationMs = performance.now() - startedAt2;
773
+ YieldBudgetMemory.record({ runtime: this.runtime, workloadKey, durationMs });
774
+ const entry2 = {
775
+ scope,
776
+ status: "success",
777
+ promise: Promise.resolve(value),
778
+ value,
779
+ refCount: 0,
780
+ preloadRefCount: 0,
781
+ gcTime: gcTime ?? this.gcDelayMs,
782
+ ownerId,
783
+ createdBy: "read",
784
+ workloadKey,
785
+ yieldStrategy: "none"
786
+ };
787
+ this.scheduleGC(key, entry2);
788
+ this.entries.set(key, entry2);
789
+ if ((0, import_Env.isDevEnv)() || Logix4.Debug.isDevtoolsEnabled()) {
790
+ void this.runtime.runPromise(
791
+ Logix4.Debug.record({
792
+ type: "trace:react.module.init",
793
+ moduleId: ownerId,
794
+ instanceId: value.instanceId,
795
+ data: {
796
+ mode: "suspend",
797
+ key,
798
+ durationMs: Math.round(durationMs * 100) / 100,
799
+ yieldStrategy: "none",
800
+ fastPath: "sync"
801
+ }
802
+ })
803
+ ).catch((error) => {
804
+ debugBestEffortFailure("[ModuleCache] Debug.record failed", error);
805
+ });
806
+ void this.runtime.runPromise(
807
+ Logix4.Debug.record({
808
+ type: "trace:react.module-instance",
809
+ moduleId: ownerId,
810
+ instanceId: value.instanceId,
811
+ data: {
812
+ event: "attach",
813
+ key,
814
+ mode: "suspend",
815
+ gcTime: entry2.gcTime,
816
+ fastPath: "sync"
817
+ }
818
+ })
819
+ ).catch((error) => {
820
+ debugBestEffortFailure("[ModuleCache] Debug.record failed", error);
821
+ });
822
+ }
823
+ return value;
824
+ } catch {
825
+ }
826
+ }
779
827
  const entry = {
780
828
  scope,
781
829
  status: "pending",
@@ -791,7 +839,7 @@ var ModuleCache = class {
791
839
  };
792
840
  this.scheduleGC(key, entry);
793
841
  const startedAt = performance.now();
794
- const buildEffect = yieldEffect(yieldDecision.strategy).pipe(import_effect4.Effect.zipRight(factory(scope)));
842
+ const buildEffect = yieldEffect(yieldDecision.strategy).pipe(import_effect4.Effect.flatMap(() => factory(scope)));
795
843
  const fiber = this.runtime.runFork(buildEffect);
796
844
  entry.fiber = fiber;
797
845
  const promise = this.runtime.runPromise(import_effect4.Fiber.await(fiber)).then((exit) => {
@@ -987,6 +1035,49 @@ var ModuleCache = class {
987
1035
  throw error;
988
1036
  }
989
1037
  }
1038
+ warmSync(key, factory, gcTime, ownerId, options) {
1039
+ const existing = this.entries.get(key);
1040
+ if (existing) {
1041
+ if ((0, import_Env.isDevEnv)() && existing.ownerId !== void 0 && ownerId !== void 0 && existing.ownerId !== ownerId) {
1042
+ throw new Error(
1043
+ `[ModuleCache.warmSync] resource key "${key}" has already been claimed by module "${existing.ownerId}", but is now requested by module "${ownerId}".`
1044
+ );
1045
+ }
1046
+ if (existing.status === "success") {
1047
+ return existing.value;
1048
+ }
1049
+ return void 0;
1050
+ }
1051
+ const scope = this.runtime.runSync(import_effect4.Scope.make());
1052
+ const startedAt = performance.now();
1053
+ const workloadKey = `${options?.entrypoint ?? "unknown"}::${ownerId ?? "unknown"}`;
1054
+ try {
1055
+ const value = this.runtime.runSync(factory(scope));
1056
+ const durationMs = performance.now() - startedAt;
1057
+ YieldBudgetMemory.record({ runtime: this.runtime, workloadKey, durationMs });
1058
+ const entry = {
1059
+ scope,
1060
+ status: "success",
1061
+ promise: Promise.resolve(value),
1062
+ value,
1063
+ refCount: 0,
1064
+ preloadRefCount: 0,
1065
+ gcTime: gcTime ?? this.gcDelayMs,
1066
+ ownerId,
1067
+ createdBy: "preload",
1068
+ workloadKey,
1069
+ yieldStrategy: "none"
1070
+ };
1071
+ this.scheduleGC(key, entry);
1072
+ this.entries.set(key, entry);
1073
+ return value;
1074
+ } catch (error) {
1075
+ void this.runtime.runPromise(import_effect4.Scope.close(scope, import_effect4.Exit.fail(error))).catch((closeError) => {
1076
+ debugBestEffortFailure("[ModuleCache] Scope.close failed", closeError);
1077
+ });
1078
+ return void 0;
1079
+ }
1080
+ }
990
1081
  preload(key, factory, options) {
991
1082
  const existing = this.entries.get(key);
992
1083
  if (existing) {
@@ -1016,6 +1107,38 @@ var ModuleCache = class {
1016
1107
  const gcTime = options?.gcTime ?? this.gcDelayMs;
1017
1108
  const workloadKey = `${options?.entrypoint ?? "unknown"}::${ownerId ?? "unknown"}`;
1018
1109
  const yieldDecision = decideYieldStrategy(this.runtime, workloadKey, options?.yield);
1110
+ const optimisticSyncBudgetMs = options?.optimisticSyncBudgetMs ?? 0;
1111
+ const shouldTryOptimisticSync = options?.policyMode === "defer" && optimisticSyncBudgetMs > 0;
1112
+ if (shouldTryOptimisticSync) {
1113
+ const startedAt2 = performance.now();
1114
+ try {
1115
+ const value = this.runtime.runSync(factory(scope));
1116
+ const durationMs = performance.now() - startedAt2;
1117
+ YieldBudgetMemory.record({ runtime: this.runtime, workloadKey, durationMs });
1118
+ const entry2 = {
1119
+ scope,
1120
+ status: "success",
1121
+ promise: Promise.resolve(value),
1122
+ value,
1123
+ refCount: 0,
1124
+ preloadRefCount: 1,
1125
+ gcTime,
1126
+ ownerId,
1127
+ createdBy: "preload",
1128
+ workloadKey,
1129
+ yieldStrategy: "none"
1130
+ };
1131
+ this.scheduleGC(key, entry2);
1132
+ this.entries.set(key, entry2);
1133
+ return {
1134
+ promise: Promise.resolve(value),
1135
+ cancel: () => {
1136
+ this.cancelPreload(key, entry2);
1137
+ }
1138
+ };
1139
+ } catch {
1140
+ }
1141
+ }
1019
1142
  const entry = {
1020
1143
  scope,
1021
1144
  status: "pending",
@@ -1031,7 +1154,7 @@ var ModuleCache = class {
1031
1154
  this.scheduleGC(key, entry);
1032
1155
  this.entries.set(key, entry);
1033
1156
  const startedAt = performance.now();
1034
- const buildEffect = yieldEffect(yieldDecision.strategy).pipe(import_effect4.Effect.zipRight(factory(scope)));
1157
+ const buildEffect = yieldEffect(yieldDecision.strategy).pipe(import_effect4.Effect.flatMap(() => factory(scope)));
1035
1158
  const fiber = this.runtime.runFork(buildEffect);
1036
1159
  entry.fiber = fiber;
1037
1160
  const promise = this.runtime.runPromise(import_effect4.Fiber.await(fiber)).then((exit) => {
@@ -1270,6 +1393,9 @@ var RuntimeProvider = ({
1270
1393
  }) => {
1271
1394
  const parent = (0, import_react4.useContext)(RuntimeContext);
1272
1395
  const baseRuntime = useRuntimeResolution(runtime, parent);
1396
+ const providerStartedAtRef = import_react4.default.useRef(performance.now());
1397
+ const providerReadyAtRef = import_react4.default.useRef(void 0);
1398
+ const didReportProviderGatingRef = import_react4.default.useRef(false);
1273
1399
  const resolvedPolicy = (0, import_react4.useMemo)(
1274
1400
  () => resolveRuntimeProviderPolicy({
1275
1401
  policy,
@@ -1309,7 +1435,7 @@ var RuntimeProvider = ({
1309
1435
  moduleId: event.moduleId,
1310
1436
  instanceId: event.instanceId,
1311
1437
  runtimeLabel: event.runtimeLabel
1312
- }).pipe(import_effect5.Effect.catchAllCause(() => import_effect5.Effect.void));
1438
+ }).pipe(import_effect5.Effect.catchCause(() => import_effect5.Effect.void));
1313
1439
  }
1314
1440
  if (event.type === "diagnostic" && event.severity === "error") {
1315
1441
  return handler(
@@ -1328,7 +1454,7 @@ var RuntimeProvider = ({
1328
1454
  instanceId: event.instanceId,
1329
1455
  runtimeLabel: event.runtimeLabel
1330
1456
  }
1331
- ).pipe(import_effect5.Effect.catchAllCause(() => import_effect5.Effect.void));
1457
+ ).pipe(import_effect5.Effect.catchCause(() => import_effect5.Effect.void));
1332
1458
  }
1333
1459
  return import_effect5.Effect.void;
1334
1460
  }
@@ -1343,9 +1469,7 @@ var RuntimeProvider = ({
1343
1469
  return layerBinding.debugSinks;
1344
1470
  }
1345
1471
  try {
1346
- return baseRuntime.runSync(
1347
- import_effect5.FiberRef.get(Logix5.Debug.internal.currentDebugSinks)
1348
- );
1472
+ return baseRuntime.runSync(import_effect5.Effect.service(Logix5.Debug.internal.currentDebugSinks).pipe(import_effect5.Effect.orDie));
1349
1473
  } catch {
1350
1474
  return [];
1351
1475
  }
@@ -1472,6 +1596,41 @@ var RuntimeProvider = ({
1472
1596
  const resolveFallback = (phase) => {
1473
1597
  return resolveRuntimeProviderFallback({ fallback, phase, policyMode: resolvedPolicy.mode });
1474
1598
  };
1599
+ const preloadCache = (0, import_react4.useMemo)(
1600
+ () => getModuleCache(runtimeWithBindings, configState.snapshot, configState.version),
1601
+ [runtimeWithBindings, configState.snapshot, configState.version]
1602
+ );
1603
+ const syncWarmPreloadReady = (0, import_react4.useMemo)(() => {
1604
+ if (resolvedPolicy.mode !== "defer") return false;
1605
+ if (!resolvedPolicy.preload) return true;
1606
+ if (!isLayerReady || !isConfigReady) return false;
1607
+ const handles = resolvedPolicy.preload.handles;
1608
+ if (handles.length === 0) return true;
1609
+ for (const handle of handles) {
1610
+ if (handle?._tag === "ModuleImpl") {
1611
+ const moduleId = handle.module?.id ?? "ModuleImpl";
1612
+ const key2 = resolvedPolicy.preload.keysByModuleId.get(moduleId) ?? getPreloadKeyForModuleId(moduleId);
1613
+ const factory2 = (scope) => import_effect5.Layer.buildWithScope(handle.layer, scope).pipe(
1614
+ import_effect5.Effect.map((context) => import_effect5.ServiceMap.get(context, handle.module))
1615
+ );
1616
+ const value2 = preloadCache.warmSync(key2, factory2, configState.snapshot.gcTime, moduleId, {
1617
+ entrypoint: "react.runtime.preload.sync-warm",
1618
+ policyMode: "defer"
1619
+ });
1620
+ if (!value2) return false;
1621
+ continue;
1622
+ }
1623
+ const tagId = handle.id ?? "ModuleTag";
1624
+ const key = resolvedPolicy.preload.keysByTagId.get(tagId) ?? getPreloadKeyForTagId(tagId);
1625
+ const factory = (scope) => import_effect5.Scope.provide(scope)(import_effect5.Effect.service(handle).pipe(import_effect5.Effect.orDie));
1626
+ const value = preloadCache.warmSync(key, factory, configState.snapshot.gcTime, tagId, {
1627
+ entrypoint: "react.runtime.preload.sync-warm",
1628
+ policyMode: "defer"
1629
+ });
1630
+ if (!value) return false;
1631
+ }
1632
+ return true;
1633
+ }, [resolvedPolicy, isLayerReady, isConfigReady, preloadCache, configState.snapshot.gcTime]);
1475
1634
  const [deferReady, setDeferReady] = (0, import_react4.useState)(false);
1476
1635
  (0, import_react4.useEffect)(() => {
1477
1636
  if (resolvedPolicy.mode !== "defer") {
@@ -1485,6 +1644,10 @@ var RuntimeProvider = ({
1485
1644
  if (resolvedPolicy.mode !== "defer") {
1486
1645
  return;
1487
1646
  }
1647
+ if (syncWarmPreloadReady) {
1648
+ setDeferReady(true);
1649
+ return;
1650
+ }
1488
1651
  setDeferReady(false);
1489
1652
  if (!resolvedPolicy.preload) {
1490
1653
  setDeferReady(true);
@@ -1494,7 +1657,7 @@ var RuntimeProvider = ({
1494
1657
  return;
1495
1658
  }
1496
1659
  let cancelled = false;
1497
- const cache = getModuleCache(runtimeWithBindings, configState.snapshot, configState.version);
1660
+ const cache = preloadCache;
1498
1661
  const preloadHandles = resolvedPolicy.preload.handles;
1499
1662
  if (preloadHandles.length === 0) {
1500
1663
  setDeferReady(true);
@@ -1512,13 +1675,14 @@ var RuntimeProvider = ({
1512
1675
  const moduleId = handle.module?.id ?? "ModuleImpl";
1513
1676
  const key2 = resolvedPolicy.preload.keysByModuleId.get(moduleId) ?? getPreloadKeyForModuleId(moduleId);
1514
1677
  const factory2 = (scope) => import_effect5.Layer.buildWithScope(handle.layer, scope).pipe(
1515
- import_effect5.Effect.map((context) => import_effect5.Context.get(context, handle.module))
1678
+ import_effect5.Effect.map((context) => import_effect5.ServiceMap.get(context, handle.module))
1516
1679
  );
1517
1680
  const op2 = cache.preload(key2, factory2, {
1518
1681
  ownerId: moduleId,
1519
1682
  yield: resolvedPolicy.preload.yield,
1520
1683
  entrypoint: "react.runtime.preload",
1521
- policyMode: "defer"
1684
+ policyMode: "defer",
1685
+ optimisticSyncBudgetMs: resolvedPolicy.syncBudgetMs
1522
1686
  });
1523
1687
  allCancels.add(op2.cancel);
1524
1688
  await op2.promise;
@@ -1543,14 +1707,13 @@ var RuntimeProvider = ({
1543
1707
  }
1544
1708
  const tagId = handle.id ?? "ModuleTag";
1545
1709
  const key = resolvedPolicy.preload.keysByTagId.get(tagId) ?? getPreloadKeyForTagId(tagId);
1546
- const factory = (scope) => handle.pipe(
1547
- import_effect5.Scope.extend(scope)
1548
- );
1710
+ const factory = (scope) => import_effect5.Scope.provide(scope)(import_effect5.Effect.service(handle).pipe(import_effect5.Effect.orDie));
1549
1711
  const op = cache.preload(key, factory, {
1550
1712
  ownerId: tagId,
1551
1713
  yield: resolvedPolicy.preload.yield,
1552
1714
  entrypoint: "react.runtime.preload",
1553
- policyMode: "defer"
1715
+ policyMode: "defer",
1716
+ optimisticSyncBudgetMs: resolvedPolicy.syncBudgetMs
1554
1717
  });
1555
1718
  allCancels.add(op.cancel);
1556
1719
  await op.promise;
@@ -1588,7 +1751,7 @@ var RuntimeProvider = ({
1588
1751
  if (cancelled) return;
1589
1752
  if (onErrorRef.current) {
1590
1753
  runtimeWithBindings.runFork(
1591
- onErrorRef.current(import_effect5.Cause.die(error), { source: "provider", phase: "provider.layer.build" }).pipe(import_effect5.Effect.catchAllCause(() => import_effect5.Effect.void))
1754
+ onErrorRef.current(import_effect5.Cause.die(error), { source: "provider", phase: "provider.layer.build" }).pipe(import_effect5.Effect.catchCause(() => import_effect5.Effect.void))
1592
1755
  );
1593
1756
  }
1594
1757
  setDeferReady(true);
@@ -1621,13 +1784,54 @@ var RuntimeProvider = ({
1621
1784
  release();
1622
1785
  };
1623
1786
  }, [resolvedPolicy.mode, deferReady]);
1624
- const isReady = isTickServicesReady && isLayerReady && isConfigReady && (resolvedPolicy.mode !== "defer" || deferReady);
1787
+ const isReady = isTickServicesReady && isLayerReady && isConfigReady && (resolvedPolicy.mode !== "defer" || deferReady || syncWarmPreloadReady);
1788
+ if (isReady && providerReadyAtRef.current === void 0) {
1789
+ providerReadyAtRef.current = performance.now();
1790
+ }
1791
+ (0, import_react4.useEffect)(() => {
1792
+ if (!isReady) {
1793
+ return;
1794
+ }
1795
+ if (didReportProviderGatingRef.current) {
1796
+ return;
1797
+ }
1798
+ let diagnosticsLevel = "off";
1799
+ try {
1800
+ diagnosticsLevel = runtimeWithBindings.runSync(
1801
+ import_effect5.Effect.service(Logix5.Debug.internal.currentDiagnosticsLevel).pipe(import_effect5.Effect.orDie)
1802
+ );
1803
+ } catch {
1804
+ diagnosticsLevel = (0, import_Env.isDevEnv)() ? "light" : "off";
1805
+ }
1806
+ if (diagnosticsLevel === "off") {
1807
+ return;
1808
+ }
1809
+ didReportProviderGatingRef.current = true;
1810
+ const readyAt = providerReadyAtRef.current ?? performance.now();
1811
+ const durationMs = Math.round((readyAt - providerStartedAtRef.current) * 100) / 100;
1812
+ const effectDelayMs = Math.round((performance.now() - readyAt) * 100) / 100;
1813
+ void runtimeWithBindings.runPromise(
1814
+ Logix5.Debug.record({
1815
+ type: "trace:react.provider.gating",
1816
+ data: {
1817
+ event: "ready",
1818
+ policyMode: resolvedPolicy.mode,
1819
+ durationMs,
1820
+ effectDelayMs,
1821
+ configLoadMode: configState.loadMode,
1822
+ syncOverBudget: Boolean(configState.syncOverBudget),
1823
+ syncDurationMs: configState.syncDurationMs !== void 0 ? Math.round(configState.syncDurationMs * 100) / 100 : void 0
1824
+ }
1825
+ })
1826
+ ).catch(() => {
1827
+ });
1828
+ }, [configState.loadMode, configState.syncDurationMs, configState.syncOverBudget, isReady, resolvedPolicy.mode, runtimeWithBindings]);
1625
1829
  if (!isReady) {
1626
1830
  const blockersList = [
1627
1831
  isTickServicesReady ? null : "tick",
1628
1832
  isLayerReady ? null : "layer",
1629
1833
  isConfigReady ? null : "config",
1630
- resolvedPolicy.mode !== "defer" || deferReady ? null : "preload"
1834
+ resolvedPolicy.mode !== "defer" || deferReady || syncWarmPreloadReady ? null : "preload"
1631
1835
  ].filter((x) => x !== null);
1632
1836
  const blockers = blockersList.length > 0 ? blockersList.join("+") : void 0;
1633
1837
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
@@ -1740,13 +1944,13 @@ function useRuntime(options) {
1740
1944
 
1741
1945
  // src/internal/hooks/useModule.ts
1742
1946
  var import_react9 = __toESM(require("react"), 1);
1743
- var Logix10 = __toESM(require("@logixjs/core"), 1);
1744
- var import_effect9 = require("effect");
1947
+ var Logix11 = __toESM(require("@logixjs/core"), 1);
1948
+ var import_effect10 = require("effect");
1745
1949
 
1746
1950
  // src/internal/hooks/useModuleRuntime.ts
1747
1951
  var import_react6 = require("react");
1748
- var Logix6 = __toESM(require("@logixjs/core"), 1);
1749
- var import_effect7 = require("effect");
1952
+ var Logix7 = __toESM(require("@logixjs/core"), 1);
1953
+ var import_effect8 = require("effect");
1750
1954
 
1751
1955
  // src/internal/store/ModuleRef.ts
1752
1956
  var isModuleRef = (value) => typeof value === "object" && value !== null && "runtime" in value && "actions" in value && "dispatch" in value;
@@ -1837,11 +2041,26 @@ var applyHandleExtend = (tag, runtime, base) => {
1837
2041
  return { ...base, ...next };
1838
2042
  };
1839
2043
 
2044
+ // src/internal/provider/runtimeDebugBridge.ts
2045
+ var import_effect7 = require("effect");
2046
+ var Logix6 = __toESM(require("@logixjs/core"), 1);
2047
+ var readRuntimeDiagnosticsLevel = (runtime) => {
2048
+ try {
2049
+ return runtime.runSync(import_effect7.Effect.service(Logix6.Debug.internal.currentDiagnosticsLevel).pipe(import_effect7.Effect.orDie));
2050
+ } catch {
2051
+ return (0, import_Env.isDevEnv)() ? "light" : "off";
2052
+ }
2053
+ };
2054
+ var emitRuntimeDebugEventBestEffort = (runtime, event) => {
2055
+ runtime.runFork(event);
2056
+ };
2057
+
1840
2058
  // src/internal/hooks/useModuleRuntime.ts
1841
2059
  var isModuleRuntime = (value) => typeof value === "object" && value !== null && "dispatch" in value && "getState" in value;
1842
2060
  function useModuleRuntime(handle) {
1843
2061
  const runtime = useRuntime();
1844
2062
  const runtimeContext = (0, import_react6.useContext)(RuntimeContext);
2063
+ const moduleTagResolveTraceRef = (0, import_react6.useRef)(void 0);
1845
2064
  if (!runtimeContext) {
1846
2065
  throw new RuntimeProviderNotFoundError("useModuleRuntime");
1847
2066
  }
@@ -1862,36 +2081,48 @@ function useModuleRuntime(handle) {
1862
2081
  const preloadKey = runtimeContext.policy.preload?.keysByTagId.get(tokenId);
1863
2082
  const key = preloadKey ?? `tag:${tokenId}`;
1864
2083
  const mode = runtimeContext.policy.moduleTagMode;
1865
- const factory = (scope) => tag.pipe(import_effect7.Scope.extend(scope));
1866
- return mode === "suspend" ? cache.read(key, factory, void 0, tokenId, {
2084
+ const startedAtMs = performance.now();
2085
+ const factory = (scope) => import_effect8.Scope.provide(scope)(import_effect8.Effect.service(tag).pipe(import_effect8.Effect.orDie));
2086
+ const resolvedRuntime = mode === "suspend" ? cache.read(key, factory, void 0, tokenId, {
1867
2087
  entrypoint: "react.useModuleRuntime",
1868
2088
  policyMode: runtimeContext.policy.mode,
1869
- yield: runtimeContext.policy.yield
2089
+ yield: runtimeContext.policy.yield,
2090
+ optimisticSyncBudgetMs: runtimeContext.policy.syncBudgetMs
1870
2091
  }) : cache.readSync(key, factory, void 0, tokenId, {
1871
2092
  entrypoint: "react.useModuleRuntime",
1872
2093
  policyMode: runtimeContext.policy.mode,
1873
2094
  warnSyncBlockingThresholdMs: 5
1874
2095
  });
2096
+ moduleTagResolveTraceRef.current = {
2097
+ tokenId,
2098
+ durationMs: Math.round((performance.now() - startedAtMs) * 100) / 100,
2099
+ cacheMode: mode
2100
+ };
2101
+ return resolvedRuntime;
1875
2102
  }, [cache, runtimeContext.policy, handle]);
1876
2103
  (0, import_react6.useEffect)(() => {
1877
2104
  if (!isTagHandle) {
1878
2105
  return;
1879
2106
  }
1880
- if (!(0, import_Env.isDevEnv)() && !Logix6.Debug.isDevtoolsEnabled()) {
2107
+ const diagnosticsLevel = readRuntimeDiagnosticsLevel(runtime);
2108
+ if (diagnosticsLevel === "off") {
1881
2109
  return;
1882
2110
  }
1883
2111
  const tokenId = handle?.id ?? "ModuleTag";
1884
- const effect = Logix6.Debug.record({
2112
+ const trace = moduleTagResolveTraceRef.current;
2113
+ const effect = Logix7.Debug.record({
1885
2114
  type: "trace:react.moduleTag.resolve",
1886
2115
  moduleId: resolved.moduleId,
1887
2116
  instanceId: resolved.instanceId,
1888
2117
  data: {
1889
2118
  mode: runtimeContext.policy.moduleTagMode,
1890
2119
  tokenId,
1891
- yieldStrategy: runtimeContext.policy.yield.strategy
2120
+ yieldStrategy: runtimeContext.policy.yield.strategy,
2121
+ durationMs: trace?.durationMs,
2122
+ cacheMode: trace?.cacheMode ?? runtimeContext.policy.moduleTagMode
1892
2123
  }
1893
2124
  });
1894
- runtime.runFork(effect);
2125
+ emitRuntimeDebugEventBestEffort(runtime, effect);
1895
2126
  }, [runtime, runtimeContext.policy, resolved, handle, isTagHandle]);
1896
2127
  return resolved;
1897
2128
  }
@@ -1899,11 +2130,11 @@ function useModuleRuntime(handle) {
1899
2130
  // src/internal/hooks/useSelector.ts
1900
2131
  var import_react7 = require("react");
1901
2132
  var import_with_selector = require("use-sync-external-store/shim/with-selector");
1902
- var Logix8 = __toESM(require("@logixjs/core"), 1);
2133
+ var Logix9 = __toESM(require("@logixjs/core"), 1);
1903
2134
 
1904
2135
  // src/internal/store/RuntimeExternalStore.ts
1905
- var Logix7 = __toESM(require("@logixjs/core"), 1);
1906
- var import_effect8 = require("effect");
2136
+ var Logix8 = __toESM(require("@logixjs/core"), 1);
2137
+ var import_effect9 = require("effect");
1907
2138
  var storesByRuntime = /* @__PURE__ */ new WeakMap();
1908
2139
  var getStoreMapForRuntime = (runtime) => {
1909
2140
  const cached = storesByRuntime.get(runtime);
@@ -1914,8 +2145,8 @@ var getStoreMapForRuntime = (runtime) => {
1914
2145
  };
1915
2146
  var makeModuleInstanceKey = (moduleId, instanceId) => `${moduleId}::${instanceId}`;
1916
2147
  var makeReadQueryTopicKey = (moduleInstanceKey, selectorId) => `${moduleInstanceKey}::rq:${selectorId}`;
1917
- var getRuntimeStore = (runtime) => Logix7.InternalContracts.getRuntimeStore(runtime);
1918
- var getHostScheduler = (runtime) => Logix7.InternalContracts.getHostScheduler(runtime);
2148
+ var getRuntimeStore = (runtime) => Logix8.InternalContracts.getRuntimeStore(runtime);
2149
+ var getHostScheduler = (runtime) => Logix8.InternalContracts.getHostScheduler(runtime);
1919
2150
  var getOrCreateStore = (runtime, topicKey, make) => {
1920
2151
  const map = getStoreMapForRuntime(runtime);
1921
2152
  const cached = map.get(topicKey);
@@ -1939,6 +2170,8 @@ var makeTopicExternalStore = (args) => {
1939
2170
  let currentSnapshot;
1940
2171
  const listeners = /* @__PURE__ */ new Set();
1941
2172
  let unsubscribeFromRuntimeStore;
2173
+ let teardownScheduled = false;
2174
+ let teardownToken = 0;
1942
2175
  const lowPriorityDelayMs = args.options?.lowPriorityDelayMs ?? 16;
1943
2176
  const lowPriorityMaxDelayMs = args.options?.lowPriorityMaxDelayMs ?? 50;
1944
2177
  let notifyScheduled = false;
@@ -2023,7 +2256,38 @@ var makeTopicExternalStore = (args) => {
2023
2256
  currentSnapshot = next;
2024
2257
  return next;
2025
2258
  };
2259
+ const cancelScheduledTeardown = () => {
2260
+ if (!teardownScheduled) return;
2261
+ teardownScheduled = false;
2262
+ teardownToken += 1;
2263
+ };
2264
+ const finalizeTeardown = () => {
2265
+ if (listeners.size > 0) return;
2266
+ try {
2267
+ args.onLastListener?.();
2268
+ } catch {
2269
+ }
2270
+ const unsub = unsubscribeFromRuntimeStore;
2271
+ unsubscribeFromRuntimeStore = void 0;
2272
+ cancelLow();
2273
+ try {
2274
+ unsub?.();
2275
+ } catch {
2276
+ }
2277
+ removeStore(runtime, topicKey);
2278
+ };
2279
+ const scheduleTeardown = () => {
2280
+ if (teardownScheduled) return;
2281
+ teardownScheduled = true;
2282
+ const token = ++teardownToken;
2283
+ hostScheduler.scheduleMicrotask(() => {
2284
+ if (!teardownScheduled || token !== teardownToken) return;
2285
+ teardownScheduled = false;
2286
+ finalizeTeardown();
2287
+ });
2288
+ };
2026
2289
  const subscribe = (listener) => {
2290
+ cancelScheduledTeardown();
2027
2291
  const isFirst = listeners.size === 0;
2028
2292
  listeners.add(listener);
2029
2293
  ensureSubscription();
@@ -2037,18 +2301,7 @@ var makeTopicExternalStore = (args) => {
2037
2301
  return () => {
2038
2302
  listeners.delete(listener);
2039
2303
  if (listeners.size > 0) return;
2040
- try {
2041
- args.onLastListener?.();
2042
- } catch {
2043
- }
2044
- const unsub = unsubscribeFromRuntimeStore;
2045
- unsubscribeFromRuntimeStore = void 0;
2046
- cancelLow();
2047
- try {
2048
- unsub?.();
2049
- } catch {
2050
- }
2051
- removeStore(runtime, topicKey);
2304
+ scheduleTeardown();
2052
2305
  };
2053
2306
  };
2054
2307
  return { getSnapshot, getServerSnapshot: getSnapshot, subscribe };
@@ -2092,14 +2345,14 @@ var getRuntimeReadQueryExternalStore = (runtime, moduleRuntime, selectorReadQuer
2092
2345
  options,
2093
2346
  onFirstListener: () => {
2094
2347
  if (readQueryDrainFiber) return;
2095
- const effect = import_effect8.Stream.runDrain(moduleRuntime.changesReadQueryWithMeta(selectorReadQuery));
2348
+ const effect = import_effect9.Stream.runDrain(moduleRuntime.changesReadQueryWithMeta(selectorReadQuery));
2096
2349
  readQueryDrainFiber = runtime.runFork(effect);
2097
2350
  },
2098
2351
  onLastListener: () => {
2099
2352
  const fiber = readQueryDrainFiber;
2100
2353
  if (!fiber) return;
2101
2354
  readQueryDrainFiber = void 0;
2102
- runtime.runFork(import_effect8.Fiber.interrupt(fiber));
2355
+ runtime.runFork(import_effect9.Fiber.interrupt(fiber));
2103
2356
  }
2104
2357
  })
2105
2358
  );
@@ -2165,7 +2418,7 @@ function useSelector(handle, selector, equalityFn) {
2165
2418
  const moduleRuntime = useModuleRuntime(handle);
2166
2419
  const actualSelector = selector ?? ((state) => state);
2167
2420
  const selectorReadQuery = (0, import_react7.useMemo)(
2168
- () => typeof selector === "function" ? Logix8.ReadQuery.compile(selector) : void 0,
2421
+ () => typeof selector === "function" ? Logix9.ReadQuery.compile(selector) : void 0,
2169
2422
  [selector]
2170
2423
  );
2171
2424
  const actualEqualityFn = (0, import_react7.useMemo)(() => {
@@ -2203,7 +2456,7 @@ function useSelector(handle, selector, equalityFn) {
2203
2456
  actualEqualityFn
2204
2457
  );
2205
2458
  (0, import_react7.useEffect)(() => {
2206
- if (!(0, import_Env.isDevEnv)() && !Logix8.Debug.isDevtoolsEnabled()) {
2459
+ if (!(0, import_Env.isDevEnv)() && !Logix9.Debug.isDevtoolsEnabled()) {
2207
2460
  return;
2208
2461
  }
2209
2462
  const instanceId = moduleRuntime.instanceId;
@@ -2219,7 +2472,7 @@ function useSelector(handle, selector, equalityFn) {
2219
2472
  const rawDebugKey = meta.debugKey;
2220
2473
  selectorKey = typeof rawDebugKey === "string" && rawDebugKey.length > 0 ? rawDebugKey : typeof selector.name === "string" && selector.name.length > 0 ? selector.name : void 0;
2221
2474
  }
2222
- const effect = Logix8.Debug.record({
2475
+ const effect = Logix9.Debug.record({
2223
2476
  type: "trace:react-selector",
2224
2477
  moduleId: moduleRuntime.moduleId,
2225
2478
  instanceId,
@@ -2242,7 +2495,7 @@ function useSelector(handle, selector, equalityFn) {
2242
2495
  }
2243
2496
 
2244
2497
  // src/internal/store/resolveImportedModuleRef.ts
2245
- var Logix9 = __toESM(require("@logixjs/core"), 1);
2498
+ var Logix10 = __toESM(require("@logixjs/core"), 1);
2246
2499
  var getOrCreateWeakMap = (map, key, make) => {
2247
2500
  const cached = map.get(key);
2248
2501
  if (cached) return cached;
@@ -2266,7 +2519,7 @@ var resolveImportedModuleRef = (runtime, parentRuntime, module2) => {
2266
2519
  if (cached) {
2267
2520
  return cached;
2268
2521
  }
2269
- const importsScope = Logix9.InternalContracts.getImportsScope(parentRuntime);
2522
+ const importsScope = Logix10.InternalContracts.getImportsScope(parentRuntime);
2270
2523
  const childRuntime = importsScope.get(module2);
2271
2524
  if (childRuntime) {
2272
2525
  const dispatch = Object.assign(
@@ -2352,8 +2605,8 @@ var useStableId = () => {
2352
2605
 
2353
2606
  // src/internal/hooks/useModule.ts
2354
2607
  var isModuleImpl2 = (handle) => Boolean(handle) && typeof handle === "object" && handle._tag === "ModuleImpl";
2355
- var isModule = (handle) => Logix10.Module.hasImpl(handle);
2356
- var isModuleDef = (handle) => Logix10.Module.is(handle) && handle._kind === "ModuleDef";
2608
+ var isModule = (handle) => Logix11.Module.hasImpl(handle);
2609
+ var isModuleDef = (handle) => Logix11.Module.is(handle) && handle._kind === "ModuleDef";
2357
2610
  function useModule(handle, selectorOrOptions, equalityFn) {
2358
2611
  const runtimeBase = useRuntime();
2359
2612
  const runtimeContext = import_react9.default.useContext(RuntimeContext);
@@ -2377,6 +2630,7 @@ function useModule(handle, selectorOrOptions, equalityFn) {
2377
2630
  }
2378
2631
  }
2379
2632
  let runtime;
2633
+ const moduleImplResolveTraceRef = import_react9.default.useRef(void 0);
2380
2634
  if (isModuleImpl2(normalizedHandle)) {
2381
2635
  const cache = import_react9.default.useMemo(
2382
2636
  () => getModuleCache(runtimeBase, runtimeContext.reactConfigSnapshot, runtimeContext.configVersion),
@@ -2405,9 +2659,9 @@ function useModule(handle, selectorOrOptions, equalityFn) {
2405
2659
  const key = depsHash ? `${baseKey}:${depsHash}` : baseKey;
2406
2660
  const ownerId = moduleId;
2407
2661
  const baseFactory = import_react9.default.useMemo(
2408
- () => (scope) => import_effect9.Layer.buildWithScope(normalizedHandle.layer, scope).pipe(
2409
- import_effect9.Effect.map(
2410
- (context) => import_effect9.Context.get(context, normalizedHandle.module)
2662
+ () => (scope) => import_effect10.Layer.buildWithScope(import_effect10.Layer.fresh(normalizedHandle.layer), scope).pipe(
2663
+ import_effect10.Effect.map(
2664
+ (context) => import_effect10.ServiceMap.get(context, normalizedHandle.module)
2411
2665
  )
2412
2666
  ),
2413
2667
  [normalizedHandle]
@@ -2417,26 +2671,56 @@ function useModule(handle, selectorOrOptions, equalityFn) {
2417
2671
  return baseFactory;
2418
2672
  }
2419
2673
  return (scope) => baseFactory(scope).pipe(
2420
- import_effect9.Effect.timeoutFail({
2421
- duration: initTimeoutMs,
2422
- onTimeout: () => new Error(`[useModule] Module "${ownerId}" initialization timed out after ${initTimeoutMs}ms`)
2423
- })
2674
+ import_effect10.Effect.timeoutOption(initTimeoutMs),
2675
+ import_effect10.Effect.flatMap(
2676
+ (maybe) => maybe._tag === "Some" ? import_effect10.Effect.succeed(maybe.value) : import_effect10.Effect.die(new Error(`[useModule] Module "${ownerId}" initialization timed out after ${initTimeoutMs}ms`))
2677
+ )
2424
2678
  );
2425
2679
  }, [baseFactory, suspend, initTimeoutMs, ownerId]);
2680
+ const moduleResolveStartedAt = performance.now();
2426
2681
  const moduleRuntime = suspend ? cache.read(key, factory, gcTime, ownerId, {
2427
2682
  entrypoint: "react.useModule",
2428
2683
  policyMode: runtimeContext.policy.mode,
2429
- yield: runtimeContext.policy.yield
2684
+ yield: runtimeContext.policy.yield,
2685
+ optimisticSyncBudgetMs: runtimeContext.policy.syncBudgetMs
2430
2686
  }) : cache.readSync(key, factory, gcTime, ownerId, {
2431
2687
  entrypoint: "react.useModule",
2432
2688
  policyMode: runtimeContext.policy.mode,
2433
2689
  warnSyncBlockingThresholdMs: 5
2434
2690
  });
2691
+ moduleImplResolveTraceRef.current = {
2692
+ moduleId,
2693
+ cacheMode: suspend ? "suspend" : "sync",
2694
+ durationMs: Math.round((performance.now() - moduleResolveStartedAt) * 100) / 100
2695
+ };
2435
2696
  import_react9.default.useEffect(() => cache.retain(key), [cache, key]);
2436
2697
  runtime = moduleRuntime;
2437
2698
  } else {
2438
2699
  runtime = useModuleRuntime(normalizedHandle);
2439
2700
  }
2701
+ import_react9.default.useEffect(() => {
2702
+ if (!isModuleImpl2(normalizedHandle)) {
2703
+ return;
2704
+ }
2705
+ const diagnosticsLevel = readRuntimeDiagnosticsLevel(runtimeBase);
2706
+ if (diagnosticsLevel === "off") {
2707
+ return;
2708
+ }
2709
+ const trace = moduleImplResolveTraceRef.current;
2710
+ if (!trace) {
2711
+ return;
2712
+ }
2713
+ const effect = Logix11.Debug.record({
2714
+ type: "trace:react.moduleImpl.resolve",
2715
+ moduleId: trace.moduleId,
2716
+ instanceId: runtime.instanceId,
2717
+ data: {
2718
+ cacheMode: trace.cacheMode,
2719
+ durationMs: trace.durationMs
2720
+ }
2721
+ });
2722
+ emitRuntimeDebugEventBestEffort(runtimeBase, effect);
2723
+ }, [runtimeBase, runtime, normalizedHandle]);
2440
2724
  import_react9.default.useEffect(() => {
2441
2725
  if (!isModuleImpl2(normalizedHandle)) {
2442
2726
  return;
@@ -2446,22 +2730,22 @@ function useModule(handle, selectorOrOptions, equalityFn) {
2446
2730
  if (!label) {
2447
2731
  return;
2448
2732
  }
2449
- const effect = Logix10.Debug.record({
2733
+ const effect = Logix11.Debug.record({
2450
2734
  type: "trace:instanceLabel",
2451
2735
  moduleId: normalizedHandle.module.id,
2452
2736
  instanceId: runtime.instanceId,
2453
2737
  data: { label }
2454
2738
  });
2455
- runtimeBase.runFork(effect);
2739
+ emitRuntimeDebugEventBestEffort(runtimeBase, effect);
2456
2740
  }, [runtimeBase, runtime, normalizedHandle, options]);
2457
2741
  import_react9.default.useEffect(() => {
2458
- if (!(0, import_Env.isDevEnv)() && !Logix10.Debug.isDevtoolsEnabled()) {
2742
+ if (!(0, import_Env.isDevEnv)() && !Logix11.Debug.isDevtoolsEnabled()) {
2459
2743
  return;
2460
2744
  }
2461
2745
  if (!runtime.instanceId) {
2462
2746
  return;
2463
2747
  }
2464
- const effect = Logix10.Debug.record({
2748
+ const effect = Logix11.Debug.record({
2465
2749
  type: "trace:react-render",
2466
2750
  moduleId: runtime.moduleId,
2467
2751
  instanceId: runtime.instanceId,
@@ -2471,7 +2755,7 @@ function useModule(handle, selectorOrOptions, equalityFn) {
2471
2755
  }
2472
2756
  });
2473
2757
  runtimeBase.runFork(effect);
2474
- }, [runtimeBase, runtime]);
2758
+ });
2475
2759
  if (selector) {
2476
2760
  if (isModuleImpl2(normalizedHandle)) {
2477
2761
  return useSelector(runtime, selector, equalityFn);
@@ -2558,8 +2842,8 @@ function useModule(handle, selectorOrOptions, equalityFn) {
2558
2842
 
2559
2843
  // src/internal/hooks/useLocalModule.ts
2560
2844
  var import_react10 = __toESM(require("react"), 1);
2561
- var Logix11 = __toESM(require("@logixjs/core"), 1);
2562
- var import_effect10 = require("effect");
2845
+ var Logix12 = __toESM(require("@logixjs/core"), 1);
2846
+ var import_effect11 = require("effect");
2563
2847
  function isModuleTag2(source) {
2564
2848
  if (!source || typeof source !== "object" && typeof source !== "function") {
2565
2849
  return false;
@@ -2579,7 +2863,7 @@ function useLocalModule(source, second) {
2579
2863
  );
2580
2864
  const componentId = useStableId();
2581
2865
  const moduleTag = import_react10.default.useMemo(() => {
2582
- if (Logix11.Module.is(source)) {
2866
+ if (Logix12.Module.is(source)) {
2583
2867
  return source.tag;
2584
2868
  }
2585
2869
  if (isModuleTag2(source)) {
@@ -2588,7 +2872,7 @@ function useLocalModule(source, second) {
2588
2872
  return null;
2589
2873
  }, [source]);
2590
2874
  const def = import_react10.default.useMemo(() => {
2591
- if (Logix11.Module.is(source) || isModuleTag2(source)) {
2875
+ if (Logix12.Module.is(source) || isModuleTag2(source)) {
2592
2876
  return source;
2593
2877
  }
2594
2878
  return void 0;
@@ -2616,7 +2900,7 @@ function useLocalModule(source, second) {
2616
2900
  return createModuleTagFactory(moduleTag, moduleOptions);
2617
2901
  }
2618
2902
  const factoryFn = source;
2619
- return (scope) => factoryFn().pipe(import_effect10.Scope.extend(scope));
2903
+ return (scope) => import_effect11.Scope.provide(scope)(factoryFn());
2620
2904
  }, [isModule2, moduleTag, source, moduleOptions]);
2621
2905
  const moduleRuntime = cache.readSync(key, factory, void 0, ownerId, {
2622
2906
  entrypoint: "react.useLocalModule",
@@ -2676,9 +2960,9 @@ function createModuleTagFactory(module2, options) {
2676
2960
  throw new Error("useLocalModule(module, options) \u9700\u8981\u63D0\u4F9B initial \u72B6\u6001");
2677
2961
  }
2678
2962
  const logics = options.logics ?? [];
2679
- return (scope) => import_effect10.Layer.buildWithScope(module2.live(options.initial, ...logics), scope).pipe(
2680
- import_effect10.Effect.map((context) => {
2681
- const runtime = import_effect10.Context.get(context, module2);
2963
+ return (scope) => import_effect11.Layer.buildWithScope(module2.live(options.initial, ...logics), scope).pipe(
2964
+ import_effect11.Effect.map((context) => {
2965
+ const runtime = import_effect11.ServiceMap.get(context, module2);
2682
2966
  return runtime;
2683
2967
  })
2684
2968
  );
@@ -2686,7 +2970,7 @@ function createModuleTagFactory(module2, options) {
2686
2970
 
2687
2971
  // src/internal/hooks/useLayerModule.ts
2688
2972
  var import_react11 = __toESM(require("react"), 1);
2689
- var import_effect11 = require("effect");
2973
+ var import_effect12 = require("effect");
2690
2974
 
2691
2975
  // src/internal/hooks/useDispatch.ts
2692
2976
  var import_react12 = require("react");
@@ -2716,8 +3000,8 @@ var import_react14 = __toESM(require("react"), 1);
2716
3000
 
2717
3001
  // src/internal/hooks/useProcesses.ts
2718
3002
  var import_react15 = __toESM(require("react"), 1);
2719
- var import_effect12 = require("effect");
2720
- var Logix12 = __toESM(require("@logixjs/core"), 1);
3003
+ var import_effect13 = require("effect");
3004
+ var Logix13 = __toESM(require("@logixjs/core"), 1);
2721
3005
 
2722
3006
  // src/ReactPlatform.ts
2723
3007
  var import_react16 = __toESM(require("react"), 1);