⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(web): guard tiptap setHardBreak against invalid-content schema error
justinbe3ffb513a21
diff --git a/apps/web/package.json b/apps/web/package.jsonindex 10106f09c..eae38cf06 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -50,6 +50,7 @@"@tanstack/router-plugin": "^1.168.26","@tiptap/core": "^3.31.3","@tiptap/extension-code-block-lowlight": "^3.31.3",+ "@tiptap/extension-hard-break": "^3.31.3","@tiptap/extension-image": "^3.31.3","@tiptap/extension-link": "^3.31.3","@tiptap/extension-list": "^3.31.3",diff --git a/apps/web/src/components/activity/comment-editor.tsx b/apps/web/src/components/activity/comment-editor.tsxindex 1e4c72b9a..06b5a4c11 100644--- a/apps/web/src/components/activity/comment-editor.tsx+++ b/apps/web/src/components/activity/comment-editor.tsx@@ -43,6 +43,7 @@ import { KaneoMention } from "@/components/task/extensions/kaneo-mention";import type { MentionMember } from "@/components/task/extensions/mention-list";import { MentionSuggestion } from "@/components/task/extensions/mention-suggestion";import { MermaidBlock } from "@/components/task/extensions/mermaid-block";+import { SafeHardBreak } from "@/components/task/extensions/safe-hard-break";import {SHIKI_CODEBLOCK_REFRESH_META,ShikiCodeBlock,@@ -609,7 +610,9 @@ export default function CommentEditor({codeBlock: {HTMLAttributes: { class: "kaneo-tiptap-codeblock" },},+ hardBreak: false,}),+ SafeHardBreak,Markdown.configure({markedOptions: {breaks: true,diff --git a/apps/web/src/components/task/extensions/safe-hard-break.test.ts b/apps/web/src/components/task/extensions/safe-hard-break.test.tsnew file mode 100644index 000000000..589326a68--- /dev/null+++ b/apps/web/src/components/task/extensions/safe-hard-break.test.ts@@ -0,0 +1,98 @@+import { Editor } from "@tiptap/core";+import StarterKit from "@tiptap/starter-kit";+import { describe, expect, it } from "vitest";+import { SafeHardBreak } from "./safe-hard-break";++function buildEditor(options: {+ editable: boolean;+ content?: object;+ useSafe?: boolean;+}) {+ const extensions = options.useSafe+ ? StarterKit.configure({ hardBreak: false })+ : StarterKit;+ return new Editor({+ extensions: options.useSafe ? [extensions, SafeHardBreak] : [extensions],+ content: options.content ?? {+ type: "doc",+ content: [{ type: "paragraph" }],+ },+ editable: options.editable,+ });+}++function fireShiftEnter(editor: Editor): boolean {+ const event = new KeyboardEvent("keydown", {+ key: "Enter",+ code: "Enter",+ shiftKey: true,+ bubbles: true,+ cancelable: true,+ });+ editor.view.dom.dispatchEvent(event);+ return event.defaultPrevented;+}++describe("SafeHardBreak (Fixes KANEO-WEB-6)", () => {+ it("treats Shift+Enter as a no-op in a readOnly editor and does not throw", () => {+ const editor = buildEditor({ editable: false, useSafe: true });+ const before = editor.getJSON();++ expect(() => {+ fireShiftEnter(editor);+ }).not.toThrow();++ // SafeHardBreak returns false from the keymap in readOnly, so no+ // transaction is built and the upstream "Invalid content for node+ // paragraph" throw cannot fire. The document is therefore unchanged.+ expect(editor.getJSON()).toEqual(before);+ expect(editor.isEditable).toBe(false);+ editor.destroy();+ });++ it("inserts a hardBreak on Shift+Enter in an editable editor", () => {+ const editor = buildEditor({+ editable: true,+ useSafe: true,+ content: {+ type: "doc",+ content: [+ {+ type: "paragraph",+ content: [{ type: "text", text: "hello" }],+ },+ ],+ },+ });++ editor.commands.focus("end");+ fireShiftEnter(editor);++ const json = editor.getJSON();+ const paragraph = json.content?.[0];+ const containsHardBreak = paragraph?.content?.some(+ (n) => n.type === "hardBreak",+ );+ const containsHello = paragraph?.content?.some(+ (n) => n.type === "text" && (n as { text?: string }).text === "hello",+ );+ expect(containsHardBreak).toBe(true);+ expect(containsHello).toBe(true);+ editor.destroy();+ });++ it("documents the upstream readOnly keymap behavior that SafeHardBreak replaces", () => {+ // Upstream HardBreak's keymap runs regardless of `editor.isEditable` and+ // builds a `tr.replaceSelectionWith` transaction. In real comment-editor+ // and task-description editors this transaction can throw+ // `TransformError: Invalid content for node paragraph`+ // (KANEO-WEB-6). SafeHardBreak replaces the keymap so the throw never+ // occurs. In this isolated schema the upstream path happens to succeed,+ // so we instead assert that the readOnly document stays unchanged.+ const editor = buildEditor({ editable: false, useSafe: false });+ const before = editor.getJSON();+ fireShiftEnter(editor);+ expect(editor.getJSON()).toEqual(before);+ editor.destroy();+ });+});diff --git a/apps/web/src/components/task/extensions/safe-hard-break.ts b/apps/web/src/components/task/extensions/safe-hard-break.tsnew file mode 100644index 000000000..85be05fbb--- /dev/null+++ b/apps/web/src/components/task/extensions/safe-hard-break.ts@@ -0,0 +1,44 @@+import HardBreak from "@tiptap/extension-hard-break";++// SafeHardBreak replaces Tiptap StarterKit's HardBreak with a version that+// does not throw `TransformError: Invalid content for node paragraph` on+// Shift+Enter (KANEO-WEB-6). The upstream command routes through+// `chain().insertContent({ type: "hardBreak" })`, which calls+// `tr.replaceWith` under the hood and can reject the replace against complex+// schemas. A direct `tr.replaceSelectionWith(this.type.create())` is the+// reliable equivalent for a leaf inline node, and we gate the keymap on+// `editor.isEditable` so readOnly viewers never build a transaction in the+// first place.+export const SafeHardBreak = HardBreak.extend<Record<string, never>>({+ addCommands() {+ return {+ setHardBreak:+ () =>+ ({ commands, state, editor }) => {+ if (!editor.isEditable) return false;+ const { selection } = state;+ if (selection.$from.parent.type.spec.isolating) return false;+ return commands.command(({ tr }) => {+ tr.replaceSelectionWith(this.type.create());+ return true;+ });+ },+ };+ },++ addKeyboardShortcuts() {+ const insert = () => {+ if (!this.editor.isEditable) return false;+ const { selection } = this.editor.state;+ if (selection.$from.parent.type.spec.isolating) return false;+ return this.editor.commands.command(({ tr }) => {+ tr.replaceSelectionWith(this.type.create());+ return true;+ });+ };+ return {+ "Mod-Enter": insert,+ "Shift-Enter": insert,+ };+ },+});diff --git a/apps/web/src/components/task/task-description.tsx b/apps/web/src/components/task/task-description.tsxindex f83c91b10..a34fb2bef 100644--- a/apps/web/src/components/task/task-description.tsx+++ b/apps/web/src/components/task/task-description.tsx@@ -78,6 +78,7 @@ import { AttachmentCard } from "./extensions/attachment-card";import { EmbedBlock } from "./extensions/embed-block";import { KaneoIssueLink } from "./extensions/kaneo-issue-link";import { MermaidBlock } from "./extensions/mermaid-block";+import { SafeHardBreak } from "./extensions/safe-hard-break";import {SHIKI_CODEBLOCK_REFRESH_META,ShikiCodeBlock,@@ -628,7 +629,9 @@ export default function TaskDescription({ taskId }: TaskDescriptionProps) {},trailingNode: false,heading: { levels: [1, 2, 3] },+ hardBreak: false,}),+ SafeHardBreak,Markdown.configure({markedOptions: {breaks: true,diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex beeb198ba..55637542d 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -150,7 +150,7 @@ importers:version: 3.0.3better-auth:specifier: 1.6.25- version: 1.6.25(cdbb2b6587814fec3716647cf5477731)+ version: 1.6.25(df449a996fc4c4a6112c372d264be731)creem:specifier: ^1.6.0version: 1.6.0@@ -393,6 +393,9 @@ importers:'@tiptap/extension-code-block-lowlight':specifier: ^3.31.3version: 3.31.3(@tiptap/[email protected](@tiptap/[email protected]))(@tiptap/[email protected](@tiptap/[email protected](@tiptap/[email protected]))(@tiptap/[email protected]))(@tiptap/[email protected])([email protected])([email protected])+ '@tiptap/extension-hard-break':+ specifier: ^3.31.3+ version: 3.31.3(@tiptap/[email protected](@tiptap/[email protected]))'@tiptap/extension-image':specifier: ^3.31.3version: 3.31.3(@tiptap/[email protected](@tiptap/[email protected]))@@ -452,7 +455,7 @@ importers:version: 1.0.0better-auth:specifier: 1.6.25- version: 1.6.25(cdbb2b6587814fec3716647cf5477731)+ version: 1.6.25(df449a996fc4c4a6112c372d264be731)class-variance-authority:specifier: ^0.7.1version: 0.7.1@@ -716,7 +719,7 @@ importers:dependencies:better-auth:specifier: 1.6.25- version: 1.6.25(cdbb2b6587814fec3716647cf5477731)+ version: 1.6.25(df449a996fc4c4a6112c372d264be731)devDependencies:'@kaneo/typescript-config':specifier: workspace:*@@ -9331,7 +9334,7 @@ snapshots:dependencies:'@better-auth/core': 1.6.25(@better-auth/[email protected])(@better-fetch/[email protected])(@opentelemetry/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])'@better-auth/utils': 0.4.2- better-auth: 1.6.25(cdbb2b6587814fec3716647cf5477731)+ better-auth: 1.6.25(df449a996fc4c4a6112c372d264be731)better-call: 1.3.7([email protected])zod: 4.4.3@@ -9339,7 +9342,7 @@ snapshots:dependencies:'@better-auth/core': 1.6.25(@better-auth/[email protected])(@better-fetch/[email protected])(@opentelemetry/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])'@better-auth/utils': 0.4.2- better-auth: 1.6.25(cdbb2b6587814fec3716647cf5477731)+ better-auth: 1.6.25(df449a996fc4c4a6112c372d264be731)better-call: 1.3.7([email protected])zod: 4.4.3@@ -12920,7 +12923,7 @@ snapshots:- [email protected](cdbb2b6587814fec3716647cf5477731):+ [email protected](df449a996fc4c4a6112c372d264be731):dependencies:'@better-auth/core': 1.6.25(@better-auth/[email protected])(@better-fetch/[email protected])(@opentelemetry/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected])'@better-auth/drizzle-adapter': 1.6.25(@better-auth/[email protected](@better-auth/[email protected])(@better-fetch/[email protected])(@opentelemetry/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected]))(@better-auth/[email protected])([email protected](@electric-sql/[email protected])(@opentelemetry/[email protected])(@prisma/[email protected]([email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])([email protected]))([email protected]))(@types/[email protected])([email protected])([email protected](@types/[email protected]))([email protected])([email protected])([email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])([email protected])))