Skip to content

fix(editor): prevent empty Markdoc placeholder from breaking IME composition - #1682

Open
MilindChatrabhuji wants to merge 1 commit into
Thinkmill:mainfrom
MilindChatrabhuji:fix/markdoc-ime-first-char-1616
Open

MilindChatrabhuji wants to merge 1 commit into
Thinkmill:mainfrom
MilindChatrabhuji:fix/markdoc-ime-first-char-1616

Conversation

@MilindChatrabhuji

Copy link
Copy Markdown
Contributor

Fixes #1616

Summary

  • Switch placeholderPlugin in the Markdoc ProseMirror editor from Decoration.widget(1, <span>) to Decoration.node(0, doc.firstChild.nodeSize, { class: classes.placeholder, 'data-placeholder': text }), and render the placeholder text via CSS ::before with content: attr(data-placeholder) in utils.ts.
    • Previously, inserting the first character in an empty editor removed the <span class="ProseMirror-placeholder"> child DOM node inside the composing <p> element while IME composition was active, breaking Chrome/Firefox Japanese IME first-character composition.
  • Guard viewRef.current.updateState(state) in useEditorView (editor-view.tsx) with viewRef.current.state !== state so React's post-dispatch re-render does not redundantly re-run ProseMirror updateState for the state instance just applied in dispatchTransaction.
  • Add regression tests in packages/keystatic/src/form/fields/markdoc/editor/tests/placeholder-ime.test.tsx verifying:
    • No widget child <span> is inserted or removed during first-character composition on an empty editor, and placeholder attributes appear/disappear cleanly across empty/non-empty transitions.
    • EditorView.prototype.updateState is called once per transaction rather than twice on React re-render.
  • Add @keystatic/core patch changeset in .changeset/markdoc-placeholder-ime.md.

Verification

  • vitest run --maxWorkers=1 --testTimeout=15000 packages/keystatic/src/form/fields/markdoc/editor/tests/: 18 test files passed (316 passed, 5 skipped pre-existing skipped/todo cases).
  • tsc --noEmit: 0 errors across the workspace.
  • eslint and prettier --check on all modified/added files: passed.

This branch has not been deployed

No deployments
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.

Japanese IME composition is broken on the first character in an empty Markdoc field

1 participant