Skip to content

fix(settings): restore last-used workspace mode after async hydration#2613

Merged
tatoalo merged 1 commit into
mainfrom
posthog-code/persist-workspace-mode-on-relaunch
Jun 11, 2026
Merged

fix(settings): restore last-used workspace mode after async hydration#2613
tatoalo merged 1 commit into
mainfrom
posthog-code/persist-workspace-mode-on-relaunch

Conversation

@tatoalo

@tatoalo tatoalo commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown

React Doctor could not complete this scan.

No React dependency found in /tmp/react-doctor-baseline-3yz917/package.json. Add "react" to dependencies (or peerDependencies) and re-run.

Reviewed by React Doctor for commit 498f2d9.

@greptile-apps

greptile-apps Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix 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

Comment thread packages/ui/src/features/settings/settingsStore.test.ts Outdated
@tatoalo tatoalo force-pushed the posthog-code/persist-workspace-mode-on-relaunch branch from 18c8dbd to 429ac8b Compare June 11, 2026 14:43
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
@tatoalo tatoalo force-pushed the posthog-code/persist-workspace-mode-on-relaunch branch from 429ac8b to 498f2d9 Compare June 11, 2026 14:47
@tatoalo tatoalo self-assigned this Jun 11, 2026
@tatoalo tatoalo marked this pull request as ready for review June 11, 2026 15:55
@tatoalo tatoalo added the Stamphog This will request an autostamp by stamphog on small changes label Jun 11, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@tatoalo tatoalo merged commit c8bdcaf into main Jun 11, 2026
30 checks passed
@tatoalo tatoalo deleted the posthog-code/persist-workspace-mode-on-relaunch branch June 11, 2026 16:00
@greptile-apps

greptile-apps Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "fix(settings): restore last-used workspa..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stamphog This will request an autostamp by stamphog on small changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant