@esportsplus/reactivity 0.43.1 → 0.43.2

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/build/system.js CHANGED
@@ -547,7 +547,9 @@ function makeComputed(fn, eager = false) {
547
547
  link(self, observer);
548
548
  }
549
549
  else {
550
+ self.gv = -1;
550
551
  self.height = observer.height + 1;
552
+ self.state |= STATE_DIRTY;
551
553
  insertIntoHeap(self);
552
554
  schedule();
553
555
  }
package/package.json CHANGED
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "type": "module",
43
43
  "types": "build/index.d.ts",
44
- "version": "0.43.1",
44
+ "version": "0.43.2",
45
45
  "scripts": {
46
46
  "agent:bench": "vitest bench --run",
47
47
  "agent:test": "pnpm typecheck && vitest run",
package/src/system.ts CHANGED
@@ -817,7 +817,7 @@ function makeComputed<T>(fn: Computed<T>['fn'], eager: boolean = false): Compute
817
817
  else if (eager) {
818
818
  // computed() must know fn's return type to pick sync vs async. This probe runs BEFORE
819
819
  // link(), so self has no subs yet — recompute's propagate is a no-op and cannot
820
- // re-run the parent. Deferring here (as effect() still does) would leave value unset.
820
+ // re-run the parent. Deferring here (as effect() still does) would leave the type unknown until it ran.
821
821
  self.height = observer.height + 1;
822
822
  recompute(self);
823
823
  link(self, observer);
@@ -825,8 +825,11 @@ function makeComputed<T>(fn: Computed<T>['fn'], eager: boolean = false): Compute
825
825
  else {
826
826
  // Deferred, so not linked: the parent has not read a value, and the creation run setting one later is
827
827
  // no change it depends on. Linked, that run would re-run the parent, whose re-run creates another node,
828
- // looping. A parent that reads the node links through read().
828
+ // looping. A parent that reads the node links through read(), whose pull must then run it: a node
829
+ // that never ran has no notify bits and a write version that can match, so mark it dirty and unversioned.
830
+ self.gv = -1;
829
831
  self.height = observer.height + 1;
832
+ self.state |= STATE_DIRTY;
830
833
  insertIntoHeap(self);
831
834
  schedule();
832
835
  }
@@ -434,4 +434,41 @@ describe('deferred inner effects', () => {
434
434
  expect(outer).toBe(1);
435
435
  expect(applied).toEqual([true]);
436
436
  });
437
+
438
+ it('a parent that reads its inner effect gets its value, once, and follows it', async () => {
439
+ let inner = 0,
440
+ other = signal(0),
441
+ outer = 0,
442
+ s = signal(1),
443
+ seen: (number | undefined)[] = [];
444
+
445
+ effect(() => {
446
+ read(other);
447
+ outer++;
448
+
449
+ if (outer > 20) {
450
+ return;
451
+ }
452
+
453
+ let doubled = effect(() => {
454
+ inner++;
455
+
456
+ return read(s) * 2;
457
+ });
458
+
459
+ seen.push(read(doubled));
460
+ });
461
+
462
+ await Promise.resolve();
463
+ await Promise.resolve();
464
+
465
+ expect(seen).toEqual([2]);
466
+ expect(outer).toBe(1);
467
+ expect(inner).toBe(1);
468
+
469
+ write(s, 2);
470
+ await waitFor(() => seen.length === 2, 'the parent re-runs');
471
+
472
+ expect(seen).toEqual([2, 4]);
473
+ });
437
474
  });