Skip to content

Commit d1b0184

Browse files
authored
improvement(perf): cut server-only and unused code out of the workspace client bundles (#6975)
* improvement(perf): cut server-only and unused code out of the workspace client bundles Every workspace route shipped JavaScript it never executes. Four independent import edges, each fixed by moving a symbol rather than changing behaviour: - js-tiktoken's BPE rank tables (5.4 MB source / 2.5 MB wire) reached the workflow editor because the tokenization barrel re-exported the exact counters alongside the character heuristics. Split into lib/tokenization/accurate.ts, which the barrel no longer re-exports. - crypto-browserify (~105 KB gzip, all 26 workspace routes) came from the Salesforce and Gong triggers importing webhook provider modules that reach node:crypto through @sim/security. The two symbols they actually needed are now in crypto-free modules. - tables, files and knowledge each imported one dependency-free hook from the sidebar-hooks barrel, whose other exports reach the 5 MB generated tool-metadata artifact. Deep-imported per the code-splitting rule in sim-imports.md. - lib/workflows/subblocks/display.ts imported a string constant from a React module under app/, inverting the app/lib layering. Moved to lib/. Also adds a loading boundary to chat/[chatId]. Without one, a dynamic route is prefetched as nothing, so clicking a chat held the previous chat on screen for the whole server round trip. Measured on a production build, JS downloaded before the load event: /w/[workflowId] 7.38 MB -> 4.80 MB (-35%) /logs 4.57 MB -> 4.44 MB /knowledge 4.35 MB -> 4.22 MB /home 4.57 MB -> 4.44 MB crypto-browserify no longer appears in any shipped chunk. The tool-registry boundary baseline is retightened so the reclaimed graph weight cannot silently regress. * improvement(sidebar): move useContextMenu to shared hooks Review flagged the four workspace routes deep-importing `useContextMenu` from the sidebar's hooks barrel as a barrel-convention violation. Fair — the code-splitting exception in sim-imports.md is written for `lazy()` splits, and these are static imports. The hook was in the wrong place to begin with. It is entirely generic — no sidebar-specific references, just right-click state and positioning — and nine consumers across tables, files, knowledge, home, the terminal and the preview editor already reached across features to get it. Moved to `@/hooks`, the repo's shared-hooks location, and every consumer including the sidebar's own now imports it from there. This satisfies the barrel convention rather than making an exception to it, and keeps the graph win: tables, knowledge and files stay off the sidebar barrel's path to `stores/workflow-diff -> serializer -> tools/metadata`, unchanged at 20.19 / 20.89 / 21.37 MB of reachable source.
1 parent 3a04426 commit d1b0184

39 files changed

Lines changed: 445 additions & 380 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { HomeFallback } from '@/app/workspace/[workspaceId]/home/home-fallback'
2+
3+
/**
4+
* Route-level loading boundary for a chat.
5+
*
6+
* Its real job is prefetching, not painting. With `cacheComponents` off, a
7+
* default `<Link>` prefetch degrades to Next's LoadingBoundary strategy, which
8+
* prefetches a dynamic route only as far as its nearest `loading` segment — so
9+
* a route without one is prefetched as nothing, and clicking a chat leaves the
10+
* previous chat frozen on screen until the server responds. This file is what
11+
* makes that click commit immediately.
12+
*
13+
* Renders the same surface `HomeFallback` gives the Suspense boundary inside
14+
* the page, so the loading frame and the mounted frame share a background and
15+
* the transition reads as one step rather than two.
16+
*/
17+
export default function ChatLoading() {
18+
return <HomeFallback />
19+
}

apps/sim/app/workspace/[workspaceId]/files/files.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ import {
128128
} from '@/app/workspace/[workspaceId]/files/untitled-title'
129129
import { useRegisterGlobalCommands } from '@/app/workspace/[workspaceId]/providers/global-commands-provider'
130130
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
131-
import { useContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks'
132131
import { usePinItem, usePinnedIds, useUnpinItem } from '@/hooks/queries/pinned-items'
133132
import { useWorkspaceMembersQuery, type WorkspaceMember } from '@/hooks/queries/workspace'
134133
import {
@@ -147,6 +146,7 @@ import {
147146
useUploadWorkspaceFile,
148147
useWorkspaceFiles,
149148
} from '@/hooks/queries/workspace-files'
149+
import { useContextMenu } from '@/hooks/use-context-menu'
150150
import { useDebouncedSearchSetter } from '@/hooks/use-debounced-search-setter'
151151
import { useInlineRename } from '@/hooks/use-inline-rename'
152152
import { usePermissionConfig } from '@/hooks/use-permission-config'

apps/sim/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/components/terminal-session/terminal-session.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { WebLinksAddon } from '@xterm/addon-web-links'
3434
import { WebglAddon } from '@xterm/addon-webgl'
3535
import { type IBufferRange, Terminal } from '@xterm/xterm'
3636
import { useTheme } from 'next-themes'
37+
import { useContextMenu } from '@/hooks/use-context-menu'
3738
import '@xterm/xterm/css/xterm.css'
3839
import {
3940
describeRunningCommand,
@@ -73,7 +74,6 @@ import { useMothershipResources } from '@/app/workspace/[workspaceId]/home/compo
7374
import { TerminalContextMenu } from '@/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/components/terminal-session/terminal-context-menu'
7475
import { TerminalTabIcon } from '@/app/workspace/[workspaceId]/home/components/mothership-view/components/resource-content/components/terminal-session/terminal-tab-icon'
7576
import { ContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/components/workflow-list/components/context-menu/context-menu'
76-
import { useContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks'
7777
import { useDesktopPreferenceMutation } from '@/hooks/use-desktop-preference-mutation'
7878
import { useCopilotTerminalStore } from '@/stores/copilot-terminal/store'
7979
import type { ChatContext, TerminalTextSelection } from '@/stores/panel'

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/[documentId]/components/chunk-editor/chunk-editor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { isApiClientError } from '@/lib/api/client/errors'
66
import { requestJson } from '@/lib/api/client/request'
77
import { getKnowledgeChunkContract } from '@/lib/api/contracts/knowledge'
88
import type { ChunkData, DocumentData } from '@/lib/knowledge/types'
9-
import { getAccurateTokenCount, getTokenStrings } from '@/lib/tokenization/estimators'
9+
import { getAccurateTokenCount, getTokenStrings } from '@/lib/tokenization/accurate'
1010
import { useCreateChunk, useUpdateChunk } from '@/hooks/queries/kb/knowledge'
1111
import { useAutosave } from '@/hooks/use-autosave'
1212

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/[documentId]/document.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ import {
5959
import { ActionBar } from '@/app/workspace/[workspaceId]/knowledge/[id]/components'
6060
import { getDocumentIcon } from '@/app/workspace/[workspaceId]/knowledge/components'
6161
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
62-
import { useContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks'
6362
import { CONNECTOR_META_REGISTRY } from '@/connectors/registry'
6463
import { useDocument, useDocumentChunks, useKnowledgeBase } from '@/hooks/kb/use-knowledge'
6564
import {
@@ -69,6 +68,7 @@ import {
6968
useUpdateChunk,
7069
useUpdateDocument,
7170
} from '@/hooks/queries/kb/knowledge'
71+
import { useContextMenu } from '@/hooks/use-context-menu'
7272
import { useDebounce } from '@/hooks/use-debounce'
7373
import { useDebouncedSearchSetter } from '@/hooks/use-debounced-search-setter'
7474
import { useInlineRename } from '@/hooks/use-inline-rename'

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/base.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ import {
9797
import { getDocumentIcon } from '@/app/workspace/[workspaceId]/knowledge/components'
9898
import { useRegisterGlobalCommands } from '@/app/workspace/[workspaceId]/providers/global-commands-provider'
9999
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
100-
import { useContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks'
101100
import { BrandIcon } from '@/blocks/brand-icon'
102101
import { CONNECTOR_META_REGISTRY } from '@/connectors/registry'
103102
import {
@@ -119,6 +118,7 @@ import {
119118
useUpdateDocument,
120119
useUpdateKnowledgeBase,
121120
} from '@/hooks/queries/kb/knowledge'
121+
import { useContextMenu } from '@/hooks/use-context-menu'
122122
import { useDebounce } from '@/hooks/use-debounce'
123123
import { useDebouncedSearchSetter } from '@/hooks/use-debounced-search-setter'
124124
import { useInlineRename } from '@/hooks/use-inline-rename'

apps/sim/app/workspace/[workspaceId]/knowledge/knowledge.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ import {
7979
} from '@/app/workspace/[workspaceId]/knowledge/search-params'
8080
import { useRegisterGlobalCommands } from '@/app/workspace/[workspaceId]/providers/global-commands-provider'
8181
import { useUserPermissionsContext } from '@/app/workspace/[workspaceId]/providers/workspace-permissions-provider'
82-
import { useContextMenu } from '@/app/workspace/[workspaceId]/w/components/sidebar/hooks'
8382
import { BrandIcon } from '@/blocks/brand-icon'
8483
import { CONNECTOR_META_REGISTRY } from '@/connectors/registry'
8584
import { useKnowledgeBasesList } from '@/hooks/kb/use-knowledge'
@@ -92,6 +91,7 @@ import {
9291
} from '@/hooks/queries/kb/knowledge'
9392
import { usePinItem, usePinnedIds, useUnpinItem } from '@/hooks/queries/pinned-items'
9493
import { useWorkspaceMembersQuery, type WorkspaceMember } from '@/hooks/queries/workspace'
94+
import { useContextMenu } from '@/hooks/use-context-menu'
9595
import { useDebouncedSearchSetter } from '@/hooks/use-debounced-search-setter'
9696
import { useInlineRename } from '@/hooks/use-inline-rename'
9797
import { usePermissionConfig } from '@/hooks/use-permission-config'

apps/sim/app/workspace/[workspaceId]/logs/components/dashboard/components/workflows-list/workflows-list.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { memo } from 'react'
22
import { cn, handleKeyboardActivation } from '@sim/emcn'
33
import { Workflow } from '@sim/emcn/icons'
4+
import { DELETED_WORKFLOW_LABEL } from '@/lib/workflows/workflow-labels'
45
import { FloatingOverflowText } from '@/app/workspace/[workspaceId]/components'
5-
import { DELETED_WORKFLOW_LABEL } from '@/app/workspace/[workspaceId]/logs/utils'
66
import { StatusBar, type StatusBarSegment } from '..'
77

88
export interface WorkflowExecutionItem {

apps/sim/app/workspace/[workspaceId]/logs/components/log-details/log-details.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { MothershipHandoffStorage } from '@/lib/core/utils/browser-storage'
4747
import { filterHiddenOutputKeys } from '@/lib/logs/execution/trace-spans/trace-spans'
4848
import type { TraceSpan } from '@/lib/logs/types'
4949
import { sendMothershipMessage } from '@/lib/mothership/events'
50+
import { DELETED_WORKFLOW_LABEL } from '@/lib/workflows/workflow-labels'
5051
import {
5152
ExecutionSnapshot,
5253
FileCards,
@@ -58,7 +59,6 @@ import {
5859
logDetailsTabUrlKeys,
5960
} from '@/app/workspace/[workspaceId]/logs/search-params'
6061
import {
61-
DELETED_WORKFLOW_LABEL,
6262
formatDate,
6363
getDisplayStatus,
6464
resolveLogWorkflowId,

apps/sim/app/workspace/[workspaceId]/logs/logs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
type WorkflowData,
5050
} from '@/lib/logs/search-suggestions'
5151
import { SEARCH_DEBOUNCE_MS } from '@/lib/url-state'
52+
import { DELETED_WORKFLOW_LABEL } from '@/lib/workflows/workflow-labels'
5253
import type {
5354
FilterTag,
5455
ResourceAction,
@@ -94,7 +95,6 @@ import { useFilterStore } from '@/stores/logs/filters/store'
9495
import { CORE_TRIGGER_TYPES } from '@/stores/logs/filters/types'
9596
import { Dashboard, ExecutionSnapshot, LogDetails, LogRowContextMenu } from './components'
9697
import {
97-
DELETED_WORKFLOW_LABEL,
9898
formatDate,
9999
getDisplayStatus,
100100
type LogStatus,

0 commit comments

Comments
 (0)