improvement(perf): cut server-only and unused code out of the workspace client bundles - #6975
Conversation
…ce 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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryMedium Risk Overview Exact tiktoken counting moves from Gong/Salesforce triggers now import crypto-free helpers (
Adds Reviewed by Cursor Bugbot for commit 2487a0f. Configure here. |
Greptile SummaryThe PR reduces workspace client bundles by separating server-only and heavyweight dependencies from browser-facing import graphs, relocating a generic context-menu hook into the shared hooks directory, and adding a chat loading boundary.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the previously reported import-boundary issue was resolved by moving the generic hook unchanged into shared hooks, updating all consumers, and removing the competing sidebar export.
|
| Filename | Overview |
|---|---|
| apps/sim/hooks/use-context-menu.ts | Relocates the generic hook without implementation changes; consumers consistently use the new shared path. |
| apps/sim/app/workspace/[workspaceId]/w/components/sidebar/hooks/index.ts | Removes the obsolete context-menu re-export after all affected consumers were migrated. |
| apps/sim/lib/tokenization/accurate.ts | Isolates heavyweight exact-tokenization helpers from the lightweight tokenization barrel. |
| apps/sim/lib/webhooks/providers/salesforce-payload.ts | Extracts payload-shape logic so client-side trigger code no longer imports the server webhook-provider graph. |
| apps/sim/lib/webhooks/providers/gong-config.ts | Extracts Gong configuration metadata into a crypto-free module for client consumers. |
| apps/sim/app/workspace/[workspaceId]/chat/[chatId]/loading.tsx | Adds a route loading boundary using the existing home fallback surface. |
Reviews (2): Last reviewed commit: "improvement(sidebar): move useContextMen..." | Re-trigger Greptile
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.
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 2487a0f. Configure here.
Summary
Every workspace route was shipping JavaScript it never executes. Four independent import edges, each fixed by moving a symbol — no behaviour changes.
js-tiktoken(5.4 MB source / 2.5 MB wire) reached the workflow editor because the tokenization barrel re-exported the exact counters next to the character heuristics. Split intolib/tokenization/accurate.ts; the barrel no longer re-exports them. Only the KB chunk editor, embeddings client, and agent memory handler need exact counts, and all three still get them.crypto-browserify(~105 KB gzip, all 26 workspace routes) came from the Salesforce and Gong triggers importing webhook provider modules that reachnode:cryptovia@sim/security— server-only signature verification shipping to every browser. The two symbols the triggers actually need (a payload-shape helper and a config key) moved to crypto-free modules.tables,files,knowledgeeach imported one dependency-free hook (useContextMenu) from the 21-export sidebar-hooks barrel, whose other exports reach the 5 MB generatedtool-metadataartifact viastores/workflow-diff → serializer. Deep-imported per the "Code-splitting through barrels" rule insim-imports.md. The barrel export stays — sidebar internals still use it.lib/workflows/subblocks/display.tsimported a string constant from a React module underapp/, inverting the app/lib layering and pulling React + emcn + the block registry along for one string. Moved tolib/workflows/workflow-labels.ts.Also adds a loading boundary to
chat/[chatId]. WithcacheComponentsoff, a<Link>prefetch degrades to Next's LoadingBoundary strategy, which prefetches a dynamic route only as far as its nearestloadingsegment — so a route without one is prefetched as nothing and the click held the previous chat on screen for the whole server round trip.Measurements
Production build, JS downloaded before the load event:
/w/[workflowId]/logs/knowledge/homecrypto-browserifyno longer appears in any shipped chunk. The tool-registry boundary baseline is retightened so the reclaimed graph weight can't silently regress.Worth setting expectations on the last three rows: the barrel fix removes ~5.3 MB of source from those route graphs but only ~130 KB of wire bytes, because the persistent sidebar and socket provider in the workspace layout reach the same modules through
hooks/queries/deployments → workflows/comparison/compare → hooks/selectors/registry. Until that shell edge is addressed, per-route graph fixes can't pay out fully. Noted below.Not in this PR
Investigated and deliberately left out:
value: () => …closures across 271 files,tools.config.toolin 268 files, andiconfields that are React components.serializerandvisibilitylegitimately need the closures.staleTimes.dynamic. Refuted — it's live at exactly one call site reachable only through the BFCache path; the segment cache underSTATIC_STALETIME_MSis what already serves these navigations. It would buy nothing and accept stale session-dependent output.loading.tsxforw/[workflowId]. Written, then dropped: it reproducibly caused a React chore(deps): bump the workspace-dependencies group with 22 updates #418 hydration mismatch on that route. Confirmed by A/B — clean build without the file, error with it. The editor's loading boundary needs to match its SSR output, which is its own piece of work.Type of Change
Testing
Tested manually against a production build. 1,264 tests pass across the touched areas (tokenization, embeddings, agent memory, webhook providers, salesforce/gong triggers, workflow subblocks, logs).
bun run type-checkclean,bun run lintclean, all 32 audits incheck:auditspass, block-registry audit passes. All eight workspace routes verified rendering with zero console errors in a headless browser.Checklist