Commit 14bb968
authored
fix(shell-docs): suppress docs-render snippet warnings + fix ComponentExamples render (CopilotKit#4992)
## Summary
Three changes to `src/lib/docs-render.tsx` that together eliminate the
`[docs-render] snippet missing for component X` log noise on prod AND
fix a hard SSR error on `/quickstart` caused by a missing
`ComponentExamples` registration.
## Changes
**1. Suppress warnings for components the MDX imports** (existing scope
of this PR).
`inlineSnippets()` runs after `stripLeadingImports()` removes the MDX's
`import` lines, so the regex can't tell a `<PascalCase />` reference
apart from a real React component imported into the file. Every imported
component triggered a false-positive `snippet missing` warning. The page
still rendered correctly via `docsComponents`; only the log was wrong.
Capture imports before stripping, then short-circuit the warning when
the regex hits one of those names.
**2. Add `ComponentExamples` to `SNIPPET_MAP`** (new).
`copilot-ui.mdx` imports `ComponentExamples` from
`@/snippets/component-examples.mdx` and renders it. When
`copilot-ui.mdx` is recursively inlined into a parent MDX (e.g. via
`<CopilotUI />`), the import line is stripped and the inliner finds no
`SNIPPET_MAP` entry for `ComponentExamples`. The bare JSX survives the
inliner and `next-mdx-remote` throws `Expected component
ComponentExamples to be defined` at SSR. The error is caught in a
partial-render error boundary so the page returns 200, but a chunk of
content is missing from the rendered output.
Add `ComponentExamples: "component-examples.mdx"` to `SNIPPET_MAP` so
the recursive inliner resolves it the same way it resolves `CopilotUI`.
One line, fixes both the SSR error and the cosmetic warning.
(Note: the `gatherImportedComponentNames` shortcut from change 1 doesn't
help here because it captures imports from the OUTER MDX, not from
recursively-inlined snippet bodies. That deeper structural limitation
can be addressed later; the `SNIPPET_MAP` entry resolves the immediate
failure.)
**3. Skip icon-prefix bare references** (new).
Lucide `Square*` icons (`SquareTerminal`, `SquareChartGantt`) and
`react-icons` `Fa*` / `Si*` / `Pi*` families are bare-referenced in many
MDX files — no explicit import, resolved at render time via the
registry's emoji stubs in `docsComponents`. The existing
`endsWith("Icon")` filter doesn't catch these PascalCase +
library-prefix shapes. Add a regex check next to it:
`/^(Fa|Si|Pi|Square)[A-Z]/`.
## Components covered after changes 1-3
The import-aware filter catches every `import { X } from "..."`
reference (current set: AgentCoreCommandTabs, CodePanel, CodeShowcase,
Frame, IframeSwitcher, ImageAndCode, LinkToCopilotCloud,
NewLookAndFeelPreview, StartProviders).
The icon-prefix filter catches `FaArrowUp`, `FaWrench`,
`SquareTerminal`, `SquareChartGantt`, and future icon-library additions
matching the prefix shape.
`ComponentExamples` is registered in `SNIPPET_MAP` so the inliner
resolves it instead of warning.
Remaining bare references that don't match any of the above (e.g.
`CloudCopilotKit`) still warn — these are runtime React components
registered in `docsComponents` but not imported in the MDX. The right
cleanup for those is to add explicit `import { CloudCopilotKit } from
"..."` lines in the MDX, which the import-aware filter then catches
automatically. Out of scope for this PR.
## Adjacent observation (not fixed)
While diagnosing change 2, found that the underlying
`new-look-and-feel.tsx` component file referenced by
`troubleshooting/migrate-to-1.8.2.mdx` doesn't exist on disk. The MDX
registry stubs the name with `<div>{children}</div>`, so the preview
area in that page renders empty. This PR doesn't address the
empty-preview behavior; the snippet-missing log noise is purely
cosmetic.
## Test plan
- [x] Diff is additive only; runtime render path unchanged.
- [ ] Local: build shell-docs, hit `/built-in-agent/quickstart` +
`/crewai-crews/quickstart` + `/built-in-agent/agentic-protocols/mcp` +
`/built-in-agent/shared-state/predictive-state-updates` +
`/built-in-agent/troubleshooting/migrate-to-1.8.2`. Confirm zero
`[docs-render] snippet missing` and zero `Expected component
ComponentExamples to be defined` warnings in the dev server log.
- [ ] Local: confirm the ComponentExamples Tabs block actually renders
on `/crewai-crews/quickstart` (was silently missing pre-fix).
- [ ] Post-deploy: re-check Railway logs for the warning + error class
over a sample of page loads.1 file changed
Lines changed: 50 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
806 | 806 | | |
807 | 807 | | |
808 | 808 | | |
| 809 | + | |
809 | 810 | | |
810 | 811 | | |
811 | 812 | | |
| |||
1013 | 1014 | | |
1014 | 1015 | | |
1015 | 1016 | | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
1016 | 1045 | | |
1017 | 1046 | | |
1018 | 1047 | | |
1019 | 1048 | | |
1020 | 1049 | | |
| 1050 | + | |
1021 | 1051 | | |
1022 | 1052 | | |
1023 | 1053 | | |
| |||
1070 | 1100 | | |
1071 | 1101 | | |
1072 | 1102 | | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
1073 | 1123 | | |
1074 | 1124 | | |
1075 | 1125 | | |
| |||
0 commit comments