Skip to content

Commit 0303c29

Browse files
committed
fix(app): failed to create store
1 parent adb0c4d commit 0303c29

2 files changed

Lines changed: 42 additions & 3 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { describe, expect, test } from "bun:test"
2+
import { createRoot, getOwner } from "solid-js"
3+
import { createStore } from "solid-js/store"
4+
import type { State } from "./types"
5+
import { createChildStoreManager } from "./child-store"
6+
7+
const child = () => createStore({} as State)
8+
9+
describe("createChildStoreManager", () => {
10+
test("does not evict the active directory during mark", () => {
11+
const owner = createRoot((dispose) => {
12+
const current = getOwner()
13+
dispose()
14+
return current
15+
})
16+
if (!owner) throw new Error("owner required")
17+
18+
const manager = createChildStoreManager({
19+
owner,
20+
markStats() {},
21+
incrementEvictions() {},
22+
isBooting: () => false,
23+
isLoadingSessions: () => false,
24+
onBootstrap() {},
25+
onDispose() {},
26+
})
27+
28+
Array.from({ length: 30 }, (_, index) => `/pinned-${index}`).forEach((directory) => {
29+
manager.children[directory] = child()
30+
manager.pin(directory)
31+
})
32+
33+
const directory = "/active"
34+
manager.children[directory] = child()
35+
manager.mark(directory)
36+
37+
expect(manager.children[directory]).toBeDefined()
38+
})
39+
})

packages/app/src/context/global-sync/child-store.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function createChildStoreManager(input: {
3636
const mark = (directory: string) => {
3737
if (!directory) return
3838
lifecycle.set(directory, { lastAccessAt: Date.now() })
39-
runEviction()
39+
runEviction(directory)
4040
}
4141

4242
const pin = (directory: string) => {
@@ -106,7 +106,7 @@ export function createChildStoreManager(input: {
106106
return true
107107
}
108108

109-
function runEviction() {
109+
function runEviction(skip?: string) {
110110
const stores = Object.keys(children)
111111
if (stores.length === 0) return
112112
const list = pickDirectoriesToEvict({
@@ -116,7 +116,7 @@ export function createChildStoreManager(input: {
116116
max: MAX_DIR_STORES,
117117
ttl: DIR_IDLE_TTL_MS,
118118
now: Date.now(),
119-
})
119+
}).filter((directory) => directory !== skip)
120120
if (list.length === 0) return
121121
for (const directory of list) {
122122
if (!disposeDirectory(directory)) continue

0 commit comments

Comments
 (0)