From 3ca742e15706467c590bd07960d212affd774ff4 Mon Sep 17 00:00:00 2001 From: waleed Date: Sat, 17 Jan 2026 19:14:06 -0800 Subject: [PATCH] improvement(performance): used react scan to identify rerendering issues and react issues --- .../message/components/markdown-renderer.tsx | 48 +- apps/sim/app/layout.tsx | 9 +- .../workspace-permissions-provider.tsx | 6 +- .../components/action-bar/action-bar.tsx | 18 +- .../components/markdown-renderer.tsx | 15 +- .../components/copilot-message/hooks/index.ts | 2 - .../hooks/use-message-feedback.ts | 138 -- .../hooks/use-success-timers.ts | 77 -- .../components/tool-call/tool-call.tsx | 598 +-------- .../user-input/hooks/use-mention-data.ts | 2 +- .../user-input/hooks/use-mention-tokens.ts | 34 +- .../components/user-input/user-input.tsx | 9 +- .../sub-block/components/code/code.tsx | 160 ++- .../components/combobox/combobox.tsx | 211 +-- .../components/dropdown/dropdown.tsx | 28 +- .../messages-input/messages-input.tsx | 15 +- .../components/short-input/short-input.tsx | 6 +- .../components/starter/input-format.tsx | 89 +- .../components/tool-input/tool-input.tsx | 6 +- .../sub-block/hooks/use-depends-on-gate.ts | 74 +- .../sub-block/hooks/use-sub-block-value.ts | 33 +- .../editor/components/sub-block/sub-block.tsx | 20 +- .../panel/components/editor/editor.tsx | 23 +- .../editor/hooks/use-block-connections.ts | 7 +- .../editor/hooks/use-connections-resize.ts | 8 +- .../hooks/use-editor-block-properties.ts | 52 +- .../editor/hooks/use-subflow-editor.ts | 15 +- .../panel/components/toolbar/toolbar.tsx | 1158 ++++++++-------- .../w/[workflowId]/components/panel/panel.tsx | 42 +- .../components/terminal/terminal.tsx | 1042 ++++++++------- .../components/workflow-block/utils.ts | 12 +- .../workflow-block/workflow-block.tsx | 100 +- .../workflow-controls/workflow-controls.tsx | 11 +- .../w/[workflowId]/hooks/use-block-visual.ts | 14 +- .../components/search-modal/search-modal.tsx | 181 +-- .../workflow-item/workflow-item.tsx | 7 +- .../sidebar/hooks/use-workflow-operations.ts | 25 +- .../sidebar/hooks/use-workspace-management.ts | 10 +- .../w/components/sidebar/sidebar.tsx | 32 +- .../w/hooks/use-duplicate-workflow.ts | 30 +- .../w/hooks/use-export-workflow.ts | 11 +- .../workspace/providers/socket-provider.tsx | 89 +- .../emcn/components/combobox/combobox.tsx | 1161 +++++++++-------- .../emcn/components/modal/modal.tsx | 2 +- apps/sim/hooks/use-collaborative-workflow.ts | 321 +++-- apps/sim/hooks/use-permission-config.ts | 34 +- apps/sim/hooks/use-undo-redo.ts | 260 ++-- apps/sim/hooks/use-workspace-permissions.ts | 4 +- apps/sim/lib/core/config/env.ts | 1 + apps/sim/lib/core/config/feature-flags.ts | 6 + apps/sim/stores/operation-queue/store.ts | 74 +- 51 files changed, 2985 insertions(+), 3345 deletions(-) delete mode 100644 apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/copilot-message/hooks/use-message-feedback.ts delete mode 100644 apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/copilot-message/hooks/use-success-timers.ts diff --git a/apps/sim/app/chat/components/message/components/markdown-renderer.tsx b/apps/sim/app/chat/components/message/components/markdown-renderer.tsx index ba69814cfc..8aa66579d5 100644 --- a/apps/sim/app/chat/components/message/components/markdown-renderer.tsx +++ b/apps/sim/app/chat/components/message/components/markdown-renderer.tsx @@ -1,4 +1,4 @@ -import React, { type HTMLAttributes, type ReactNode } from 'react' +import React, { type HTMLAttributes, memo, type ReactNode, useMemo } from 'react' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' import { Tooltip } from '@/components/emcn' @@ -23,24 +23,16 @@ export function LinkWithPreview({ href, children }: { href: string; children: Re ) } -export default function MarkdownRenderer({ - content, - customLinkComponent, -}: { - content: string - customLinkComponent?: typeof LinkWithPreview -}) { - const LinkComponent = customLinkComponent || LinkWithPreview +const REMARK_PLUGINS = [remarkGfm] - const customComponents = { - // Paragraph +function createCustomComponents(LinkComponent: typeof LinkWithPreview) { + return { p: ({ children }: React.HTMLAttributes) => (

{children}

), - // Headings h1: ({ children }: React.HTMLAttributes) => (

{children} @@ -62,7 +54,6 @@ export default function MarkdownRenderer({

), - // Lists ul: ({ children }: React.HTMLAttributes) => (
    ), - // Code blocks pre: ({ children }: HTMLAttributes) => { let codeProps: HTMLAttributes = {} let codeContent: ReactNode = children @@ -120,7 +110,6 @@ export default function MarkdownRenderer({ ) }, - // Inline code code: ({ inline, className, @@ -144,24 +133,20 @@ export default function MarkdownRenderer({ ) }, - // Blockquotes blockquote: ({ children }: React.HTMLAttributes) => (
    {children}
    ), - // Horizontal rule hr: () =>
    , - // Links a: ({ href, children, ...props }: React.AnchorHTMLAttributes) => ( {children} ), - // Tables table: ({ children }: React.TableHTMLAttributes) => (
    @@ -193,7 +178,6 @@ export default function MarkdownRenderer({ ), - // Images img: ({ src, alt, ...props }: React.ImgHTMLAttributes) => ( ), } +} + +const DEFAULT_COMPONENTS = createCustomComponents(LinkWithPreview) + +const MarkdownRenderer = memo(function MarkdownRenderer({ + content, + customLinkComponent, +}: { + content: string + customLinkComponent?: typeof LinkWithPreview +}) { + const components = useMemo(() => { + if (!customLinkComponent) { + return DEFAULT_COMPONENTS + } + return createCustomComponents(customLinkComponent) + }, [customLinkComponent]) - // Pre-process content to fix common issues const processedContent = content.trim() return (
    - + {processedContent}
    ) -} +}) + +export default MarkdownRenderer diff --git a/apps/sim/app/layout.tsx b/apps/sim/app/layout.tsx index 166b260af8..6ab3aae353 100644 --- a/apps/sim/app/layout.tsx +++ b/apps/sim/app/layout.tsx @@ -7,7 +7,7 @@ import { generateBrandedMetadata, generateStructuredData } from '@/lib/branding/ import { PostHogProvider } from '@/app/_shell/providers/posthog-provider' import '@/app/_styles/globals.css' import { OneDollarStats } from '@/components/analytics/onedollarstats' -import { isReactGrabEnabled } from '@/lib/core/config/feature-flags' +import { isReactGrabEnabled, isReactScanEnabled } from '@/lib/core/config/feature-flags' import { HydrationErrorHandler } from '@/app/_shell/hydration-error-handler' import { QueryProvider } from '@/app/_shell/providers/query-provider' import { SessionProvider } from '@/app/_shell/providers/session-provider' @@ -35,6 +35,13 @@ export default function RootLayout({ children }: { children: React.ReactNode }) return ( + {isReactScanEnabled && ( +