Skip to content

fix(collab): preserve setup step in browser history#3419

Open
RSO wants to merge 1 commit into
mainfrom
rift-spaghetti
Open

fix(collab): preserve setup step in browser history#3419
RSO wants to merge 1 commit into
mainfrom
rift-spaghetti

Conversation

@RSO
Copy link
Copy Markdown
Contributor

@RSO RSO commented May 22, 2026

Summary

  • Preserve /collab setup and authorize steps in the URL so browser back/forward returns to the previous step instead of leaving the flow.
  • Add shared setup path parsing/building for personal and organization setup URLs, with personal represented by step=1 and no organizationId.

Verification

  • Manually went back-and-forth through the /collab flow in my dev server.

Visual Changes

N/A

Reviewer Notes

  • Personal setup step two uses /collab?step=1; organization setup step two adds organizationId.


export function getSetupWorkspace(searchParams: SearchParamReader): WorkspaceSelection | null {
const organizationId = searchParams.get('organizationId');
if (organizationId) return { type: 'org', id: organizationId, name: '' };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

WARNING: Org workspace name is silently empty when reconstructed from URL

When navigating back or sharing a URL, getSetupWorkspace restores the org workspace with name: ''. The WorkspaceSelector currently uses org.organizationId (from the fetched list) for display, so it doesn't visibly break today. However, workspace.name could be read elsewhere (e.g. in future display code or passed to APIs) and silently produce an empty string. Consider fetching/resolving the org name from the list once loaded, or at minimum add a comment documenting this invariant.

).toBe('/collab?step=1&organizationId=0c06733d-0f2c-42ec-921b-c312fb190427');
});

test('defaults step two to personal workspace when organization is not set', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SUGGESTION: Missing test case for getInitialSetupState with an organizationId in the URL

There's a test for buildSetupPath with org workspace and one for getInitialSetupState with step=1 (personal), but no test for restoring state when organizationId is present in the URL. A round-trip test like the following would catch regressions:

test('restores org workspace state from URL', () => {
  const params = new URLSearchParams({ step: '1', organizationId: 'some-id' });
  expect(getInitialSetupState(params)).toEqual({
    stepIndex: 1,
    workspace: { type: 'org', id: 'some-id', name: '' },
  });
});

const setupSearch = searchParams.toString();
const trpc = useTRPC();
const [stepIndex, setStepIndex] = useState(0);
const initialSetupState = getInitialSetupState(searchParams);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

SUGGESTION: getInitialSetupState is called unconditionally on every render

getInitialSetupState(searchParams) is called in the render body on every render, but its result is only used to seed useState (lines 42–46). React ignores the initializer value on subsequent renders, so this is a wasted computation on every re-render. Consider using the lazy initializer form of useState or wrapping the call in useMemo if the computation becomes heavier, or restructuring to inline the initial values directly in the useState calls.

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented May 22, 2026

Code Review Summary

Status: 3 Issues Found | Recommendation: Address before merge

Executive Summary

Org workspace name is silently empty when restored from URL, which is a latent data-quality issue in the new setup-path state management.

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 2
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/app/collab/_components/setup-path.ts 13 Org workspace reconstructed from URL has name: '', which is silently passed through state and could cause subtle display or API bugs if workspace.name is ever read

SUGGESTION

File Line Issue
apps/web/src/app/collab/_components/setup-path.test.ts 24 Missing test for getInitialSetupState when organizationId is in the URL — the round-trip for org workspace state is untested
apps/web/src/app/collab/_components/BotWizard.tsx 41 getInitialSetupState called unconditionally on every render; result is only used for useState initialization and is discarded on subsequent renders
Files Reviewed (4 files)
  • apps/web/src/app/collab/_components/BotWizard.tsx — 1 suggestion
  • apps/web/src/app/collab/_components/setup-path.ts — 1 warning
  • apps/web/src/app/collab/_components/setup-path.test.ts — 1 suggestion
  • apps/web/src/app/collab/authorize/_components/AuthorizeFlow.tsx — no issues

Fix these issues in Kilo Cloud


Reviewed by claude-4.6-sonnet-20260217 · 617,899 tokens

Review guidance: REVIEW.md from base branch main

Copy link
Copy Markdown
Contributor

@alex-alecu alex-alecu left a comment

Choose a reason for hiding this comment

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

LGTM after fixing code reviewer comments

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants