Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/remove-unlinks-stale-parents.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect-atom/atom": patch
---

Unlink a removed node from its parents when it was invalidated before removal, so the parents can be removed too.
4 changes: 0 additions & 4 deletions packages/atom/src/internal/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,6 @@ class Node<A> {
this.state = NodeState.removed
this.listeners.clear()

if (this.lifetime === undefined) {
return
}

this.disposeLifetime()

if (this.previousParents === undefined) {
Expand Down
16 changes: 16 additions & 0 deletions packages/atom/test/Atom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,22 @@ describe("Atom", () => {
unsubscribe()
})

it("removes parents of a node that was invalidated before removal", async () => {
const parent = Atom.make(0)
const source = Atom.make(0)
const child = Atom.make((get) => get(parent) + get(source))
const registry = Registry.make()
const unmount = registry.mount(child)

unmount()
registry.set(source, 1)
await new Promise((resolve) => resolve(null))

const nodes = registry.getNodes()
assert.strictEqual(nodes.has(child), false)
assert.strictEqual(nodes.has(parent), false)
})

it("refresh derived before mount resolves base effect", async () => {
const baseAtom = Atom.make(
Effect.succeed("value").pipe(Effect.delay(100))
Expand Down
Loading