Skip to content

fix(client): give the host MarkdownText the labels it dereferences - #107

Merged
flymysql merged 1 commit into
flymysql:mainfrom
hjwsm1989:fix/md-labels
Nov 10, 2026
Merged

flymysql merged 1 commit into
flymysql:mainfrom
hjwsm1989:fix/md-labels

Conversation

@hjwsm1989

Copy link
Copy Markdown
Contributor

Symptom

In a remote Session, opening a .md file that contains a fenced code block shows an empty pane: the read succeeds (SFTP returns the bytes), nothing renders, and no error is displayed. Markdown without a code fence or footnote renders normally, which makes the failure look file-specific.

Reproduced with DSH 0.2.2-rc.1 + dsh-remote 0.8.83, remote host Linux.

Root cause

The host's MarkdownText reads its chrome strings from a labels prop and dereferences them without a guard while rendering the affected nodes:

// dsh-web-frontend (MarkdownText renderer)
copyLabel:   r.labels.code.copyLabel,
copiedLabel: r.labels.code.copiedLabel,
toolbarLabels: r.labels.code.toolbarLabels,
// and, for footnotes
children: e.labels.footnotes

RemoteFileTab passes only text / variant:

React.createElement(MarkdownText, { text: originalText, variant: 'body' })

So the first fenced code block throws TypeError: Cannot read properties of undefined (reading 'code') inside the host renderer. The error boundary around the pane swallows it, and the body stays empty — the "opened a file, got a blank page" report. The same unguarded reads exist in 0.2.1-rc.5, so this is not a host regression; the viewer has never supplied labels.

Fix

  • Build the labels bundle the host expects (code.{copyLabel,copiedLabel,toolbarLabels}, footnotes), localized through the existing zh/en tables.
  • Wrap the host renderer in a small error boundary so that a future host asking for one more label degrades to source text instead of an empty body. Under partial React faces that omit Component the boundary is a pass-through, which keeps the module loadable in the existing harnesses.

Why the suite missed it

test/harness/render.js stubbed MarkdownText as (props) => <div className="md-stub">{props.text}</div>. The stub never touched labels, so the #74 test stayed green while production threw. The stub now supports strictMarkdownText, which performs the same dereferences as the real host, and the new panel test feeds a fenced code block.

Verification

  • node --check lib/client.js test/harness/render.js test/ui-panels.test.js — pass
  • npm test — 1086 pass, 0 fail, 7 skipped (1093 tests)
  • Mutation check: with only the labels change reverted, the new test fails (13 pass / 1 fail) and the old [Bug] Remote session: .md links open the local mirror instead of the remote file #74 test still passes — the new test is what pins the behaviour
  • git diff --check — clean, LF endings preserved

A remote `.md` containing a fenced code block opened to a blank pane: the
file was read (SFTP returned the bytes) but nothing rendered, and no error
was shown.

The host's MarkdownText takes its chrome strings from a `labels` prop and
dereferences them UNGUARDED while rendering those nodes —
`labels.code.copyLabel` / `.copiedLabel` / `.toolbarLabels`, and
`labels.footnotes`. The viewer passed only `text`, so the first code fence
threw inside the host renderer; the error boundary around the pane swallowed
the exception and the body stayed empty. Documents without a code fence or
footnote were unaffected, which is why the failure looked file-specific.

Pass the bundle the host expects (code-block chrome + footnote caption) and
wrap the renderer in a small boundary so that a future host asking for one
more label degrades to source instead of an empty body. The boundary is a
no-op under partial React faces that omit `Component`, which keeps the
module loadable in the existing harnesses.

Add the regression at the layer that missed it: the render harness stubbed
MarkdownText as a plain text div, so flymysql#74's test stayed green while
production threw. `strictMarkdownText` makes the stub perform the same
dereferences as the host, and the new panel test feeds a fenced code block.

Co-authored-by: huangjun <[email protected]>
@flymysql
flymysql merged commit ba35d19 into flymysql:main Nov 10, 2026
3 checks passed
@flymysql

Copy link
Copy Markdown
Owner

又一个干净的修复,已合入并随 v0.8.85 发布。特别点赞两点:①严格模式测试桩的思路——让桩做与真实宿主相同的无守卫解引用,这类契约断裂今后红灯伺候而不是悄无声息;②顺手做了 mutation 对照(拆掉 labels 修复新测试必挂、老 #74 测试不受影响),举证责任尽到了。

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.

2 participants