-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: add branching #2763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Kitenite
wants to merge
15
commits into
main
Choose a base branch
from
feat/branching
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: add branching #2763
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0751df4
update types
Kitenite 161fc61
update dto to mappers
Kitenite f8216d2
update dto to mappers
Kitenite efc8855
clean up
Kitenite d51ebdb
add main branch
Kitenite f5b677b
add branch route
Kitenite f4bc424
update schema
Kitenite 2bd9daf
clean up
Kitenite b4d6f19
saving state
Kitenite 61a01e8
merge main
Kitenite 769610c
update seed script
Kitenite d394578
working create
Kitenite 4727ebe
fix types
Kitenite 5eb19fc
fix types
Kitenite 8386d2d
saving
Kitenite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
apps/web/client/src/components/store/editor/branch/manager.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import type { Branch } from '@onlook/models'; | ||
import { makeAutoObservable } from 'mobx'; | ||
import type { EditorEngine } from '../engine'; | ||
import { SandboxManager } from '../sandbox'; | ||
|
||
export class BranchManager { | ||
private editorEngine: EditorEngine; | ||
private currentBranchId: string | null = null; | ||
private branchIdToSandboxManager = new Map<string, SandboxManager>(); | ||
|
||
constructor(editorEngine: EditorEngine) { | ||
this.editorEngine = editorEngine; | ||
makeAutoObservable(this); | ||
} | ||
|
||
get currentBranch(): string | null { | ||
return this.currentBranchId; | ||
} | ||
|
||
getCurrentSandbox(): SandboxManager { | ||
if (!this.currentBranchId) { | ||
throw new Error('No branch selected. Call switchToBranch() first.'); | ||
} | ||
|
||
if (!this.branchIdToSandboxManager.has(this.currentBranchId)) { | ||
const sandboxManager = new SandboxManager(this.editorEngine); | ||
this.branchIdToSandboxManager.set(this.currentBranchId, sandboxManager); | ||
} | ||
|
||
return this.branchIdToSandboxManager.get(this.currentBranchId)!; | ||
} | ||
|
||
async startCurrentBranchSandbox(): Promise<void> { | ||
if (!this.currentBranchId) { | ||
throw new Error('No branch selected. Call switchToBranch() first.'); | ||
} | ||
|
||
const branch = await this.getBranchById(this.currentBranchId); | ||
await this.getCurrentSandbox().session.start(branch.sandbox.id); | ||
} | ||
|
||
async switchToBranch(branchId: string): Promise<void> { | ||
if (this.currentBranchId === branchId) { | ||
return; | ||
} | ||
|
||
this.currentBranchId = branchId; | ||
} | ||
|
||
async createBranch( | ||
name: string, | ||
description?: string, | ||
fromBranchId?: string, | ||
isDefault = false | ||
): Promise<Branch> { | ||
const newBranch: Branch = { | ||
id: `branch-${Date.now()}`, | ||
name, | ||
description: description || null, | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
git: null, | ||
sandbox: { | ||
id: `sandbox-${Date.now()}`, | ||
}, | ||
}; | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return newBranch; | ||
} | ||
|
||
async deleteBranch(branchId: string): Promise<void> { | ||
if (branchId === this.currentBranchId) { | ||
throw new Error('Cannot delete the currently active branch'); | ||
} | ||
|
||
const sandboxManager = this.branchIdToSandboxManager.get(branchId); | ||
if (sandboxManager) { | ||
sandboxManager.clear(); | ||
this.branchIdToSandboxManager.delete(branchId); | ||
} | ||
} | ||
|
||
async getDefaultBranch(): Promise<Branch> { | ||
return { | ||
id: 'main-branch-id', | ||
name: 'main', | ||
description: 'Default main branch', | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
git: null, | ||
sandbox: { | ||
id: 'main-sandbox-id', | ||
}, | ||
}; | ||
} | ||
|
||
async getBranchById(branchId: string): Promise<Branch> { | ||
return { | ||
id: branchId, | ||
name: branchId === 'main-branch-id' ? 'main' : `branch-${branchId}`, | ||
description: null, | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
git: null, | ||
sandbox: { | ||
id: `${branchId}-sandbox`, | ||
}, | ||
}; | ||
} | ||
|
||
|
||
private async createMainBranch(): Promise<Branch> { | ||
return { | ||
id: 'main-branch-id', | ||
name: 'main', | ||
description: 'Default main branch', | ||
createdAt: new Date(), | ||
updatedAt: new Date(), | ||
git: null, | ||
sandbox: { | ||
id: 'main-sandbox-id', | ||
}, | ||
}; | ||
} | ||
|
||
async listBranches(): Promise<Branch[]> { | ||
return []; | ||
} | ||
|
||
clear(): void { | ||
for (const sandboxManager of this.branchIdToSandboxManager.values()) { | ||
sandboxManager.clear(); | ||
} | ||
this.branchIdToSandboxManager.clear(); | ||
this.currentBranchId = null; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Confirm lastScreenshotAt type; updatedAt may be Date/string vs previous numeric timestamp
The old field (updatedPreviewImgAt) was likely a number (epoch ms). The new chain uses previewImg?.updatedAt, which may be a string/Date. If consumers of editorEngine.screenshot.lastScreenshotAt expect a number, this will silently break comparisons/sorts.
Run this to verify both types before we normalize:
If lastScreenshotAt should remain a number, normalize:
If it's allowed to be a string/Date, consider renaming the field or adding a JSDoc to prevent type drift.
🏁 Script executed:
Length of output: 8912
Fix mismatched types for
lastScreenshotAt
The
screenshot.lastScreenshotAt
setter is typed asDate | null
, butproject.metadata.previewImg?.updatedAt
is astring
(perpackages/models/src/project/project.ts
), so assigning it directly will store astring
instead of aDate
.• In
apps/web/client/src/app/project/[id]/_hooks/use-start-project.tsx
(line 44)• Normalize the string to a
Date
:Consider adding a JSDoc or strengthening the type for
previewImg.updatedAt
if you ever intend to accept other formats.📝 Committable suggestion
🤖 Prompt for AI Agents