Skip to content

Commit 599cb7b

Browse files
committed
Speed up canvas
1 parent 7729655 commit 599cb7b

File tree

9 files changed

+1903
-1763
lines changed

9 files changed

+1903
-1763
lines changed

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/diff-controls.tsx

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { memo, useCallback } from 'react'
12
import { Eye, EyeOff } from 'lucide-react'
23
import { Button } from '@/components/ui/button'
34
import { createLogger } from '@/lib/logs/console/logger'
@@ -9,31 +10,51 @@ import { useWorkflowStore } from '@/stores/workflows/workflow/store'
910

1011
const logger = createLogger('DiffControls')
1112

12-
export function DiffControls() {
13-
const {
14-
isShowingDiff,
15-
isDiffReady,
16-
diffWorkflow,
17-
toggleDiffView,
18-
acceptChanges,
19-
rejectChanges,
20-
diffMetadata,
21-
} = useWorkflowDiffStore()
13+
export const DiffControls = memo(function DiffControls() {
14+
// Optimized: Single diff store subscription
15+
const { isShowingDiff, isDiffReady, diffWorkflow, toggleDiffView, acceptChanges, rejectChanges } =
16+
useWorkflowDiffStore(
17+
useCallback(
18+
(state) => ({
19+
isShowingDiff: state.isShowingDiff,
20+
isDiffReady: state.isDiffReady,
21+
diffWorkflow: state.diffWorkflow,
22+
toggleDiffView: state.toggleDiffView,
23+
acceptChanges: state.acceptChanges,
24+
rejectChanges: state.rejectChanges,
25+
}),
26+
[]
27+
)
28+
)
29+
30+
// Optimized: Single copilot store subscription for needed values
31+
const { updatePreviewToolCallState, clearPreviewYaml, currentChat, messages } = useCopilotStore(
32+
useCallback(
33+
(state) => ({
34+
updatePreviewToolCallState: state.updatePreviewToolCallState,
35+
clearPreviewYaml: state.clearPreviewYaml,
36+
currentChat: state.currentChat,
37+
messages: state.messages,
38+
}),
39+
[]
40+
)
41+
)
2242

23-
const { updatePreviewToolCallState, clearPreviewYaml, currentChat, messages } = useCopilotStore()
24-
const { activeWorkflowId } = useWorkflowRegistry()
43+
const { activeWorkflowId } = useWorkflowRegistry(
44+
useCallback((state) => ({ activeWorkflowId: state.activeWorkflowId }), [])
45+
)
2546

2647
// Don't show anything if no diff is available or diff is not ready
2748
if (!diffWorkflow || !isDiffReady) {
2849
return null
2950
}
3051

31-
const handleToggleDiff = () => {
52+
const handleToggleDiff = useCallback(() => {
3253
logger.info('Toggling diff view', { currentState: isShowingDiff })
3354
toggleDiffView()
34-
}
55+
}, [isShowingDiff, toggleDiffView])
3556

36-
const createCheckpoint = async () => {
57+
const createCheckpoint = useCallback(async () => {
3758
if (!activeWorkflowId || !currentChat?.id) {
3859
logger.warn('Cannot create checkpoint: missing workflowId or chatId', {
3960
workflowId: activeWorkflowId,
@@ -184,9 +205,9 @@ export function DiffControls() {
184205
logger.error('Failed to create checkpoint:', error)
185206
return false
186207
}
187-
}
208+
}, [activeWorkflowId, currentChat, messages])
188209

189-
const handleAccept = async () => {
210+
const handleAccept = useCallback(async () => {
190211
logger.info('Accepting proposed changes with backup protection')
191212

192213
try {
@@ -239,9 +260,9 @@ export function DiffControls() {
239260
console.error('Workflow update failed:', errorMessage)
240261
alert(`Failed to save workflow changes: ${errorMessage}`)
241262
}
242-
}
263+
}, [createCheckpoint, clearPreviewYaml, updatePreviewToolCallState, acceptChanges])
243264

244-
const handleReject = () => {
265+
const handleReject = useCallback(() => {
245266
logger.info('Rejecting proposed changes (optimistic)')
246267

247268
// Clear preview YAML immediately
@@ -279,7 +300,7 @@ export function DiffControls() {
279300
rejectChanges().catch((error) => {
280301
logger.error('Failed to reject changes (background):', error)
281302
})
282-
}
303+
}, [clearPreviewYaml, updatePreviewToolCallState, rejectChanges])
283304

284305
return (
285306
<div className='-translate-x-1/2 fixed bottom-20 left-1/2 z-30'>
@@ -319,4 +340,4 @@ export function DiffControls() {
319340
</div>
320341
</div>
321342
)
322-
}
343+
})

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/context-usage-pill/context-usage-pill.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client'
22

3-
import { Plus } from 'lucide-react'
43
import { memo } from 'react'
4+
import { Plus } from 'lucide-react'
55
import { cn } from '@/lib/utils'
66

77
interface ContextUsagePillProps {
@@ -45,11 +45,11 @@ export const ContextUsagePill = memo(
4545
e.stopPropagation()
4646
onCreateNewChat()
4747
}}
48-
className="inline-flex items-center justify-center hover:opacity-70 transition-opacity"
49-
title="Recommended: Start a new chat for better quality"
50-
type="button"
48+
className='inline-flex items-center justify-center transition-opacity hover:opacity-70'
49+
title='Recommended: Start a new chat for better quality'
50+
type='button'
5151
>
52-
<Plus className="h-3 w-3" />
52+
<Plus className='h-3 w-3' />
5353
</button>
5454
)}
5555
</div>

apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/user-input/user-input.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,14 @@ const UserInput = forwardRef<UserInputRef, UserInputProps>(
183183
const [isLoadingLogs, setIsLoadingLogs] = useState(false)
184184

185185
const { data: session } = useSession()
186-
const { currentChat, workflowId, enabledModels, setEnabledModels, contextUsage, createNewChat } =
187-
useCopilotStore()
186+
const {
187+
currentChat,
188+
workflowId,
189+
enabledModels,
190+
setEnabledModels,
191+
contextUsage,
192+
createNewChat,
193+
} = useCopilotStore()
188194
const params = useParams()
189195
const workspaceId = params.workspaceId as string
190196

@@ -244,7 +250,6 @@ const UserInput = forwardRef<UserInputRef, UserInputProps>(
244250
}
245251
}, [enabledModels, setEnabledModels])
246252

247-
248253
// Auto-resize textarea and toggle vertical scroll when exceeding max height
249254
useEffect(() => {
250255
const textarea = textareaRef.current
@@ -1930,7 +1935,10 @@ const UserInput = forwardRef<UserInputRef, UserInputProps>(
19301935
{/* Context Usage Pill - Top Right */}
19311936
{contextUsage && contextUsage.percentage > 0 && (
19321937
<div className='absolute top-2 right-2 z-10'>
1933-
<ContextUsagePill percentage={contextUsage.percentage} onCreateNewChat={createNewChat} />
1938+
<ContextUsagePill
1939+
percentage={contextUsage.percentage}
1940+
onCreateNewChat={createNewChat}
1941+
/>
19341942
</div>
19351943
)}
19361944
{/* Attached Files Display with Thumbnails */}

0 commit comments

Comments
 (0)