-
Notifications
You must be signed in to change notification settings - Fork 30
[Cleanup] Move cachedDeviceId from module scope into store factory closure #225
Copy link
Copy link
Open
Labels
area/coreTask & Session Core WGTask & Session Core WGgood first issueGood for newcomersGood for newcomerskind/cleanupCategorizes issue or PR as related to code cleanupCategorizes issue or PR as related to code cleanup
Description
What problem are you trying to solve?
cachedDeviceId is a module-level let variable in task-store.ts. Because it lives outside the store factory function, it leaks across store re-creations in the same process. In tests, this means vi.resetModules() is required to get a clean state. Moving it into the factory closure scopes it properly.
Where
packages/core/src/stores/task-store.ts — cachedDeviceId is declared at the module level (around line 95) and mutated inside the hydrate method.
What needs to be done
- Open
packages/core/src/stores/task-store.ts - Find
let cachedDeviceId: string | null = null;at the module level (around line 95) - Move this declaration inside the store factory function (the function that creates and returns the store)
- Verify that the
hydratemethod that setscachedDeviceId = await deps.getDeviceId()still has access to the variable in its new scope - Verify that any reads of
cachedDeviceIdwithin the factory also still work - Run
pnpm checkto verify nothing breaks
Why does this matter?
Module-level mutable state creates implicit coupling between store instances and makes testing harder. Moving it into the factory closure ensures each store instance has its own cache.
Primary area
Task execution
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area/coreTask & Session Core WGTask & Session Core WGgood first issueGood for newcomersGood for newcomerskind/cleanupCategorizes issue or PR as related to code cleanupCategorizes issue or PR as related to code cleanup