fix: immediately run push on commit & push#1830
Conversation
08abd30 to
f8c2d77
Compare
430e157 to
f88cc92
Compare
Prompt To Fix All With AIThis is a comment left during a code review.
Path: apps/code/src/renderer/features/git-interaction/hooks/useGitInteraction.ts
Line: 413-416
Comment:
**Stale `pushMode` closure when commit-push is used**
`runPush()` reads `store.pushMode` from the Zustand snapshot captured at the last React render, but `modal.openPush(...)` updates the Zustand store synchronously via `set()` without triggering a re-render before `runPush()` is called. The component hasn't re-rendered between these two calls, so `store.pushMode` is still the *previously persisted* value.
A concrete failure case: a user previously pushed to a remote repo (`pushMode = "push"` persisted), then switches to a repo without a remote and uses "commit & push". `modal.openPush("publish")` sets the store to `"publish"`, but `runPush()` still reads the stale `"push"` from the closure and calls `trpcClient.git.push` instead of `trpcClient.git.publish`.
The simplest fix is to derive the mode from the same expression used in `openPush` and pass it explicitly:
```typescript
const mode = git.hasRemote ? "push" : "publish";
modal.openPush(mode);
await runPush(mode);
```
…and update `runPush` to accept an optional `mode` parameter, falling back to `store.pushMode` for the standalone push flow.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix: immediately run push on commit & pu..." | Re-trigger Greptile |
| if (store.commitNextStep === "commit-push") { | ||
| modal.openPush(git.hasRemote ? "push" : "publish"); | ||
| await runPush(); | ||
| return; |
There was a problem hiding this comment.
Stale
pushMode closure when commit-push is used
runPush() reads store.pushMode from the Zustand snapshot captured at the last React render, but modal.openPush(...) updates the Zustand store synchronously via set() without triggering a re-render before runPush() is called. The component hasn't re-rendered between these two calls, so store.pushMode is still the previously persisted value.
A concrete failure case: a user previously pushed to a remote repo (pushMode = "push" persisted), then switches to a repo without a remote and uses "commit & push". modal.openPush("publish") sets the store to "publish", but runPush() still reads the stale "push" from the closure and calls trpcClient.git.push instead of trpcClient.git.publish.
The simplest fix is to derive the mode from the same expression used in openPush and pass it explicitly:
const mode = git.hasRemote ? "push" : "publish";
modal.openPush(mode);
await runPush(mode);…and update runPush to accept an optional mode parameter, falling back to store.pushMode for the standalone push flow.
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/git-interaction/hooks/useGitInteraction.ts
Line: 413-416
Comment:
**Stale `pushMode` closure when commit-push is used**
`runPush()` reads `store.pushMode` from the Zustand snapshot captured at the last React render, but `modal.openPush(...)` updates the Zustand store synchronously via `set()` without triggering a re-render before `runPush()` is called. The component hasn't re-rendered between these two calls, so `store.pushMode` is still the *previously persisted* value.
A concrete failure case: a user previously pushed to a remote repo (`pushMode = "push"` persisted), then switches to a repo without a remote and uses "commit & push". `modal.openPush("publish")` sets the store to `"publish"`, but `runPush()` still reads the stale `"push"` from the closure and calls `trpcClient.git.push` instead of `trpcClient.git.publish`.
The simplest fix is to derive the mode from the same expression used in `openPush` and pass it explicitly:
```typescript
const mode = git.hasRemote ? "push" : "publish";
modal.openPush(mode);
await runPush(mode);
```
…and update `runPush` to accept an optional `mode` parameter, falling back to `store.pushMode` for the standalone push flow.
How can I resolve this? If you propose a fix, please make it concise.f8c2d77 to
c7b587f
Compare
f88cc92 to
25b215d
Compare
c7b587f to
cb07e28
Compare
25b215d to
8027df2
Compare
cb07e28 to
172016f
Compare
8027df2 to
6e52943
Compare
172016f to
b5e3a2e
Compare
6e52943 to
1db72f2
Compare
b5e3a2e to
4691a08
Compare
1db72f2 to
79f4277
Compare
79f4277 to
b6575d8
Compare
4691a08 to
34161ec
Compare
b6575d8 to
f40543e
Compare
34161ec to
cbac191
Compare
cbac191 to
d483201
Compare
Merge activity
|

Closes #1814