@logixjs/react 0.1.1 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  ReactPlatform
3
- } from "./chunk-JC3R6GII.js";
4
- import "./chunk-WOTNVLCD.js";
5
- import "./chunk-G2LX7WWQ.js";
3
+ } from "./chunk-KYWW4KMQ.js";
4
+ import "./chunk-6NLXTHZ7.js";
5
+ import "./chunk-E3ZXST5F.js";
6
6
  import "./chunk-VFWWMK67.js";
7
- import "./chunk-2M6MDNVT.js";
8
- import "./chunk-2WFULYPJ.js";
7
+ import "./chunk-XSGDBJXD.js";
8
+ import "./chunk-L7KTYBXN.js";
9
9
  export {
10
10
  ReactPlatform
11
11
  };
@@ -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) => {
@@ -1239,6 +1362,9 @@ var RuntimeProvider = ({
1239
1362
  }) => {
1240
1363
  const parent = (0, import_react4.useContext)(RuntimeContext);
1241
1364
  const baseRuntime = useRuntimeResolution(runtime, parent);
1365
+ const providerStartedAtRef = import_react4.default.useRef(performance.now());
1366
+ const providerReadyAtRef = import_react4.default.useRef(void 0);
1367
+ const didReportProviderGatingRef = import_react4.default.useRef(false);
1242
1368
  const resolvedPolicy = (0, import_react4.useMemo)(
1243
1369
  () => resolveRuntimeProviderPolicy({
1244
1370
  policy,
@@ -1278,7 +1404,7 @@ var RuntimeProvider = ({
1278
1404
  moduleId: event.moduleId,
1279
1405
  instanceId: event.instanceId,
1280
1406
  runtimeLabel: event.runtimeLabel
1281
- }).pipe(import_effect5.Effect.catchAllCause(() => import_effect5.Effect.void));
1407
+ }).pipe(import_effect5.Effect.catchCause(() => import_effect5.Effect.void));
1282
1408
  }
1283
1409
  if (event.type === "diagnostic" && event.severity === "error") {
1284
1410
  return handler(
@@ -1297,7 +1423,7 @@ var RuntimeProvider = ({
1297
1423
  instanceId: event.instanceId,
1298
1424
  runtimeLabel: event.runtimeLabel
1299
1425
  }
1300
- ).pipe(import_effect5.Effect.catchAllCause(() => import_effect5.Effect.void));
1426
+ ).pipe(import_effect5.Effect.catchCause(() => import_effect5.Effect.void));
1301
1427
  }
1302
1428
  return import_effect5.Effect.void;
1303
1429
  }
@@ -1312,9 +1438,7 @@ var RuntimeProvider = ({
1312
1438
  return layerBinding.debugSinks;
1313
1439
  }
1314
1440
  try {
1315
- return baseRuntime.runSync(
1316
- import_effect5.FiberRef.get(Logix5.Debug.internal.currentDebugSinks)
1317
- );
1441
+ return baseRuntime.runSync(import_effect5.Effect.service(Logix5.Debug.internal.currentDebugSinks).pipe(import_effect5.Effect.orDie));
1318
1442
  } catch {
1319
1443
  return [];
1320
1444
  }
@@ -1441,6 +1565,41 @@ var RuntimeProvider = ({
1441
1565
  const resolveFallback = (phase) => {
1442
1566
  return resolveRuntimeProviderFallback({ fallback, phase, policyMode: resolvedPolicy.mode });
1443
1567
  };
1568
+ const preloadCache = (0, import_react4.useMemo)(
1569
+ () => getModuleCache(runtimeWithBindings, configState.snapshot, configState.version),
1570
+ [runtimeWithBindings, configState.snapshot, configState.version]
1571
+ );
1572
+ const syncWarmPreloadReady = (0, import_react4.useMemo)(() => {
1573
+ if (resolvedPolicy.mode !== "defer") return false;
1574
+ if (!resolvedPolicy.preload) return true;
1575
+ if (!isLayerReady || !isConfigReady) return false;
1576
+ const handles = resolvedPolicy.preload.handles;
1577
+ if (handles.length === 0) return true;
1578
+ for (const handle of handles) {
1579
+ if (handle?._tag === "ModuleImpl") {
1580
+ const moduleId = handle.module?.id ?? "ModuleImpl";
1581
+ const key2 = resolvedPolicy.preload.keysByModuleId.get(moduleId) ?? getPreloadKeyForModuleId(moduleId);
1582
+ const factory2 = (scope) => import_effect5.Layer.buildWithScope(handle.layer, scope).pipe(
1583
+ import_effect5.Effect.map((context) => import_effect5.ServiceMap.get(context, handle.module))
1584
+ );
1585
+ const value2 = preloadCache.warmSync(key2, factory2, configState.snapshot.gcTime, moduleId, {
1586
+ entrypoint: "react.runtime.preload.sync-warm",
1587
+ policyMode: "defer"
1588
+ });
1589
+ if (!value2) return false;
1590
+ continue;
1591
+ }
1592
+ const tagId = handle.id ?? "ModuleTag";
1593
+ const key = resolvedPolicy.preload.keysByTagId.get(tagId) ?? getPreloadKeyForTagId(tagId);
1594
+ const factory = (scope) => import_effect5.Scope.provide(scope)(import_effect5.Effect.service(handle).pipe(import_effect5.Effect.orDie));
1595
+ const value = preloadCache.warmSync(key, factory, configState.snapshot.gcTime, tagId, {
1596
+ entrypoint: "react.runtime.preload.sync-warm",
1597
+ policyMode: "defer"
1598
+ });
1599
+ if (!value) return false;
1600
+ }
1601
+ return true;
1602
+ }, [resolvedPolicy, isLayerReady, isConfigReady, preloadCache, configState.snapshot.gcTime]);
1444
1603
  const [deferReady, setDeferReady] = (0, import_react4.useState)(false);
1445
1604
  (0, import_react4.useEffect)(() => {
1446
1605
  if (resolvedPolicy.mode !== "defer") {
@@ -1454,6 +1613,10 @@ var RuntimeProvider = ({
1454
1613
  if (resolvedPolicy.mode !== "defer") {
1455
1614
  return;
1456
1615
  }
1616
+ if (syncWarmPreloadReady) {
1617
+ setDeferReady(true);
1618
+ return;
1619
+ }
1457
1620
  setDeferReady(false);
1458
1621
  if (!resolvedPolicy.preload) {
1459
1622
  setDeferReady(true);
@@ -1463,7 +1626,7 @@ var RuntimeProvider = ({
1463
1626
  return;
1464
1627
  }
1465
1628
  let cancelled = false;
1466
- const cache = getModuleCache(runtimeWithBindings, configState.snapshot, configState.version);
1629
+ const cache = preloadCache;
1467
1630
  const preloadHandles = resolvedPolicy.preload.handles;
1468
1631
  if (preloadHandles.length === 0) {
1469
1632
  setDeferReady(true);
@@ -1481,13 +1644,14 @@ var RuntimeProvider = ({
1481
1644
  const moduleId = handle.module?.id ?? "ModuleImpl";
1482
1645
  const key2 = resolvedPolicy.preload.keysByModuleId.get(moduleId) ?? getPreloadKeyForModuleId(moduleId);
1483
1646
  const factory2 = (scope) => import_effect5.Layer.buildWithScope(handle.layer, scope).pipe(
1484
- import_effect5.Effect.map((context) => import_effect5.Context.get(context, handle.module))
1647
+ import_effect5.Effect.map((context) => import_effect5.ServiceMap.get(context, handle.module))
1485
1648
  );
1486
1649
  const op2 = cache.preload(key2, factory2, {
1487
1650
  ownerId: moduleId,
1488
1651
  yield: resolvedPolicy.preload.yield,
1489
1652
  entrypoint: "react.runtime.preload",
1490
- policyMode: "defer"
1653
+ policyMode: "defer",
1654
+ optimisticSyncBudgetMs: resolvedPolicy.syncBudgetMs
1491
1655
  });
1492
1656
  allCancels.add(op2.cancel);
1493
1657
  await op2.promise;
@@ -1512,14 +1676,13 @@ var RuntimeProvider = ({
1512
1676
  }
1513
1677
  const tagId = handle.id ?? "ModuleTag";
1514
1678
  const key = resolvedPolicy.preload.keysByTagId.get(tagId) ?? getPreloadKeyForTagId(tagId);
1515
- const factory = (scope) => handle.pipe(
1516
- import_effect5.Scope.extend(scope)
1517
- );
1679
+ const factory = (scope) => import_effect5.Scope.provide(scope)(import_effect5.Effect.service(handle).pipe(import_effect5.Effect.orDie));
1518
1680
  const op = cache.preload(key, factory, {
1519
1681
  ownerId: tagId,
1520
1682
  yield: resolvedPolicy.preload.yield,
1521
1683
  entrypoint: "react.runtime.preload",
1522
- policyMode: "defer"
1684
+ policyMode: "defer",
1685
+ optimisticSyncBudgetMs: resolvedPolicy.syncBudgetMs
1523
1686
  });
1524
1687
  allCancels.add(op.cancel);
1525
1688
  await op.promise;
@@ -1557,7 +1720,7 @@ var RuntimeProvider = ({
1557
1720
  if (cancelled) return;
1558
1721
  if (onErrorRef.current) {
1559
1722
  runtimeWithBindings.runFork(
1560
- onErrorRef.current(import_effect5.Cause.die(error), { source: "provider", phase: "provider.layer.build" }).pipe(import_effect5.Effect.catchAllCause(() => import_effect5.Effect.void))
1723
+ onErrorRef.current(import_effect5.Cause.die(error), { source: "provider", phase: "provider.layer.build" }).pipe(import_effect5.Effect.catchCause(() => import_effect5.Effect.void))
1561
1724
  );
1562
1725
  }
1563
1726
  setDeferReady(true);
@@ -1590,13 +1753,54 @@ var RuntimeProvider = ({
1590
1753
  release();
1591
1754
  };
1592
1755
  }, [resolvedPolicy.mode, deferReady]);
1593
- const isReady = isTickServicesReady && isLayerReady && isConfigReady && (resolvedPolicy.mode !== "defer" || deferReady);
1756
+ const isReady = isTickServicesReady && isLayerReady && isConfigReady && (resolvedPolicy.mode !== "defer" || deferReady || syncWarmPreloadReady);
1757
+ if (isReady && providerReadyAtRef.current === void 0) {
1758
+ providerReadyAtRef.current = performance.now();
1759
+ }
1760
+ (0, import_react4.useEffect)(() => {
1761
+ if (!isReady) {
1762
+ return;
1763
+ }
1764
+ if (didReportProviderGatingRef.current) {
1765
+ return;
1766
+ }
1767
+ let diagnosticsLevel = "off";
1768
+ try {
1769
+ diagnosticsLevel = runtimeWithBindings.runSync(
1770
+ import_effect5.Effect.service(Logix5.Debug.internal.currentDiagnosticsLevel).pipe(import_effect5.Effect.orDie)
1771
+ );
1772
+ } catch {
1773
+ diagnosticsLevel = (0, import_Env.isDevEnv)() ? "light" : "off";
1774
+ }
1775
+ if (diagnosticsLevel === "off") {
1776
+ return;
1777
+ }
1778
+ didReportProviderGatingRef.current = true;
1779
+ const readyAt = providerReadyAtRef.current ?? performance.now();
1780
+ const durationMs = Math.round((readyAt - providerStartedAtRef.current) * 100) / 100;
1781
+ const effectDelayMs = Math.round((performance.now() - readyAt) * 100) / 100;
1782
+ void runtimeWithBindings.runPromise(
1783
+ Logix5.Debug.record({
1784
+ type: "trace:react.provider.gating",
1785
+ data: {
1786
+ event: "ready",
1787
+ policyMode: resolvedPolicy.mode,
1788
+ durationMs,
1789
+ effectDelayMs,
1790
+ configLoadMode: configState.loadMode,
1791
+ syncOverBudget: Boolean(configState.syncOverBudget),
1792
+ syncDurationMs: configState.syncDurationMs !== void 0 ? Math.round(configState.syncDurationMs * 100) / 100 : void 0
1793
+ }
1794
+ })
1795
+ ).catch(() => {
1796
+ });
1797
+ }, [configState.loadMode, configState.syncDurationMs, configState.syncOverBudget, isReady, resolvedPolicy.mode, runtimeWithBindings]);
1594
1798
  if (!isReady) {
1595
1799
  const blockersList = [
1596
1800
  isTickServicesReady ? null : "tick",
1597
1801
  isLayerReady ? null : "layer",
1598
1802
  isConfigReady ? null : "config",
1599
- resolvedPolicy.mode !== "defer" || deferReady ? null : "preload"
1803
+ resolvedPolicy.mode !== "defer" || deferReady || syncWarmPreloadReady ? null : "preload"
1600
1804
  ].filter((x) => x !== null);
1601
1805
  const blockers = blockersList.length > 0 ? blockersList.join("+") : void 0;
1602
1806
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
@@ -1,8 +1,8 @@
1
1
  import "./chunk-VFWWMK67.js";
2
2
  import {
3
3
  RuntimeProvider
4
- } from "./chunk-2M6MDNVT.js";
5
- import "./chunk-2WFULYPJ.js";
4
+ } from "./chunk-XSGDBJXD.js";
5
+ import "./chunk-L7KTYBXN.js";
6
6
  export {
7
7
  RuntimeProvider
8
8
  };
@@ -6,18 +6,18 @@ import {
6
6
  useModuleRuntime,
7
7
  useRuntime,
8
8
  useStableId
9
- } from "./chunk-G2LX7WWQ.js";
9
+ } from "./chunk-E3ZXST5F.js";
10
10
  import {
11
11
  RuntimeContext,
12
12
  getModuleCache,
13
13
  isDevEnv,
14
14
  stableHash
15
- } from "./chunk-2WFULYPJ.js";
15
+ } from "./chunk-L7KTYBXN.js";
16
16
 
17
17
  // src/internal/hooks/useLocalModule.ts
18
18
  import React, { useEffect, useMemo } from "react";
19
19
  import * as Logix from "@logixjs/core";
20
- import { Context, Effect, Layer, Scope } from "effect";
20
+ import { Effect, Layer, Scope, ServiceMap } from "effect";
21
21
  function isModuleTag(source) {
22
22
  if (!source || typeof source !== "object" && typeof source !== "function") {
23
23
  return false;
@@ -74,7 +74,7 @@ function useLocalModule(source, second) {
74
74
  return createModuleTagFactory(moduleTag, moduleOptions);
75
75
  }
76
76
  const factoryFn = source;
77
- return (scope) => factoryFn().pipe(Scope.extend(scope));
77
+ return (scope) => Scope.provide(scope)(factoryFn());
78
78
  }, [isModule, moduleTag, source, moduleOptions]);
79
79
  const moduleRuntime = cache.readSync(key, factory, void 0, ownerId, {
80
80
  entrypoint: "react.useLocalModule",
@@ -136,7 +136,7 @@ function createModuleTagFactory(module, options) {
136
136
  const logics = options.logics ?? [];
137
137
  return (scope) => Layer.buildWithScope(module.live(options.initial, ...logics), scope).pipe(
138
138
  Effect.map((context) => {
139
- const runtime = Context.get(context, module);
139
+ const runtime = ServiceMap.get(context, module);
140
140
  return runtime;
141
141
  })
142
142
  );
@@ -144,12 +144,12 @@ function createModuleTagFactory(module, options) {
144
144
 
145
145
  // src/internal/hooks/useLayerModule.ts
146
146
  import React2 from "react";
147
- import { Context as Context2, Effect as Effect2, Layer as Layer2 } from "effect";
147
+ import { Effect as Effect2, Layer as Layer2, ServiceMap as ServiceMap2 } from "effect";
148
148
  function useLayerModule(module, layer, deps = []) {
149
149
  const factory = React2.useCallback(
150
150
  () => Layer2.build(layer).pipe(
151
151
  Effect2.scoped,
152
- Effect2.map((context) => Context2.get(context, module))
152
+ Effect2.map((context) => ServiceMap2.get(context, module))
153
153
  ),
154
154
  // layer/module are typically constants; deps lets callers opt into rebuilding when needed.
155
155
  [layer, module]
@@ -330,7 +330,7 @@ function useProcesses(processes, options) {
330
330
  }
331
331
  return Effect3.forkScoped(process).pipe(Effect3.asVoid);
332
332
  }),
333
- Effect3.catchAll(() => Effect3.forkScoped(process).pipe(Effect3.asVoid))
333
+ Effect3.catch(() => Effect3.forkScoped(process).pipe(Effect3.asVoid))
334
334
  ),
335
335
  { discard: true }
336
336
  ).pipe(Effect3.provideService(Scope2.Scope, scope));