Skip to content

fix(client): render remote .md when the host ships MarkdownText as React.memo - #102

Merged
flymysql merged 1 commit into
flymysql:mainfrom
hjwsm1989:fix/md-render-memo-guard
Nov 9, 2026
Merged

flymysql merged 1 commit into
flymysql:mainfrom
hjwsm1989:fix/md-render-memo-guard

Conversation

@hjwsm1989

Copy link
Copy Markdown
Contributor

Fixes #101.

What breaks

lib/client.js decides whether to render a remote .md with the host's
MarkdownText via

typeof Primitives.MarkdownText === 'function'

The host exports MarkdownText as a React.memo wrapper
(typeof === 'object', $$typeof === Symbol.for('react.memo')), which
React.createElement accepts normally. The guard evaluates to false, the
viewer takes the raw-source branch, and every remote .md renders as a source
wall (literal #, **, backticks) — the regression #64 reported, reaching
production through a different door since the #74 change.

The fix

Treat host primitives as component types, not functions:

const isComponentType = (value) => typeof value === 'function'
  || (typeof value === 'object' && value !== null && typeof value.$$typeof === 'symbol')
const MarkdownText = (Primitives && isComponentType(Primitives.MarkdownText)) ? Primitives.MarkdownText : null

Modal, Menu and useModalLayer are still plain functions on the builds I
checked, so this is the only affected primitive; their guards are left alone.

Why the suite didn't catch it

test/harness/render.js stubbed the primitive as a plain function, i.e. a shape
the host never ships. The stub is now a React.memo wrapper like the real one,
and ui-panels.test.js additionally pins mdEls[0].type.$$typeof === Symbol.for('react.memo'), so the memo path is what gets asserted.

Verified locally that the test is a real guard: with only lib/client.js
reverted to the strict check, the #74 test fails with

expected the MarkdownText branch to render, got: 📄 README.md…只读编辑下载# Title

- one
- two

and passes with the fix.

Verification

  • node --check lib/*.js — clean
  • node check.mjs — OK: no framework-constraint violations
  • npm test — 1040 pass / 0 fail / 7 skipped
  • npm run test:coverage:gate — weighted line coverage: 81.4% >= 70%, per-file floors OK
  • End-to-end in a real DSH 0.2.2-rc.1 GUI over SSH: same file before/after the
    one-line guard change — h1/h2/h3 0 → 18, tables 0 → 4, inline code 0 → 472,
    literal backticks/asterisks gone.

…act.memo

The host exports MarkdownText as a React.memo wrapper (typeof 'object',
$$typeof Symbol.for('react.memo')), which createElement accepts. The
`typeof === 'function'` guard therefore yielded null and every remote .md
silently fell back to the raw-source wall (issue flymysql#101).

Also make the render harness stub a memo wrapper, matching the host: the
plain-function stub is why the flymysql#74 test stayed green while production was
broken.
@flymysql
flymysql merged commit 02661c3 into flymysql:main Nov 9, 2026
3 checks passed
@flymysql

flymysql commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Merged — clean fix, and making the harness stub memo-faithful plus pinning typeof === react.memo is exactly the kind of test correction that keeps this whole class of regression out. I verified the negative control locally: with the oldtypeof === 'function'` guard the #74 test fails with the raw-source wall, and it passes again with your change.

Ships in the next release. Thanks!

flymysql added a commit that referenced this pull request Nov 9, 2026
…less machines + resilient rw_sync + TUI mirror-folder key (PR #102/#100/#105/#103)
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.

[bug] remote .md shows raw source: the MarkdownText guard rejects the host's React.memo component

2 participants