Skip to content

Commit 8839fd7

Browse files
CopilotByron
andcommitted
Fix stackId null handling in frontend API calls
- Fix URL parameter parsing converting null to "null" string - Update branchChanges methods to convert "null" string to null - Update type signatures to accept string | null for stackId - Update mock backend validation to accept null stackId values Co-authored-by: Byron <[email protected]>
1 parent f13c908 commit 8839fd7

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

apps/desktop/cypress/e2e/support/mock/changes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export function isGetCommitChangesParams(args: unknown): args is GetCommitChange
147147

148148
export type GetBranchChangesParams = {
149149
projectId: string;
150-
stackId?: string;
150+
stackId?: string | null;
151151
branch: string;
152152
};
153153

@@ -157,7 +157,7 @@ export function isGetBranchChangesParams(args: unknown): args is GetBranchChange
157157
args !== null &&
158158
'projectId' in args &&
159159
typeof args['projectId'] === 'string' &&
160-
(typeof (args as any).stackId === 'string' || (args as any).stackId === undefined) &&
160+
(typeof (args as any).stackId === 'string' || (args as any).stackId === undefined || (args as any).stackId === null) &&
161161
'branch' in args &&
162162
typeof args['branch'] === 'string'
163163
);

apps/desktop/src/lib/stacks/stackService.svelte.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,12 @@ export class StackService {
602602
* If the branch is part of a stack and if the stackId is provided, this will include only the changes up to the next branch in the stack.
603603
* Otherwise, if stackId is not provided, this will include all changes as compared to the target branch
604604
*/
605-
branchChanges(args: { projectId: string; stackId?: string; branch: BranchRef }) {
605+
branchChanges(args: { projectId: string; stackId?: string | null; branch: BranchRef }) {
606606
return this.api.endpoints.branchChanges.useQuery(
607607
{
608608
projectId: args.projectId,
609-
stackId: args.stackId,
609+
// Handle case where URL parameters convert null to "null" string
610+
stackId: args.stackId === 'null' ? null : args.stackId,
610611
branch: args.branch
611612
},
612613
{
@@ -618,11 +619,12 @@ export class StackService {
618619
);
619620
}
620621

621-
branchChange(args: { projectId: string; stackId?: string; branch: BranchRef; path: string }) {
622+
branchChange(args: { projectId: string; stackId?: string | null; branch: BranchRef; path: string }) {
622623
return this.api.endpoints.branchChanges.useQuery(
623624
{
624625
projectId: args.projectId,
625-
stackId: args.stackId,
626+
// Handle case where URL parameters convert null to "null" string
627+
stackId: args.stackId === 'null' ? null : args.stackId,
626628
branch: args.branch
627629
},
628630
{ transform: (result) => changesSelectors.selectById(result.changes, args.path) }
@@ -631,14 +633,15 @@ export class StackService {
631633

632634
async branchChangesByPaths(args: {
633635
projectId: string;
634-
stackId?: string;
636+
stackId?: string | null;
635637
branch: BranchRef;
636638
paths: string[];
637639
}) {
638640
const result = await this.api.endpoints.branchChanges.fetch(
639641
{
640642
projectId: args.projectId,
641-
stackId: args.stackId,
643+
// Handle case where URL parameters convert null to "null" string
644+
stackId: args.stackId === 'null' ? null : args.stackId,
642645
branch: args.branch
643646
},
644647
{ transform: (result) => selectChangesByPaths(result.changes, args.paths) }
@@ -1185,7 +1188,7 @@ function injectEndpoints(api: ClientState['backendApi'], uiState: UiState) {
11851188
}),
11861189
branchChanges: build.query<
11871190
{ changes: EntityState<TreeChange, string>; stats: TreeStats },
1188-
{ projectId: string; stackId?: string; branch: BranchRef }
1191+
{ projectId: string; stackId?: string | null; branch: BranchRef }
11891192
>({
11901193
extraOptions: { command: 'changes_in_branch' },
11911194
query: (args) => args,

apps/desktop/src/routes/[projectId]/workspace/+page.svelte

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717
const stackId = $derived(projectState.stackId.current);
1818
1919
// Check for stackId in URL query parameters
20-
const urlStackId = $derived(page.url.searchParams.get('stackId'));
20+
// Note: URLSearchParams.get() returns strings, so "null" becomes the string "null"
21+
// We need to convert it back to actual null for proper API handling
22+
const urlStackId = $derived((() => {
23+
const param = page.url.searchParams.get('stackId');
24+
// Convert string "null" back to actual null
25+
return param === 'null' ? null : param;
26+
})());
2127
let scrollToStackId = $state<string | undefined>(undefined);
2228
2329
const firstStackResult = $derived(stackService.stackAt(projectId, 0));
@@ -29,7 +35,7 @@
2935
});
3036
3137
$effect(() => {
32-
if (urlStackId) {
38+
if (urlStackId !== null) {
3339
projectState.stackId.set(urlStackId);
3440
scrollToStackId = urlStackId;
3541
} else if (stackId === undefined && firstStack) {

0 commit comments

Comments
 (0)