Skip to content

fix(dashboard): mirror code fence lang detection fix from #1661#1677

Merged
esengine merged 1 commit into
mainfrom
fix/dashboard-codeblock-lang-detection
May 24, 2026
Merged

fix(dashboard): mirror code fence lang detection fix from #1661#1677
esengine merged 1 commit into
mainfrom
fix/dashboard-codeblock-lang-detection

Conversation

@esengine

Copy link
Copy Markdown
Owner

Summary

#1661 fixed the code-fence lang-detection bug for desktop only. Dashboard's pre handler had the same c.type === "code" check, which fails when react-markdown's component override replaces code — the element's type is the override function, not the string "code".

For dashboard this didn't just mislabel the language: the old fallback returned a vanilla <pre> and skipped CodeBlock entirely, so every fenced code block in the dashboard was rendered without syntax highlighting and without the copy button.

Changes

  • dashboard/src/Markdown.tsx — mirror the desktop fix: read className from the first child element instead of relying on type === "code". Also port flattenChildText so text extraction matches desktop.
  • desktop/src/Markdown.tsx — extract the lang lookup into extractFencedLang so it can be unit-tested.
  • tests/markdown-codeblock-lang.test.tsx — new regression test covering both surfaces via the extracted helper.

Why a helper instead of rendering through <Markdown>?

CodeView pulls in prism-react-renderer, which resolves React from each package's own node_modules. Under vitest that produces two React copies and breaks hooks (useCallback is null) for any full-render test of a code block. The pure helper sidesteps that and still proves both surfaces parse the same fenced lang the same way.

Verification

  • npm run verify ✅ (3603 passed / 12 skipped, +6 from this PR)

#1661 fixed the lang-detection bug for desktop only. Dashboard's pre
handler has the same `c.type === "code"` check that fails when
react-markdown's component override replaces `code` — the element's
type is the override function, not the string "code". For dashboard
this didn't just mislabel the language; the fallback returned a vanilla
`<pre>` and skipped CodeBlock entirely, so syntax highlighting and the
copy button were missing for every fenced code block.

Extracted the lang lookup into `extractFencedLang` in both files so it
can be unit-tested without rendering CodeView (prism-react-renderer
pulls in each package's own React copy under vitest, which breaks
full-render tests across desktop/dashboard).
@esengine esengine merged commit bf18fd6 into main May 24, 2026
4 checks passed
@esengine esengine deleted the fix/dashboard-codeblock-lang-detection branch May 24, 2026 12:44
esengine pushed a commit that referenced this pull request May 24, 2026
…moved, persisted usage stats, plan dispatch gate

Headline themes:
- Desktop: bundle the CLI-hosted React dashboard, retire Tauri+Preact duplicate (#1418)
- Config: drop preset abstraction; flash/pro are direct model selections (#1657, #1630)
- Stats: persist cumulative usage to session meta + auto-restore on startup (#1667, #1680, #1643, #1628)
- Plans: editMode="plan" enforced at the ToolRegistry dispatch gate (#1681); step advance fix (#1629)
- Context: fold once at turn start, drop pre-flight + byte-ceiling (#1642, #1646); collapsible compacted card (#1649)
- Subagents: per-skill flash/pro override + Settings UI (#1632)
- Desktop polish: sidebar drag-resize (#1688), responsive collapse (#1585), copy/edit overlay + msg-history nav (#1645), Esc closes modal not turn (#1685), QQ tab isolation (#1672), DiffCard for edits (#1662), theme-aware highlighting (#1655), system events toggle (#1654/#1650), macOS TCC inheritance (#1614), dashboard.enabled (#1612)
- Dashboard polish: persistent session URL (#1586, #1589, #1599), theme-aware highlighting (#1664), IME confirm-enter guard (#1689), code-fence lang fix (#1677), vendor chunk split (#1587), markdown table h-scroll (#1562)
- TUI: Alt+S input stash/recall; static history isolated from input rerenders (#1635); legacy mouse drop (#1637, #1648); multi-edit gated in review (#1647)
- Diff: SplitDiff column border holds under CJK (#1686)
- MCP: workspace roots passed to servers (#1625); codeCommand honors mcpServers (#1603)
- Config plumbing: (baseUrl, apiKey) resolved as a tuple (#1658); stale model id self-heal (#1663)

See CHANGELOG for the full list.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant