Skip to content

Commit 53547f0

Browse files
committed
Fix issue with push & create when component unmounts mid way
1 parent 5c7a658 commit 53547f0

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

apps/desktop/src/components/ReviewCreation.svelte

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<script lang="ts" module>
22
export interface CreatePrParams {
3+
stackId: string;
4+
branchName: string;
35
title: string;
46
body: string;
57
draft: boolean;
@@ -193,6 +195,14 @@
193195
if (!branch) return;
194196
if (!$user) return;
195197
198+
// Declare early to have them inside the function closure, in case
199+
// the component unmounts or updates.
200+
const closureStackId = stackId;
201+
const closureBranchName = branchName;
202+
const title = prTitle.value;
203+
const body = shouldAddPrBody() ? prBody.value : '';
204+
const draft = $createDraft;
205+
196206
isCreatingReview = true;
197207
await tick();
198208
@@ -217,11 +227,14 @@
217227
posthog.capture('Butler Review Created');
218228
butRequestDetailsService.setDetails(reviewId, prTitle.value, prBody.value);
219229
}
230+
220231
if ((canPublishPR && $createPullRequest) || !canPublishBR) {
221232
const pr = await createPr({
222-
title: prTitle.value,
223-
body: shouldAddPrBody() ? prBody.value : '',
224-
draft: $createDraft,
233+
stackId: closureStackId,
234+
branchName: closureBranchName,
235+
title,
236+
body,
237+
draft,
225238
upstreamBranchName
226239
});
227240
prNumber = pr?.number;
@@ -310,8 +323,8 @@
310323
// Store the new pull request number with the branch data.
311324
await stackService.updateBranchPrNumber({
312325
projectId,
313-
stackId,
314-
branchName,
326+
stackId: params.stackId,
327+
branchName: params.branchName,
315328
prNumber: pr.number
316329
});
317330

0 commit comments

Comments
 (0)