Skip to content

fix(text-editor): keep host blocks mounted and spaced in the renderer - #213

Merged
clbotdev merged 1 commit into
mainfrom
fix/text-editor-renderer-blocks
Nov 21, 2026
Merged

clbotdev merged 1 commit into
mainfrom
fix/text-editor-renderer-blocks

Conversation

@clbotdev

Copy link
Copy Markdown
Contributor

Found while testing block-based lessons in a CourseLit app.

What was wrong

  1. Host blocks remounted on every render. ContentRenderer passes our node mappings to Tiptap's React renderer, which mounts each mapping as a component (React.createElement(mapping)). Our mappings — and Tiptap's own doc mapping — are new functions on every render, so each time the host page re-rendered, React unmounted and remounted the whole tree. In CourseLit, a learner passed a quiz, the page re-rendered, and the quiz lost its result and answers; a playing video would reload the same way.
  2. Host blocks had no spacing. Library blocks get margin: 1rem 0 from prose.css; blocks rendered by the host (blocks prop) got none, so two in a row (callout → video → quiz) touched.
  3. Small editor buttons wrapped. The Video block's "Use" button shrank in its flex row and wrapped to "Us / e".

Fix

  • ContentRenderer now renders through renderToElement with a renderer that calls each mapping as a plain function and keys the result by position, so the element tree only holds stable types (p, figure, the host's block components). Nothing changes for server rendering: the renderer stays hook-free.
  • Host blocks render inside <div class="te-host-block" data-block="…">, spaced like library blocks (margins collapse with paragraphs).
  • smallButton is shrink-0 whitespace-nowrap.

Testing

  • New tests: two renders of the same document produce the same element types and keys at every position (fails before the fix), changed content still renders, host blocks get the wrapper. vitest: 217 passed. tsc --noEmit clean, package build OK.
  • Docs: rendered every Markdown page in five product docs folders (690 pages) with main's renderer and this branch's under the docs profile — 0 differences.
  • Browser: swapped the build into a local CourseLit stack — a passed quiz keeps "Passed" and the selected answer; image, callout, video and quiz are spaced 16px apart.

@clbotdev
clbotdev merged commit e951b54 into main Nov 21, 2026
4 checks passed
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