⚡ 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): preserve blank paragraphs in task descriptions
Tin83b497fbc161
diff --git a/apps/web/src/components/task/task-description.test.tsx b/apps/web/src/components/task/task-description.test.tsxindex 98753e723..62a7adbac 100644--- a/apps/web/src/components/task/task-description.test.tsx+++ b/apps/web/src/components/task/task-description.test.tsx@@ -1,5 +1,5 @@import { fireEvent, render, waitFor } from "@testing-library/react";-import { Extension } from "@tiptap/core";+import { type Editor, Extension } from "@tiptap/core";import TaskItem from "@tiptap/extension-task-item";import { describe, expect, it, vi } from "vite-plus/test";import TaskDescription from "./task-description";@@ -7,6 +7,7 @@ import TaskDescription from "./task-description";const mocks = vi.hoisted(() => ({t: (key: string) => key,save: vi.fn(),+ editor: null as Editor | null,tasks: new Map<string, { id: string; description: string }>(),}));@@ -16,7 +17,12 @@ const mocks = vi.hoisted(() => ({// thing under test here; stubbing it out is what let the previous version of// this file pass while #1580 was still broken.function inert(name: string) {- return Extension.create({ name });+ return Extension.create({+ name,+ onCreate() {+ mocks.editor = this.editor;+ },+ });}vi.mock("./extensions/shiki-code-block", () => ({@@ -111,6 +117,56 @@ describe("TaskDescription", () => {reopened.unmount();});+ it("preserves blank paragraphs when editing, saving and reopening (#2017)", async () => {+ const taskId = "blank-paragraphs-task";+ let description = "First\n\n\n\nSecond\n\n\n\n\n\nThird\n\n\n\n";++ for (let cycle = 0; cycle < 4; cycle++) {+ mocks.save.mockClear();+ mocks.save.mockResolvedValue(undefined);+ mocks.tasks.set(taskId, { id: taskId, description });+ const { container, unmount } = render(+ <TaskDescription taskId={taskId} />,+ );+ await waitFor(() =>+ expect(+ container.querySelector('[contenteditable="true"]'),+ ).not.toBeNull(),+ );+ await new Promise(requestAnimationFrame);+ const editable = container.querySelector<HTMLElement>(+ '[contenteditable="true"]',+ )!;+ const paragraphs = Array.from(editable.querySelectorAll("p"));+ expect(+ paragraphs.map((paragraph) =>+ paragraph.textContent?.replace(/\u00a0/g, ""),+ ),+ ).toEqual([+ `${"!".repeat(cycle)}First`,+ "",+ "Second",+ "",+ "",+ "Third",+ "",+ "",+ ]);++ if (cycle === 3) {+ unmount();+ break;+ }++ // Make a real editor change so both hydration and saving are exercised.+ mocks.editor!.commands.insertContent("!");+ await waitFor(() => expect(mocks.save).toHaveBeenCalled());+ const saved = mocks.save.mock.calls.at(-1)![0].description as string;+ unmount();+ description = saved;+ }+ });+it("renders the parent description when navigating from a subtask (#1580)", async () => {mocks.tasks.set("child-task", {id: "child-task",diff --git a/apps/web/src/components/task/task-description.tsx b/apps/web/src/components/task/task-description.tsxindex bda0dc8d5..a76f42214 100644--- a/apps/web/src/components/task/task-description.tsx+++ b/apps/web/src/components/task/task-description.tsx@@ -98,10 +98,7 @@ type SlashMenuState = {};function formatMarkdown(markdown: string) {- return markdown- .replace(/\r\n/g, "\n")- .replace(/\n{3,}/g, "\n\n")- .replace(/\n{2,}$/g, "\n");+ return markdown.replace(/\r\n/g, "\n");}function resetUndoHistory(editor: Editor) {