fix(settings): restore last-used workspace mode after async hydration#2613
Conversation
|
React Doctor could not complete this scan.
Reviewed by React Doctor for commit |
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
packages/ui/src/features/settings/settingsStore.test.ts:79-111
The two new rehydration tests are structurally identical — both mock a persisted value, pre-set the opposite value in state, call `persist.rehydrate()`, then assert the stored value was adopted. They should be collapsed into a single parameterised test, consistent with the team's preference. The `_hasHydrated` test is distinct enough to stay separate.
```suggestion
it.each([
["lastUsedWorkspaceMode", "local", "cloud"],
["debugLogsCloudRuns", false, true],
] as const)(
"rehydrates %s",
async (field, initial, persisted) => {
getItem.mockResolvedValue(
JSON.stringify({ state: { [field]: persisted }, version: 0 }),
);
useSettingsStore.setState({ [field]: initial });
await useSettingsStore.persist.rehydrate();
expect(useSettingsStore.getState()[field]).toBe(persisted);
},
);
```
Reviews (1): Last reviewed commit: "fix(settings): restore last-used workspa..." | Re-trigger Greptile |
18c8dbd to
429ac8b
Compare
The settings store persists lastUsedWorkspaceMode and debugLogsCloudRuns, but it rehydrates asynchronously from the host-backed (tRPC/encrypted) storage. Regressed in #2047: TaskInput previously derived the workspace mode reactively, which re-read the rehydrated value after a relaunch. #2047 converted it to a one-shot useState initializer that runs before hydration completes, so it locked in the default "local" and never adopted the rehydrated value — and on task creation that stale "local" was written back, poisoning the stored preference. Make hydration observable via an onRehydrateStorage _hasHydrated flag (mirroring draftStore) and have TaskInput adopt the rehydrated workspace mode once it lands, unless a cloud repo was forced via props or the user already picked a mode. Add regression tests covering rehydration of the workspace mode, the debug-logs-for-cloud-runs toggle, and the hydration flag. Generated-By: PostHog Code Task-Id: 817c46ca-bccc-4979-bc70-d3587cdb79aa
429ac8b to
498f2d9
Compare
There was a problem hiding this comment.
Clean, low-risk fix for async hydration race: adds a runtime-only _hasHydrated flag (excluded from partialize, so not persisted) and defers workspace mode restoration in TaskInput until after the persist middleware rehydrates. Bot review comment about parameterized tests was addressed.
|
Reviews (2): Last reviewed commit: "fix(settings): restore last-used workspa..." | Re-trigger Greptile |
Problem
when you create a cloud task, then quit and relaunch PostHog Code, the new-task tab defaults back to local instead of the workspace mode you last used. The "debug logs for cloud runs" toggle in advanced settings was reported as not surviving restarts either. this was a recent regression, the bug is purely in how the value is read on mount.