Skip to content

Commit b42e3f3

Browse files
improvement(dashboards): lazy-load markdown dashboard embeds
1 parent 6d54f88 commit b42e3f3

5 files changed

Lines changed: 29 additions & 23 deletions

File tree

‎apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/code-block.tsx‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useContext, useEffect, useState } from 'react'
1+
import { lazy, Suspense, useContext, useEffect, useState } from 'react'
22
import {
33
chipVariants,
44
cn,
@@ -11,14 +11,18 @@ import {
1111
import { Check, ChevronDown, Code, Duplicate, Eye, Wrap } from '@sim/emcn/icons'
1212
import type { ReactNodeViewProps } from '@tiptap/react'
1313
import { NodeViewContent, NodeViewWrapper, ReactNodeViewRenderer } from '@tiptap/react'
14-
import { DashboardEmbed } from '@/components/dashboards/dashboard-embed'
15-
import { DASHBOARD_EMBED_LANGUAGE } from '@/lib/dashboards/spec'
14+
import { DASHBOARD_EMBED_LANGUAGE } from '@/lib/dashboards/embed-language'
1615
import { MarkdownStreamingContext } from '@/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/markdown-streaming-context'
1716
import { looksLikeMermaid, MermaidDiagram } from '../mermaid-diagram'
1817
import { MarkdownCodeBlock } from './code-block-schema'
1918
import { detectLanguage } from './detect-language'
2019
import { useEditorEditable } from './use-editor-editable'
2120

21+
/** Kept out of every rich-markdown surface's graph until a document actually holds a dashboard. */
22+
const DashboardEmbed = lazy(() =>
23+
import('@/components/dashboards/dashboard-embed').then((m) => ({ default: m.DashboardEmbed }))
24+
)
25+
2226
const PLAIN = 'plain'
2327
const MERMAID = 'mermaid'
2428

@@ -232,7 +236,9 @@ function CodeBlockView({ node, updateAttributes, editor, getPos }: ReactNodeView
232236
}}
233237
>
234238
{isDashboard ? (
235-
<DashboardEmbed source={text} isStreaming={isStreaming} />
239+
<Suspense fallback={null}>
240+
<DashboardEmbed source={text} isStreaming={isStreaming} />
241+
</Suspense>
236242
) : (
237243
<MermaidDiagram definition={text} className='mermaid-diagram-frame' />
238244
)}

‎apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/slash-command/commands.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
TextQuote,
1616
} from '@sim/emcn/icons'
1717
import type { Editor, Range } from '@tiptap/core'
18-
import { DASHBOARD_EMBED_LANGUAGE } from '@/lib/dashboards/spec'
18+
import { DASHBOARD_EMBED_LANGUAGE } from '@/lib/dashboards/embed-language'
1919

2020
/** A time-series starter; the table id is left for the author to fill in. */
2121
const DASHBOARD_EMBED_STARTER = `title: Rows over time
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/** The fence language that renders a dashboard embed in markdown; kept apart from the parser. */
2+
export const DASHBOARD_EMBED_LANGUAGE = 'dashboard'

‎apps/sim/lib/dashboards/spec.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import {
2323

2424
/** Dashboard YAML is bounded before parsing; writes report the same limit without decoding. */
2525
export const MAX_DASHBOARD_SOURCE_BYTES = 128 * 1024
26-
/** A dashboard fence embedded in a markdown document. */
27-
export const DASHBOARD_EMBED_LANGUAGE = 'dashboard'
2826
const MAX_DASHBOARD_EMBED_SOURCE_BYTES = 32 * 1024
2927
const MAX_DASHBOARD_EMBED_BLOCKS = 12
3028
export const DASHBOARD_SOURCE_TOO_LARGE = 'Dashboard source exceeds 128 KB'

‎scripts/check-tool-registry-boundary.baseline.json‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -442,33 +442,33 @@
442442
}
443443
},
444444
"app/workspace/[workspaceId]/skills/[skillId]/page.tsx": {
445-
"modules": 1421,
445+
"modules": 1457,
446446
"gateways": {
447-
"apps/sim/app/workspace/[workspaceId]/skills/[skillId]/skill-detail.tsx": 1420,
447+
"apps/sim/app/workspace/[workspaceId]/skills/[skillId]/skill-detail.tsx": 1456,
448448
"apps/sim/triggers/registry.ts": 528,
449-
"apps/sim/blocks/registry.ts": 376,
450-
"apps/sim/blocks/registry-maps.ts": 374,
451-
"apps/sim/app/workspace/[workspaceId]/skills/components/skill-fields/index.ts": 232,
452-
"apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/rich-markdown-field.tsx": 229,
453-
"apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/editor-extensions.ts": 93,
454-
"apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/mention/index.ts": 82
449+
"apps/sim/blocks/registry.ts": 374,
450+
"apps/sim/blocks/registry-maps.ts": 372,
451+
"apps/sim/app/workspace/[workspaceId]/skills/components/skill-fields/index.ts": 268,
452+
"apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/rich-markdown-field.tsx": 265,
453+
"apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/editor-extensions.ts": 117,
454+
"apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/mention/index.ts": 92
455455
}
456456
},
457457
"app/workspace/[workspaceId]/skills/error.tsx": {
458458
"modules": 3,
459459
"gateways": {}
460460
},
461461
"app/workspace/[workspaceId]/skills/new/page.tsx": {
462-
"modules": 1419,
462+
"modules": 1455,
463463
"gateways": {
464-
"apps/sim/app/workspace/[workspaceId]/skills/new/skill-create.tsx": 1418,
464+
"apps/sim/app/workspace/[workspaceId]/skills/new/skill-create.tsx": 1454,
465465
"apps/sim/triggers/registry.ts": 528,
466-
"apps/sim/blocks/registry.ts": 376,
467-
"apps/sim/blocks/registry-maps.ts": 374,
468-
"apps/sim/app/workspace/[workspaceId]/skills/components/skill-fields/index.ts": 232,
469-
"apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/rich-markdown-field.tsx": 229,
470-
"apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/editor-extensions.ts": 93,
471-
"apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/mention/index.ts": 82
466+
"apps/sim/blocks/registry.ts": 374,
467+
"apps/sim/blocks/registry-maps.ts": 372,
468+
"apps/sim/app/workspace/[workspaceId]/skills/components/skill-fields/index.ts": 268,
469+
"apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/rich-markdown-field.tsx": 265,
470+
"apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/editor-extensions.ts": 117,
471+
"apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/mention/index.ts": 92
472472
}
473473
},
474474
"app/workspace/[workspaceId]/skills/page.tsx": {

0 commit comments

Comments
 (0)