@logixjs/react 0.1.0 → 0.1.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.
@@ -1279,6 +1279,20 @@ var RuntimeProvider = ({
1279
1279
  );
1280
1280
  const onErrorRef = import_react4.default.useRef(onError);
1281
1281
  onErrorRef.current = onError;
1282
+ const hasTickServices = (0, import_react4.useMemo)(() => {
1283
+ try {
1284
+ Logix5.InternalContracts.getRuntimeStore(baseRuntime);
1285
+ return true;
1286
+ } catch {
1287
+ return false;
1288
+ }
1289
+ }, [baseRuntime]);
1290
+ const { binding: tickBinding } = useLayerBinding(
1291
+ baseRuntime,
1292
+ Logix5.InternalContracts.tickServicesLayer,
1293
+ !hasTickServices,
1294
+ onErrorRef.current
1295
+ );
1282
1296
  const { binding: layerBinding } = useLayerBinding(baseRuntime, layer, Boolean(layer), onErrorRef.current);
1283
1297
  const onErrorSink = (0, import_react4.useMemo)(() => {
1284
1298
  if (!onError) return null;
@@ -1337,17 +1351,17 @@ var RuntimeProvider = ({
1337
1351
  }
1338
1352
  }, [baseRuntime, layerBinding, onErrorSink]);
1339
1353
  const runtimeWithBindings = (0, import_react4.useMemo)(
1340
- () => layerBinding || onErrorSink ? createRuntimeAdapter(
1354
+ () => tickBinding || layerBinding || onErrorSink ? createRuntimeAdapter(
1341
1355
  baseRuntime,
1342
- layerBinding ? [layerBinding.context] : [],
1343
- layerBinding ? [layerBinding.scope] : [],
1344
- layerBinding ? [layerBinding.loggers] : [],
1345
- layerBinding ? [layerBinding.logLevel] : [],
1356
+ [...tickBinding ? [tickBinding.context] : [], ...layerBinding ? [layerBinding.context] : []],
1357
+ [...tickBinding ? [tickBinding.scope] : [], ...layerBinding ? [layerBinding.scope] : []],
1358
+ layerBinding ? [layerBinding.loggers] : tickBinding ? [tickBinding.loggers] : [],
1359
+ layerBinding ? [layerBinding.logLevel] : tickBinding ? [tickBinding.logLevel] : [],
1346
1360
  [
1347
1361
  onErrorSink ? [onErrorSink, ...inheritedDebugSinks] : layerBinding ? layerBinding.debugSinks : []
1348
1362
  ]
1349
1363
  ) : baseRuntime,
1350
- [baseRuntime, inheritedDebugSinks, layerBinding, onErrorSink]
1364
+ [baseRuntime, inheritedDebugSinks, layerBinding, onErrorSink, tickBinding]
1351
1365
  );
1352
1366
  const didReportSyncConfigSnapshotRef = import_react4.default.useRef(false);
1353
1367
  const [configState, setConfigState] = (0, import_react4.useState)(() => {
@@ -1452,6 +1466,7 @@ var RuntimeProvider = ({
1452
1466
  }),
1453
1467
  [runtimeWithBindings, configState, resolvedPolicy]
1454
1468
  );
1469
+ const isTickServicesReady = hasTickServices || tickBinding !== null;
1455
1470
  const isLayerReady = !layer || layerBinding !== null;
1456
1471
  const isConfigReady = configState.loaded;
1457
1472
  const resolveFallback = (phase) => {
@@ -1606,9 +1621,10 @@ var RuntimeProvider = ({
1606
1621
  release();
1607
1622
  };
1608
1623
  }, [resolvedPolicy.mode, deferReady]);
1609
- const isReady = isLayerReady && isConfigReady && (resolvedPolicy.mode !== "defer" || deferReady);
1624
+ const isReady = isTickServicesReady && isLayerReady && isConfigReady && (resolvedPolicy.mode !== "defer" || deferReady);
1610
1625
  if (!isReady) {
1611
1626
  const blockersList = [
1627
+ isTickServicesReady ? null : "tick",
1612
1628
  isLayerReady ? null : "layer",
1613
1629
  isConfigReady ? null : "config",
1614
1630
  resolvedPolicy.mode !== "defer" || deferReady ? null : "preload"
@@ -1724,8 +1740,8 @@ function useRuntime(options) {
1724
1740
 
1725
1741
  // src/internal/hooks/useModule.ts
1726
1742
  var import_react9 = __toESM(require("react"), 1);
1727
- var Logix9 = __toESM(require("@logixjs/core"), 1);
1728
- var import_effect10 = require("effect");
1743
+ var Logix10 = __toESM(require("@logixjs/core"), 1);
1744
+ var import_effect9 = require("effect");
1729
1745
 
1730
1746
  // src/internal/hooks/useModuleRuntime.ts
1731
1747
  var import_react6 = require("react");
@@ -1883,55 +1899,71 @@ function useModuleRuntime(handle) {
1883
1899
  // src/internal/hooks/useSelector.ts
1884
1900
  var import_react7 = require("react");
1885
1901
  var import_with_selector = require("use-sync-external-store/shim/with-selector");
1886
- var Logix7 = __toESM(require("@logixjs/core"), 1);
1902
+ var Logix8 = __toESM(require("@logixjs/core"), 1);
1887
1903
 
1888
- // src/internal/store/ModuleRuntimeExternalStore.ts
1904
+ // src/internal/store/RuntimeExternalStore.ts
1905
+ var Logix7 = __toESM(require("@logixjs/core"), 1);
1889
1906
  var import_effect8 = require("effect");
1890
1907
  var storesByRuntime = /* @__PURE__ */ new WeakMap();
1891
1908
  var getStoreMapForRuntime = (runtime) => {
1892
1909
  const cached = storesByRuntime.get(runtime);
1893
1910
  if (cached) return cached;
1894
- const next = /* @__PURE__ */ new WeakMap();
1911
+ const next = /* @__PURE__ */ new Map();
1895
1912
  storesByRuntime.set(runtime, next);
1896
1913
  return next;
1897
1914
  };
1898
- var getModuleRuntimeExternalStore = (runtime, moduleRuntime, options) => {
1899
- const byModule = getStoreMapForRuntime(runtime);
1900
- const cached = byModule.get(moduleRuntime);
1915
+ var makeModuleInstanceKey = (moduleId, instanceId) => `${moduleId}::${instanceId}`;
1916
+ var makeReadQueryTopicKey = (moduleInstanceKey, selectorId) => `${moduleInstanceKey}::rq:${selectorId}`;
1917
+ var getRuntimeStore = (runtime) => Logix7.InternalContracts.getRuntimeStore(runtime);
1918
+ var getHostScheduler = (runtime) => Logix7.InternalContracts.getHostScheduler(runtime);
1919
+ var getOrCreateStore = (runtime, topicKey, make) => {
1920
+ const map = getStoreMapForRuntime(runtime);
1921
+ const cached = map.get(topicKey);
1901
1922
  if (cached) {
1902
1923
  return cached;
1903
1924
  }
1904
- let currentState;
1925
+ const created = make();
1926
+ map.set(topicKey, created);
1927
+ return created;
1928
+ };
1929
+ var removeStore = (runtime, topicKey) => {
1930
+ const map = storesByRuntime.get(runtime);
1931
+ if (!map) return;
1932
+ map.delete(topicKey);
1933
+ };
1934
+ var makeTopicExternalStore = (args) => {
1935
+ const { runtime, runtimeStore, topicKey } = args;
1936
+ const hostScheduler = getHostScheduler(runtime);
1937
+ let currentVersion;
1938
+ let hasSnapshot = false;
1939
+ let currentSnapshot;
1905
1940
  const listeners = /* @__PURE__ */ new Set();
1906
- const lowPriorityDelayMs = options?.lowPriorityDelayMs ?? 16;
1907
- const lowPriorityMaxDelayMs = options?.lowPriorityMaxDelayMs ?? 50;
1941
+ let unsubscribeFromRuntimeStore;
1942
+ const lowPriorityDelayMs = args.options?.lowPriorityDelayMs ?? 16;
1943
+ const lowPriorityMaxDelayMs = args.options?.lowPriorityMaxDelayMs ?? 50;
1908
1944
  let notifyScheduled = false;
1909
1945
  let notifyScheduledLow = false;
1910
- let lowTimeoutId;
1911
- let lowMaxTimeoutId;
1912
- let lowRafId;
1946
+ let lowCancelDelay;
1947
+ let lowCancelMaxDelay;
1948
+ let lowCancelRaf;
1913
1949
  const cancelLow = () => {
1914
1950
  if (!notifyScheduledLow) return;
1915
1951
  notifyScheduledLow = false;
1916
- if (lowTimeoutId != null) {
1917
- clearTimeout(lowTimeoutId);
1918
- lowTimeoutId = void 0;
1919
- }
1920
- if (lowMaxTimeoutId != null) {
1921
- clearTimeout(lowMaxTimeoutId);
1922
- lowMaxTimeoutId = void 0;
1923
- }
1924
- const cancel = globalThis.cancelAnimationFrame;
1925
- if (cancel && typeof lowRafId === "number") {
1926
- cancel(lowRafId);
1927
- lowRafId = void 0;
1928
- }
1952
+ lowCancelDelay?.();
1953
+ lowCancelDelay = void 0;
1954
+ lowCancelMaxDelay?.();
1955
+ lowCancelMaxDelay = void 0;
1956
+ lowCancelRaf?.();
1957
+ lowCancelRaf = void 0;
1929
1958
  };
1930
1959
  const flushNotify = () => {
1931
1960
  notifyScheduled = false;
1932
1961
  cancelLow();
1933
1962
  for (const listener of listeners) {
1934
- listener();
1963
+ try {
1964
+ listener();
1965
+ } catch {
1966
+ }
1935
1967
  }
1936
1968
  };
1937
1969
  const scheduleNotify = (priority) => {
@@ -1943,72 +1975,135 @@ var getModuleRuntimeExternalStore = (runtime, moduleRuntime, options) => {
1943
1975
  if (!notifyScheduledLow) return;
1944
1976
  flushNotify();
1945
1977
  };
1946
- const raf = globalThis.requestAnimationFrame;
1947
- if (raf) {
1948
- lowRafId = raf(flush);
1978
+ const scheduleRaf = () => {
1979
+ if (!notifyScheduledLow) return;
1980
+ lowCancelRaf = hostScheduler.scheduleAnimationFrame(flush);
1981
+ };
1982
+ if (lowPriorityDelayMs <= 0) {
1983
+ scheduleRaf();
1949
1984
  } else {
1950
- lowTimeoutId = setTimeout(flush, lowPriorityDelayMs);
1985
+ lowCancelDelay = hostScheduler.scheduleTimeout(lowPriorityDelayMs, scheduleRaf);
1951
1986
  }
1952
- lowMaxTimeoutId = setTimeout(flush, lowPriorityMaxDelayMs);
1987
+ lowCancelMaxDelay = hostScheduler.scheduleTimeout(lowPriorityMaxDelayMs, flush);
1953
1988
  return;
1954
1989
  }
1955
1990
  cancelLow();
1956
1991
  if (notifyScheduled) return;
1957
1992
  notifyScheduled = true;
1958
- queueMicrotask(flushNotify);
1993
+ hostScheduler.scheduleMicrotask(flushNotify);
1994
+ };
1995
+ const onRuntimeStoreChange = () => {
1996
+ try {
1997
+ scheduleNotify(runtimeStore.getTopicPriority(topicKey));
1998
+ } catch {
1999
+ }
1959
2000
  };
1960
- let fiber;
1961
2001
  const ensureSubscription = () => {
1962
- if (fiber) return;
1963
- fiber = runtime.runFork(
1964
- import_effect8.Stream.runForEach(
1965
- moduleRuntime.changesWithMeta((state) => state),
1966
- ({ value: state, meta }) => import_effect8.Effect.sync(() => {
1967
- currentState = state;
1968
- scheduleNotify(meta.priority);
1969
- })
1970
- )
1971
- );
2002
+ if (unsubscribeFromRuntimeStore) return;
2003
+ unsubscribeFromRuntimeStore = runtimeStore.subscribeTopic(topicKey, onRuntimeStoreChange);
1972
2004
  };
1973
2005
  const refreshSnapshotIfStale = () => {
1974
- if (currentState === void 0) {
1975
- return;
1976
- }
2006
+ if (!hasSnapshot) return;
1977
2007
  try {
1978
- const latest = runtime.runSync(moduleRuntime.getState);
1979
- if (currentState === void 0 || !Object.is(currentState, latest)) {
1980
- currentState = latest;
1981
- scheduleNotify("normal");
2008
+ const version = runtimeStore.getTopicVersion(topicKey);
2009
+ if (currentVersion !== version) {
2010
+ scheduleNotify(runtimeStore.getTopicPriority(topicKey));
1982
2011
  }
1983
2012
  } catch {
1984
2013
  }
1985
2014
  };
1986
2015
  const getSnapshot = () => {
1987
- if (currentState !== void 0) return currentState;
1988
- currentState = runtime.runSync(moduleRuntime.getState);
1989
- return currentState;
2016
+ const version = runtimeStore.getTopicVersion(topicKey);
2017
+ if (hasSnapshot && currentVersion === version) {
2018
+ return currentSnapshot;
2019
+ }
2020
+ const next = args.readSnapshot();
2021
+ currentVersion = version;
2022
+ hasSnapshot = true;
2023
+ currentSnapshot = next;
2024
+ return next;
1990
2025
  };
1991
2026
  const subscribe = (listener) => {
2027
+ const isFirst = listeners.size === 0;
1992
2028
  listeners.add(listener);
1993
2029
  ensureSubscription();
1994
2030
  refreshSnapshotIfStale();
2031
+ if (isFirst) {
2032
+ try {
2033
+ args.onFirstListener?.();
2034
+ } catch {
2035
+ }
2036
+ }
1995
2037
  return () => {
1996
2038
  listeners.delete(listener);
1997
2039
  if (listeners.size > 0) return;
1998
- const running = fiber;
1999
- if (!running) return;
2000
- fiber = void 0;
2040
+ try {
2041
+ args.onLastListener?.();
2042
+ } catch {
2043
+ }
2044
+ const unsub = unsubscribeFromRuntimeStore;
2045
+ unsubscribeFromRuntimeStore = void 0;
2001
2046
  cancelLow();
2002
- runtime.runFork(import_effect8.Fiber.interrupt(running));
2047
+ try {
2048
+ unsub?.();
2049
+ } catch {
2050
+ }
2051
+ removeStore(runtime, topicKey);
2003
2052
  };
2004
2053
  };
2005
- const store = { getSnapshot, subscribe };
2006
- byModule.set(moduleRuntime, store);
2007
- return store;
2054
+ return { getSnapshot, getServerSnapshot: getSnapshot, subscribe };
2055
+ };
2056
+ var getRuntimeModuleExternalStore = (runtime, moduleRuntime, options) => {
2057
+ const moduleInstanceKey = makeModuleInstanceKey(moduleRuntime.moduleId, moduleRuntime.instanceId);
2058
+ const runtimeStore = getRuntimeStore(runtime);
2059
+ return getOrCreateStore(
2060
+ runtime,
2061
+ moduleInstanceKey,
2062
+ () => makeTopicExternalStore({
2063
+ runtime,
2064
+ runtimeStore,
2065
+ topicKey: moduleInstanceKey,
2066
+ readSnapshot: () => {
2067
+ const state = runtimeStore.getModuleState(moduleInstanceKey);
2068
+ if (state !== void 0) return state;
2069
+ return runtime.runSync(moduleRuntime.getState);
2070
+ },
2071
+ options
2072
+ })
2073
+ );
2074
+ };
2075
+ var getRuntimeReadQueryExternalStore = (runtime, moduleRuntime, selectorReadQuery, options) => {
2076
+ const moduleInstanceKey = makeModuleInstanceKey(moduleRuntime.moduleId, moduleRuntime.instanceId);
2077
+ const topicKey = makeReadQueryTopicKey(moduleInstanceKey, selectorReadQuery.selectorId);
2078
+ const runtimeStore = getRuntimeStore(runtime);
2079
+ let readQueryDrainFiber;
2080
+ return getOrCreateStore(
2081
+ runtime,
2082
+ topicKey,
2083
+ () => makeTopicExternalStore({
2084
+ runtime,
2085
+ runtimeStore,
2086
+ topicKey,
2087
+ readSnapshot: () => {
2088
+ const state = runtimeStore.getModuleState(moduleInstanceKey);
2089
+ const current = state ?? runtime.runSync(moduleRuntime.getState);
2090
+ return selectorReadQuery.select(current);
2091
+ },
2092
+ options,
2093
+ onFirstListener: () => {
2094
+ if (readQueryDrainFiber) return;
2095
+ const effect = import_effect8.Stream.runDrain(moduleRuntime.changesReadQueryWithMeta(selectorReadQuery));
2096
+ readQueryDrainFiber = runtime.runFork(effect);
2097
+ },
2098
+ onLastListener: () => {
2099
+ const fiber = readQueryDrainFiber;
2100
+ if (!fiber) return;
2101
+ readQueryDrainFiber = void 0;
2102
+ runtime.runFork(import_effect8.Fiber.interrupt(fiber));
2103
+ }
2104
+ })
2105
+ );
2008
2106
  };
2009
-
2010
- // src/internal/store/ModuleRuntimeSelectorExternalStore.ts
2011
- var import_effect9 = require("effect");
2012
2107
 
2013
2108
  // src/internal/hooks/shallow.ts
2014
2109
  var hasObjectShape = (value) => typeof value === "object" && value !== null;
@@ -2060,146 +2155,6 @@ var shallow = (previous, next) => {
2060
2155
  return true;
2061
2156
  };
2062
2157
 
2063
- // src/internal/store/ModuleRuntimeSelectorExternalStore.ts
2064
- var storesByRuntime2 = /* @__PURE__ */ new WeakMap();
2065
- var getStoreMapForRuntime2 = (runtime) => {
2066
- const cached = storesByRuntime2.get(runtime);
2067
- if (cached) return cached;
2068
- const next = /* @__PURE__ */ new WeakMap();
2069
- storesByRuntime2.set(runtime, next);
2070
- return next;
2071
- };
2072
- var getOrCreateSelectorMapForModule = (byModule, moduleRuntime) => {
2073
- const cached = byModule.get(moduleRuntime);
2074
- if (cached) return cached;
2075
- const next = /* @__PURE__ */ new Map();
2076
- byModule.set(moduleRuntime, next);
2077
- return next;
2078
- };
2079
- var equalsValue = (readQuery, a, b) => {
2080
- if (readQuery.equalsKind === "custom" && typeof readQuery.equals === "function") {
2081
- return readQuery.equals(a, b);
2082
- }
2083
- if (readQuery.equalsKind === "shallowStruct") {
2084
- return shallow(a, b);
2085
- }
2086
- return Object.is(a, b);
2087
- };
2088
- var getModuleRuntimeSelectorExternalStore = (runtime, moduleRuntime, selectorReadQuery, options) => {
2089
- const byModule = getStoreMapForRuntime2(runtime);
2090
- const bySelector = getOrCreateSelectorMapForModule(byModule, moduleRuntime);
2091
- const cached = bySelector.get(selectorReadQuery.selectorId);
2092
- if (cached) {
2093
- return cached;
2094
- }
2095
- let currentValue;
2096
- const listeners = /* @__PURE__ */ new Set();
2097
- const lowPriorityDelayMs = options?.lowPriorityDelayMs ?? 16;
2098
- const lowPriorityMaxDelayMs = options?.lowPriorityMaxDelayMs ?? 50;
2099
- let notifyScheduled = false;
2100
- let notifyScheduledLow = false;
2101
- let lowTimeoutId;
2102
- let lowMaxTimeoutId;
2103
- let lowRafId;
2104
- const cancelLow = () => {
2105
- if (!notifyScheduledLow) return;
2106
- notifyScheduledLow = false;
2107
- if (lowTimeoutId != null) {
2108
- clearTimeout(lowTimeoutId);
2109
- lowTimeoutId = void 0;
2110
- }
2111
- if (lowMaxTimeoutId != null) {
2112
- clearTimeout(lowMaxTimeoutId);
2113
- lowMaxTimeoutId = void 0;
2114
- }
2115
- const cancel = globalThis.cancelAnimationFrame;
2116
- if (cancel && typeof lowRafId === "number") {
2117
- cancel(lowRafId);
2118
- lowRafId = void 0;
2119
- }
2120
- };
2121
- const flushNotify = () => {
2122
- notifyScheduled = false;
2123
- cancelLow();
2124
- for (const listener of listeners) {
2125
- listener();
2126
- }
2127
- };
2128
- const scheduleNotify = (priority) => {
2129
- if (priority === "low") {
2130
- if (notifyScheduled) return;
2131
- if (notifyScheduledLow) return;
2132
- notifyScheduledLow = true;
2133
- const flush = () => {
2134
- if (!notifyScheduledLow) return;
2135
- flushNotify();
2136
- };
2137
- const raf = globalThis.requestAnimationFrame;
2138
- if (raf) {
2139
- lowRafId = raf(flush);
2140
- } else {
2141
- lowTimeoutId = setTimeout(flush, lowPriorityDelayMs);
2142
- }
2143
- lowMaxTimeoutId = setTimeout(flush, lowPriorityMaxDelayMs);
2144
- return;
2145
- }
2146
- cancelLow();
2147
- if (notifyScheduled) return;
2148
- notifyScheduled = true;
2149
- queueMicrotask(flushNotify);
2150
- };
2151
- let fiber;
2152
- const ensureSubscription = () => {
2153
- if (fiber) return;
2154
- fiber = runtime.runFork(
2155
- import_effect9.Stream.runForEach(
2156
- moduleRuntime.changesReadQueryWithMeta(selectorReadQuery),
2157
- ({ value, meta }) => import_effect9.Effect.sync(() => {
2158
- currentValue = value;
2159
- scheduleNotify(meta.priority);
2160
- })
2161
- )
2162
- );
2163
- };
2164
- const refreshSnapshotIfStale = () => {
2165
- if (currentValue === void 0) {
2166
- return;
2167
- }
2168
- try {
2169
- const state = runtime.runSync(moduleRuntime.getState);
2170
- const next = selectorReadQuery.select(state);
2171
- if (currentValue === void 0 || !equalsValue(selectorReadQuery, currentValue, next)) {
2172
- currentValue = next;
2173
- scheduleNotify("normal");
2174
- }
2175
- } catch {
2176
- }
2177
- };
2178
- const getSnapshot = () => {
2179
- if (currentValue !== void 0) return currentValue;
2180
- const state = runtime.runSync(moduleRuntime.getState);
2181
- currentValue = selectorReadQuery.select(state);
2182
- return currentValue;
2183
- };
2184
- const subscribe = (listener) => {
2185
- listeners.add(listener);
2186
- ensureSubscription();
2187
- refreshSnapshotIfStale();
2188
- return () => {
2189
- listeners.delete(listener);
2190
- if (listeners.size > 0) return;
2191
- const running = fiber;
2192
- if (!running) return;
2193
- fiber = void 0;
2194
- cancelLow();
2195
- runtime.runFork(import_effect9.Fiber.interrupt(running));
2196
- };
2197
- };
2198
- const store = { getSnapshot, subscribe };
2199
- bySelector.set(selectorReadQuery.selectorId, store);
2200
- return store;
2201
- };
2202
-
2203
2158
  // src/internal/hooks/useSelector.ts
2204
2159
  function useSelector(handle, selector, equalityFn) {
2205
2160
  const runtimeContext = (0, import_react7.useContext)(RuntimeContext);
@@ -2210,7 +2165,7 @@ function useSelector(handle, selector, equalityFn) {
2210
2165
  const moduleRuntime = useModuleRuntime(handle);
2211
2166
  const actualSelector = selector ?? ((state) => state);
2212
2167
  const selectorReadQuery = (0, import_react7.useMemo)(
2213
- () => typeof selector === "function" ? Logix7.ReadQuery.compile(selector) : void 0,
2168
+ () => typeof selector === "function" ? Logix8.ReadQuery.compile(selector) : void 0,
2214
2169
  [selector]
2215
2170
  );
2216
2171
  const actualEqualityFn = (0, import_react7.useMemo)(() => {
@@ -2218,17 +2173,12 @@ function useSelector(handle, selector, equalityFn) {
2218
2173
  if (typeof selector !== "function") return Object.is;
2219
2174
  return selectorReadQuery?.equalsKind === "shallowStruct" ? shallow : Object.is;
2220
2175
  }, [equalityFn, selector, selectorReadQuery?.equalsKind]);
2221
- const useStaticLane = typeof selector === "function" && selectorReadQuery?.lane === "static";
2176
+ const selectorTopicEligible = typeof selector === "function" && selectorReadQuery?.lane === "static" && selectorReadQuery.readsDigest != null && selectorReadQuery.fallbackReason == null;
2222
2177
  const store = (0, import_react7.useMemo)(
2223
- () => useStaticLane && selectorReadQuery ? getModuleRuntimeSelectorExternalStore(
2224
- runtime,
2225
- moduleRuntime,
2226
- selectorReadQuery,
2227
- {
2228
- lowPriorityDelayMs: runtimeContext.reactConfigSnapshot.lowPriorityDelayMs,
2229
- lowPriorityMaxDelayMs: runtimeContext.reactConfigSnapshot.lowPriorityMaxDelayMs
2230
- }
2231
- ) : getModuleRuntimeExternalStore(
2178
+ () => selectorTopicEligible && selectorReadQuery ? getRuntimeReadQueryExternalStore(runtime, moduleRuntime, selectorReadQuery, {
2179
+ lowPriorityDelayMs: runtimeContext.reactConfigSnapshot.lowPriorityDelayMs,
2180
+ lowPriorityMaxDelayMs: runtimeContext.reactConfigSnapshot.lowPriorityMaxDelayMs
2181
+ }) : getRuntimeModuleExternalStore(
2232
2182
  runtime,
2233
2183
  moduleRuntime,
2234
2184
  {
@@ -2242,18 +2192,18 @@ function useSelector(handle, selector, equalityFn) {
2242
2192
  runtimeContext.reactConfigSnapshot.lowPriorityDelayMs,
2243
2193
  runtimeContext.reactConfigSnapshot.lowPriorityMaxDelayMs,
2244
2194
  selectorReadQuery,
2245
- useStaticLane
2195
+ selectorTopicEligible
2246
2196
  ]
2247
2197
  );
2248
2198
  const selected = (0, import_with_selector.useSyncExternalStoreWithSelector)(
2249
2199
  store.subscribe,
2250
2200
  store.getSnapshot,
2251
- store.getSnapshot,
2252
- useStaticLane ? (snapshot) => snapshot : (snapshot) => actualSelector(snapshot),
2201
+ store.getServerSnapshot ?? store.getSnapshot,
2202
+ selectorTopicEligible ? (snapshot) => snapshot : (snapshot) => actualSelector(snapshot),
2253
2203
  actualEqualityFn
2254
2204
  );
2255
2205
  (0, import_react7.useEffect)(() => {
2256
- if (!(0, import_Env.isDevEnv)() && !Logix7.Debug.isDevtoolsEnabled()) {
2206
+ if (!(0, import_Env.isDevEnv)() && !Logix8.Debug.isDevtoolsEnabled()) {
2257
2207
  return;
2258
2208
  }
2259
2209
  const instanceId = moduleRuntime.instanceId;
@@ -2269,7 +2219,7 @@ function useSelector(handle, selector, equalityFn) {
2269
2219
  const rawDebugKey = meta.debugKey;
2270
2220
  selectorKey = typeof rawDebugKey === "string" && rawDebugKey.length > 0 ? rawDebugKey : typeof selector.name === "string" && selector.name.length > 0 ? selector.name : void 0;
2271
2221
  }
2272
- const effect = Logix7.Debug.record({
2222
+ const effect = Logix8.Debug.record({
2273
2223
  type: "trace:react-selector",
2274
2224
  moduleId: moduleRuntime.moduleId,
2275
2225
  instanceId,
@@ -2292,7 +2242,7 @@ function useSelector(handle, selector, equalityFn) {
2292
2242
  }
2293
2243
 
2294
2244
  // src/internal/store/resolveImportedModuleRef.ts
2295
- var Logix8 = __toESM(require("@logixjs/core"), 1);
2245
+ var Logix9 = __toESM(require("@logixjs/core"), 1);
2296
2246
  var getOrCreateWeakMap = (map, key, make) => {
2297
2247
  const cached = map.get(key);
2298
2248
  if (cached) return cached;
@@ -2316,7 +2266,7 @@ var resolveImportedModuleRef = (runtime, parentRuntime, module2) => {
2316
2266
  if (cached) {
2317
2267
  return cached;
2318
2268
  }
2319
- const importsScope = Logix8.InternalContracts.getImportsScope(parentRuntime);
2269
+ const importsScope = Logix9.InternalContracts.getImportsScope(parentRuntime);
2320
2270
  const childRuntime = importsScope.get(module2);
2321
2271
  if (childRuntime) {
2322
2272
  const dispatch = Object.assign(
@@ -2402,8 +2352,8 @@ var useStableId = () => {
2402
2352
 
2403
2353
  // src/internal/hooks/useModule.ts
2404
2354
  var isModuleImpl2 = (handle) => Boolean(handle) && typeof handle === "object" && handle._tag === "ModuleImpl";
2405
- var isModule = (handle) => Logix9.Module.hasImpl(handle);
2406
- var isModuleDef = (handle) => Logix9.Module.is(handle) && handle._kind === "ModuleDef";
2355
+ var isModule = (handle) => Logix10.Module.hasImpl(handle);
2356
+ var isModuleDef = (handle) => Logix10.Module.is(handle) && handle._kind === "ModuleDef";
2407
2357
  function useModule(handle, selectorOrOptions, equalityFn) {
2408
2358
  const runtimeBase = useRuntime();
2409
2359
  const runtimeContext = import_react9.default.useContext(RuntimeContext);
@@ -2455,9 +2405,9 @@ function useModule(handle, selectorOrOptions, equalityFn) {
2455
2405
  const key = depsHash ? `${baseKey}:${depsHash}` : baseKey;
2456
2406
  const ownerId = moduleId;
2457
2407
  const baseFactory = import_react9.default.useMemo(
2458
- () => (scope) => import_effect10.Layer.buildWithScope(normalizedHandle.layer, scope).pipe(
2459
- import_effect10.Effect.map(
2460
- (context) => import_effect10.Context.get(context, normalizedHandle.module)
2408
+ () => (scope) => import_effect9.Layer.buildWithScope(normalizedHandle.layer, scope).pipe(
2409
+ import_effect9.Effect.map(
2410
+ (context) => import_effect9.Context.get(context, normalizedHandle.module)
2461
2411
  )
2462
2412
  ),
2463
2413
  [normalizedHandle]
@@ -2467,7 +2417,7 @@ function useModule(handle, selectorOrOptions, equalityFn) {
2467
2417
  return baseFactory;
2468
2418
  }
2469
2419
  return (scope) => baseFactory(scope).pipe(
2470
- import_effect10.Effect.timeoutFail({
2420
+ import_effect9.Effect.timeoutFail({
2471
2421
  duration: initTimeoutMs,
2472
2422
  onTimeout: () => new Error(`[useModule] Module "${ownerId}" initialization timed out after ${initTimeoutMs}ms`)
2473
2423
  })
@@ -2496,7 +2446,7 @@ function useModule(handle, selectorOrOptions, equalityFn) {
2496
2446
  if (!label) {
2497
2447
  return;
2498
2448
  }
2499
- const effect = Logix9.Debug.record({
2449
+ const effect = Logix10.Debug.record({
2500
2450
  type: "trace:instanceLabel",
2501
2451
  moduleId: normalizedHandle.module.id,
2502
2452
  instanceId: runtime.instanceId,
@@ -2505,13 +2455,13 @@ function useModule(handle, selectorOrOptions, equalityFn) {
2505
2455
  runtimeBase.runFork(effect);
2506
2456
  }, [runtimeBase, runtime, normalizedHandle, options]);
2507
2457
  import_react9.default.useEffect(() => {
2508
- if (!(0, import_Env.isDevEnv)() && !Logix9.Debug.isDevtoolsEnabled()) {
2458
+ if (!(0, import_Env.isDevEnv)() && !Logix10.Debug.isDevtoolsEnabled()) {
2509
2459
  return;
2510
2460
  }
2511
2461
  if (!runtime.instanceId) {
2512
2462
  return;
2513
2463
  }
2514
- const effect = Logix9.Debug.record({
2464
+ const effect = Logix10.Debug.record({
2515
2465
  type: "trace:react-render",
2516
2466
  moduleId: runtime.moduleId,
2517
2467
  instanceId: runtime.instanceId,
@@ -2608,8 +2558,8 @@ function useModule(handle, selectorOrOptions, equalityFn) {
2608
2558
 
2609
2559
  // src/internal/hooks/useLocalModule.ts
2610
2560
  var import_react10 = __toESM(require("react"), 1);
2611
- var Logix10 = __toESM(require("@logixjs/core"), 1);
2612
- var import_effect11 = require("effect");
2561
+ var Logix11 = __toESM(require("@logixjs/core"), 1);
2562
+ var import_effect10 = require("effect");
2613
2563
  function isModuleTag2(source) {
2614
2564
  if (!source || typeof source !== "object" && typeof source !== "function") {
2615
2565
  return false;
@@ -2629,7 +2579,7 @@ function useLocalModule(source, second) {
2629
2579
  );
2630
2580
  const componentId = useStableId();
2631
2581
  const moduleTag = import_react10.default.useMemo(() => {
2632
- if (Logix10.Module.is(source)) {
2582
+ if (Logix11.Module.is(source)) {
2633
2583
  return source.tag;
2634
2584
  }
2635
2585
  if (isModuleTag2(source)) {
@@ -2638,7 +2588,7 @@ function useLocalModule(source, second) {
2638
2588
  return null;
2639
2589
  }, [source]);
2640
2590
  const def = import_react10.default.useMemo(() => {
2641
- if (Logix10.Module.is(source) || isModuleTag2(source)) {
2591
+ if (Logix11.Module.is(source) || isModuleTag2(source)) {
2642
2592
  return source;
2643
2593
  }
2644
2594
  return void 0;
@@ -2666,7 +2616,7 @@ function useLocalModule(source, second) {
2666
2616
  return createModuleTagFactory(moduleTag, moduleOptions);
2667
2617
  }
2668
2618
  const factoryFn = source;
2669
- return (scope) => factoryFn().pipe(import_effect11.Scope.extend(scope));
2619
+ return (scope) => factoryFn().pipe(import_effect10.Scope.extend(scope));
2670
2620
  }, [isModule2, moduleTag, source, moduleOptions]);
2671
2621
  const moduleRuntime = cache.readSync(key, factory, void 0, ownerId, {
2672
2622
  entrypoint: "react.useLocalModule",
@@ -2726,9 +2676,9 @@ function createModuleTagFactory(module2, options) {
2726
2676
  throw new Error("useLocalModule(module, options) \u9700\u8981\u63D0\u4F9B initial \u72B6\u6001");
2727
2677
  }
2728
2678
  const logics = options.logics ?? [];
2729
- return (scope) => import_effect11.Layer.buildWithScope(module2.live(options.initial, ...logics), scope).pipe(
2730
- import_effect11.Effect.map((context) => {
2731
- const runtime = import_effect11.Context.get(context, module2);
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);
2732
2682
  return runtime;
2733
2683
  })
2734
2684
  );
@@ -2736,7 +2686,7 @@ function createModuleTagFactory(module2, options) {
2736
2686
 
2737
2687
  // src/internal/hooks/useLayerModule.ts
2738
2688
  var import_react11 = __toESM(require("react"), 1);
2739
- var import_effect12 = require("effect");
2689
+ var import_effect11 = require("effect");
2740
2690
 
2741
2691
  // src/internal/hooks/useDispatch.ts
2742
2692
  var import_react12 = require("react");
@@ -2766,8 +2716,8 @@ var import_react14 = __toESM(require("react"), 1);
2766
2716
 
2767
2717
  // src/internal/hooks/useProcesses.ts
2768
2718
  var import_react15 = __toESM(require("react"), 1);
2769
- var import_effect13 = require("effect");
2770
- var Logix11 = __toESM(require("@logixjs/core"), 1);
2719
+ var import_effect12 = require("effect");
2720
+ var Logix12 = __toESM(require("@logixjs/core"), 1);
2771
2721
 
2772
2722
  // src/ReactPlatform.ts
2773
2723
  var import_react16 = __toESM(require("react"), 1);