@solidjs/signals 0.9.9 → 0.9.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dev.js CHANGED
@@ -158,12 +158,15 @@ function getOrCreateLane(signal) {
158
158
  if (lane) {
159
159
  return findLane(lane);
160
160
  }
161
+ const parentSource = signal._parentSource;
162
+ const parentLane = parentSource?._optimisticLane ? findLane(parentSource._optimisticLane) : null;
161
163
  lane = {
162
164
  _source: signal,
163
165
  _pendingAsync: new Set(),
164
166
  _effectQueues: [[], []],
165
167
  _mergedInto: null,
166
- _transition: activeTransition
168
+ _transition: activeTransition,
169
+ _parentLane: parentLane
167
170
  };
168
171
  signalLanes.set(signal, lane);
169
172
  activeLanes.add(lane);
@@ -209,7 +212,12 @@ function assignOrMergeLane(el, sourceLane) {
209
212
  const existingRoot = findLane(existing);
210
213
  if (activeLanes.has(existingRoot)) {
211
214
  if (existingRoot !== sourceRoot && !hasActiveOverride(el)) {
212
- mergeLanes(sourceRoot, existingRoot);
215
+ if (sourceRoot._parentLane && findLane(sourceRoot._parentLane) === existingRoot) {
216
+ el._optimisticLane = sourceLane;
217
+ } else if (existingRoot._parentLane && findLane(existingRoot._parentLane) === sourceRoot);
218
+ else {
219
+ mergeLanes(sourceRoot, existingRoot);
220
+ }
213
221
  }
214
222
  return;
215
223
  }
@@ -531,7 +539,8 @@ function transitionComplete(transition) {
531
539
  if (transition._actions.length) return false;
532
540
  let done = true;
533
541
  for (let i = 0; i < transition._asyncNodes.length; i++) {
534
- if (transition._asyncNodes[i]._statusFlags & STATUS_PENDING) {
542
+ const node = transition._asyncNodes[i];
543
+ if (node._statusFlags & STATUS_PENDING && node._error?._source === node) {
535
544
  done = false;
536
545
  break;
537
546
  }
@@ -645,13 +654,17 @@ function recompute(el, create = false) {
645
654
  value = handleAsync(el, el._fn(value));
646
655
  clearStatus(el);
647
656
  const resolvedLane = resolveLane(el);
648
- if (resolvedLane) resolvedLane._pendingAsync.delete(el);
657
+ if (resolvedLane) {
658
+ resolvedLane._pendingAsync.delete(el);
659
+ updatePendingSignal(resolvedLane._source);
660
+ }
649
661
  } catch (e) {
650
662
  if (e instanceof NotReadyError && currentOptimisticLane) {
651
663
  const lane = findLane(currentOptimisticLane);
652
664
  if (lane._source !== el) {
653
665
  lane._pendingAsync.add(el);
654
666
  el._optimisticLane = lane;
667
+ updatePendingSignal(lane._source);
655
668
  }
656
669
  }
657
670
  notifyStatus(
@@ -1106,12 +1119,24 @@ function optimisticComputed(fn, initialValue, options) {
1106
1119
  function getPendingSignal(el) {
1107
1120
  if (!el._pendingSignal) {
1108
1121
  el._pendingSignal = optimisticSignal(false, { pureWrite: true });
1122
+ if (el._parentSource) {
1123
+ el._pendingSignal._parentSource = el;
1124
+ }
1109
1125
  if (computePendingState(el)) setSignal(el._pendingSignal, true);
1110
1126
  }
1111
1127
  return el._pendingSignal;
1112
1128
  }
1113
1129
  function computePendingState(el) {
1114
1130
  const comp = el;
1131
+ if (el._optimistic && el._pendingValue !== NOT_PENDING) {
1132
+ if (comp._statusFlags & STATUS_PENDING && !(comp._statusFlags & STATUS_UNINITIALIZED))
1133
+ return true;
1134
+ if (el._parentSource) {
1135
+ const lane = el._optimisticLane ? findLane(el._optimisticLane) : null;
1136
+ return !!(lane && lane._pendingAsync.size > 0);
1137
+ }
1138
+ return true;
1139
+ }
1115
1140
  if (el._pendingValue !== NOT_PENDING && !(comp._statusFlags & STATUS_UNINITIALIZED)) return true;
1116
1141
  return !!(comp._statusFlags & STATUS_PENDING && !(comp._statusFlags & STATUS_UNINITIALIZED));
1117
1142
  }
@@ -1119,10 +1144,14 @@ function getPendingValueComputed(el) {
1119
1144
  if (!el._pendingValueComputed) {
1120
1145
  const prevPending = pendingReadActive;
1121
1146
  pendingReadActive = false;
1147
+ const prevCheck = pendingCheckActive;
1148
+ pendingCheckActive = false;
1122
1149
  const prevContext = context;
1123
1150
  context = null;
1124
1151
  el._pendingValueComputed = optimisticComputed(() => read(el));
1152
+ el._pendingValueComputed._parentSource = el;
1125
1153
  context = prevContext;
1154
+ pendingCheckActive = prevCheck;
1126
1155
  pendingReadActive = prevPending;
1127
1156
  }
1128
1157
  return el._pendingValueComputed;
@@ -1158,6 +1187,22 @@ function untrack(fn) {
1158
1187
  }
1159
1188
  }
1160
1189
  function read(el) {
1190
+ if (pendingReadActive) {
1191
+ const pendingComputed = getPendingValueComputed(el);
1192
+ const prevPending = pendingReadActive;
1193
+ pendingReadActive = false;
1194
+ const value = read(pendingComputed);
1195
+ pendingReadActive = prevPending;
1196
+ if (pendingComputed._statusFlags & STATUS_PENDING) return el._value;
1197
+ if (stale && currentOptimisticLane && pendingComputed._optimisticLane) {
1198
+ const pcLane = findLane(pendingComputed._optimisticLane);
1199
+ const curLane = findLane(currentOptimisticLane);
1200
+ if (pcLane !== curLane && pcLane._pendingAsync.size > 0) {
1201
+ return el._value;
1202
+ }
1203
+ }
1204
+ return value;
1205
+ }
1161
1206
  if (pendingCheckActive) {
1162
1207
  const target = el._firewall || el;
1163
1208
  const pendingSig = getPendingSignal(target);
@@ -1169,15 +1214,6 @@ function read(el) {
1169
1214
  pendingCheckActive = prevCheck;
1170
1215
  return el._value;
1171
1216
  }
1172
- if (pendingReadActive) {
1173
- const pendingComputed = getPendingValueComputed(el);
1174
- const prevPending = pendingReadActive;
1175
- pendingReadActive = false;
1176
- const value = read(pendingComputed);
1177
- pendingReadActive = prevPending;
1178
- if (pendingComputed._statusFlags & STATUS_PENDING) return el._value;
1179
- return value;
1180
- }
1181
1217
  let c = context;
1182
1218
  if (c?._root) c = c._parentComputed;
1183
1219
  if (refreshing && el._fn) recompute(el);