fix: keep the editor styled when editorClassName prop changes#374
Merged
Conversation
ProseMirror puts `ProseMirror` (and `ProseMirror-focused` while focused) on the editable root itself, through `classList`, so it composes with whatever else is on the element. React's `className` prop is a whole-attribute write, so any re-render with a changed `editorClassName` dropped those tokens: every `.ProseMirror …` rule in the stylesheet stopped matching, and stayed broken until the editor remounted. The most visible symptom is a wikilink's raw `[[…]]` source appearing beside its label, since `.ProseMirror .md-atom-view-content` is the only thing hiding it. The virtual caret's `.ProseMirror-focused` styling went the same way. Apply the host's classes imperatively instead, token by token, so both writers stay additive and only classes Meowdown applied itself are ever removed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
editorClassName changes
editorClassName changeseditorClassName prop changes
Member
|
Thanks. Good catch. I've changed the implementation but kept your tests. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ProseKitEditorrenders the element ProseMirror mounts into as:ProseMirror puts
ProseMirror— andProseMirror-focusedwhile focused — on thatsame element itself, via
classList, so it composes with whatever else is there.React's
classNameprop is a whole-attribute write, so any re-render with achanged
editorClassNamewipes ProseMirror's tokens, and they are not restored:PM's own bookkeeping still believes they are applied. Every
.ProseMirror …rulein the stylesheet stops matching until the editor remounts.
The most visible symptom is a wikilink's raw source appearing next to its label —
.ProseMirror .md-atom-view-content { font-size: 0; opacity: 0 }is the only thinghiding it:
It reads like "live preview turned itself off", but the document is fine; only the
class is gone.
.ProseMirror-focusedgoes the same way, which drops the virtualcaret's focused styling.
This is easy to hit from a host that sizes the editor from state. In Reflect, each
daily-stream row passes
min-h-[60vh]for today andmin-h-[100px]for past days;when local midnight passes with the app open, yesterday's row re-renders with the
new class and loses its styling until it is scrolled out of the virtualizer and back.
Fix
Apply the host's classes imperatively, token by token, so both writers stay
additive — only classes Meowdown applied itself are ever removed. React no longer
sets
classNameon that element at all.MarkdownViewis unaffected: it renders its own static tree with no ProseMirrorview, and already includes
ProseMirrorin its class list.Testing
editor.test.tsx: the class list survives aneditorClassNamechange, and a wikilink's source stays atfont-size: 0pxacross one. Both fail on
master(they time out waiting for the class) andpass here.
pnpm typecheck,oxfmt --checkandeslintclean on the changed files.@meowdown/reactsuite: 279 passed in Chromium;editor+prosekit-editoralso run green underMEOWDOWN_TEST_BROWSER=webkit.🤖 Generated with Claude Code