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
2 changes: 1 addition & 1 deletion packages/kit/src/codec/handles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class ValueHandleRegistry {
this.handleToScope.clear()
this.scopeToHandles.clear()
this.objectToHandle = new WeakMap()
this.seed = 0
// Keep seed: a stale handle from before clear() must miss, not resolve to a new object.
}

private evictOverflow(): void {
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/codec/handles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,15 @@ describe('ValueHandleRegistry', () => {
registry.releaseScope('state:component-a')
expect(registry.get(childHandle)).toBeUndefined()
})

it('does not reuse handle ids after clear', () => {
const registry = new ValueHandleRegistry()
const stale = registry.getOrCreate({ old: true })
registry.clear()
const fresh = { fresh: true }
const handle = registry.getOrCreate(fresh)
expect(handle).not.toBe(stale)
expect(registry.get(stale)).toBeUndefined()
expect(registry.get(handle)).toBe(fresh)
})
})
Loading