Skip to content

Conversation

naaa760
Copy link

@naaa760 naaa760 commented Oct 2, 2025

Description

fixes: #2896

  • Fixed branch deletion issue in template copies where users couldn't delete branches even when multiple branches existed. The problem was caused by unreliable local state checking that didn't reflect the actual database state.

Related Issues

  • Fixes the bug where branches aren't deletable in template copies.

Type of Change

  • Bug fix

Summary by CodeRabbit

  • New Features
    • Automatically selects a valid target branch when deleting the active branch for a seamless transition.
  • Bug Fixes
    • Prevents deleting when it would leave no branches, using a live branch count.
    • Deletion logic now uses real-time data instead of cached state for improved reliability.
  • Style
    • Simplified Delete button label to “Delete branch” and removed the “only branch” disabled state to reduce confusion.

Copy link

vercel bot commented Oct 2, 2025

@naaa760 is attempting to deploy a commit to the Onlook Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

coderabbitai bot commented Oct 2, 2025

Walkthrough

Replaced in-memory branch checks with a live database query during deletion, added selection of a valid target branch before deleting an active branch, and simplified the Delete button state and title. The deletion flow now depends on querying remaining branches and switching to a determined target branch when required.

Changes

Cohort / File(s) Summary of Changes
Branch deletion control flow update
apps/web/client/src/app/project/[id]/_components/left-panel/branches-tab/branch-management.tsx
Replace in-memory last-branch detection with live DB check; compute otherBranches from queried remaining branches; select targetBranch (default or first) before deleting if active; throw if ≤1 remaining or no target; simplify Delete button to use isDeleting and static title.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant UI as BranchManagement UI
    participant API as api.branch.getByProjectId
    participant EE as EditorEngine

    U->>UI: Click "Delete branch"
    UI->>API: Query remaining branches for project
    API-->>UI: Remaining branches list
    alt ≤1 remaining
        UI-->>U: Error: cannot delete last/only branch
    else Active branch being deleted?
        alt Yes
            UI->>UI: Determine targetBranch (default or first)
            alt targetBranch exists
                UI->>EE: Switch to targetBranch
            else
                UI-->>U: Error: no valid target branch
            end
            UI->>API: Delete branch
            API-->>UI: Deletion success
            UI-->>U: Update UI (branch removed)
        else No
            UI->>API: Delete branch
            API-->>UI: Deletion success
            UI-->>U: Update UI (branch removed)
        end
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nibbled through branches, neat and clean,
Checked the burrow’s map with a database sheen.
If one twig left—halt! I thump and wait,
Pick a safe limb, then hop to create.
Snip goes the old, the new stands bright—
A tidy warren, just right tonight. 🐇🌿

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description uses a "### Description" header instead of the template’s "## Description" and lacks a required Testing section, while also omitting placeholders for screenshots and additional notes. Please update the description to use the exact template headings (e.g., "## Description"), add a Testing section detailing steps or tests performed, and include any relevant screenshots or additional notes.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly and concisely describes the main change of fixing branch deletion in template copies by querying the database directly, which aligns with the implemented update in the changeset.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/client/src/app/project/[id]/_components/left-panel/branches-tab/branch-management.tsx (1)

1-1: Add 'use client' directive.

This component uses state (useState), event handlers, and is an observer component, so it must be a client component.

As per coding guidelines: observer components must be client components.

Apply this diff to add the directive:

+'use client';
+
 import { useEditorEngine } from '@/components/store/editor';
🧹 Nitpick comments (1)
apps/web/client/src/app/project/[id]/_components/left-panel/branches-tab/branch-management.tsx (1)

76-78: Consider validating projectId before querying.

If editorEngine.projectId is undefined or null, the query will fail with a less clear error message.

Apply this diff to add validation:

         try {
             setIsDeleting(true);
 
+            if (!editorEngine.projectId) {
+                throw new Error('No project selected');
+            }
+
             // Check if this is the last branch by querying the database directly
             const remainingBranches = await api.branch.getByProjectId.query({ 
                 projectId: editorEngine.projectId 
             });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53ec325 and f73e044.

📒 Files selected for processing (1)
  • apps/web/client/src/app/project/[id]/_components/left-panel/branches-tab/branch-management.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
apps/web/client/src/app/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

apps/web/client/src/app/**/*.tsx: Default to Server Components; add 'use client' when using events, state/effects, browser APIs, or client‑only libraries
Do not use process.env in client code; import env from @/env instead

Avoid hardcoded user-facing text; use next-intl messages/hooks

Files:

  • apps/web/client/src/app/project/[id]/_components/left-panel/branches-tab/branch-management.tsx
apps/web/client/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

apps/web/client/src/**/*.{ts,tsx}: Use path aliases @/* and ~/* for imports that map to apps/web/client/src/*
Avoid hardcoded user-facing text; use next-intl messages/hooks instead

Use path aliases @/* and ~/* for imports mapping to src/*

Files:

  • apps/web/client/src/app/project/[id]/_components/left-panel/branches-tab/branch-management.tsx
apps/web/client/src/**/*.tsx

📄 CodeRabbit inference engine (AGENTS.md)

apps/web/client/src/**/*.tsx: Create MobX store instances with useState(() => new Store()) for stable references across renders
Keep the active MobX store in a useRef and perform async cleanup with setTimeout(() => storeRef.current?.clear(), 0) to avoid route-change races
Avoid useMemo for creating MobX store instances
Avoid putting the MobX store instance in effect dependency arrays if it causes loops; split concerns by domain

apps/web/client/src/**/*.tsx: Create MobX store instances with useState(() => new Store()) for stable identities across renders
Keep the active MobX store in a useRef and clean up asynchronously with setTimeout(() => storeRef.current?.clear(), 0)
Do not use useMemo to create MobX stores
Avoid placing MobX store instances in effect dependency arrays if it causes loops; split concerns instead
observer components must be client components; place a single client boundary at the feature entry; child observers need not repeat 'use client'

Files:

  • apps/web/client/src/app/project/[id]/_components/left-panel/branches-tab/branch-management.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Do not use the any type unless necessary

Files:

  • apps/web/client/src/app/project/[id]/_components/left-panel/branches-tab/branch-management.tsx
apps/web/client/src/app/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Default to Server Components; add 'use client' only when using events, state/effects, browser APIs, or client-only libs

Files:

  • apps/web/client/src/app/project/[id]/_components/left-panel/branches-tab/branch-management.tsx
{apps,packages}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Avoid using the any type unless absolutely necessary

Files:

  • apps/web/client/src/app/project/[id]/_components/left-panel/branches-tab/branch-management.tsx
🧬 Code graph analysis (1)
apps/web/client/src/app/project/[id]/_components/left-panel/branches-tab/branch-management.tsx (1)
apps/web/client/src/trpc/react.tsx (1)
  • api (23-23)
🔇 Additional comments (1)
apps/web/client/src/app/project/[id]/_components/left-panel/branches-tab/branch-management.tsx (1)

199-200: LGTM! Simplified Delete button logic.

Moving the last-branch validation to runtime in handleDelete allows for a cleaner button implementation. Users get a clear error message if they attempt an invalid deletion, which is better UX than a disabled button with no explanation.

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.

[bug] When a project is made as a template, branches aren't deletable in a template copy
1 participant