fix(web): pass full ProseMirror doc to editor, not bare array
WritingView passed chapter.doc.content (a bare ProseMirror node array)
as the editor content, which made EditorState.create build a doc node
with an undefined type, throwing 'Cannot read properties of undefined
(reading schema)' and unmounting the write view. Pass the full doc
object ({ type: 'doc', content }) on init and on setContent sync.
Add editor regression tests covering schema instantiation, node
registration, and doc-content round-trip.
This commit is contained in:
@@ -57,7 +57,10 @@ export function WritingView({ onChapterChange }: WritingViewProps) {
|
||||
const projectId = project?.id ?? null;
|
||||
|
||||
const { editor } = usePubScriptEditor({
|
||||
...(chapter ? { content: chapter.doc.content } : {}),
|
||||
// Pass the full ProseMirror doc (`{ type: "doc", content }`), not the bare
|
||||
// `content` array — TipTap/ProseMirror cannot build a doc node from a bare
|
||||
// array, which would leave `doc.type` undefined and crash `EditorState.create`.
|
||||
...(chapter ? { content: chapter.doc } : {}),
|
||||
onUpdate: (ed) => {
|
||||
if (!chapter || !projectId) return;
|
||||
const json = ed.getJSON().content;
|
||||
@@ -76,7 +79,7 @@ export function WritingView({ onChapterChange }: WritingViewProps) {
|
||||
// from re-entering onUpdate (which would otherwise re-save what we just loaded).
|
||||
useEffect(() => {
|
||||
if (!editor || !chapter) return;
|
||||
editor.commands.setContent(chapter.doc.content, { emitUpdate: false });
|
||||
editor.commands.setContent(chapter.doc, { emitUpdate: false });
|
||||
editor.commands.focus();
|
||||
}, [editor, chapter?.id]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user