⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
fix(web): stop a description saving itself when nobody edited it (#295)
Ahmad Othman Ammar Adi52c16e59c348
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.mdindex ee3c1ce5..247cf983 100644--- a/apps/web/AGENTS.md+++ b/apps/web/AGENTS.md@@ -112,3 +112,13 @@ next-intl, language from the `NEXT_LOCALE` cookie — no `[locale]` route segmenimage depends on them.- When touching `localStorage`/`window` in a render path (e.g. a `useState` initializer), guardwith `typeof window === 'undefined'` — client components still server-render.++<!-- BEGIN:nextjs-agent-rules -->++# This is NOT the Next.js you know++This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` (resolved from this file's directory; in monorepos the `next` package may not be visible from the repo root) before writing any code. Heed deprecation notices.++This block is written and re-added by `next dev` — verify at `node_modules/next/dist/server/lib/generate-agent-files.js`. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean.++<!-- END:nextjs-agent-rules -->diff --git a/apps/web/src/features/issue/components/editor/IssueMarkdownEditor.test.ts b/apps/web/src/features/issue/components/editor/IssueMarkdownEditor.test.tsindex 92b88ba8..1b2cda90 100644--- a/apps/web/src/features/issue/components/editor/IssueMarkdownEditor.test.ts+++ b/apps/web/src/features/issue/components/editor/IssueMarkdownEditor.test.ts@@ -3,6 +3,7 @@ import { afterEach, beforeEach, describe, it } from 'node:test';import { Editor } from '@tiptap/core';import Link from '@tiptap/extension-link';import StarterKit from '@tiptap/starter-kit';+import { Markdown } from 'tiptap-markdown';import { JSDOM } from 'jsdom';import { issueEditorStarterKitOptions } from './IssueMarkdownEditor';import { openLinkOnModifierClick } from '../../utils/modifierClickLink';@@ -12,16 +13,19 @@ let originalGlobalDescriptors: Map<string, PropertyDescriptor | undefined>;beforeEach(() => {originalGlobalDescriptors = new Map(- ['window', 'document', 'navigator'].map((name) => [- name,- Object.getOwnPropertyDescriptor(globalThis, name),- ]),+ ['window', 'document', 'navigator', 'DOMParser', 'Node', 'Element', 'HTMLElement'].map(+ (name) => [name, Object.getOwnPropertyDescriptor(globalThis, name)],+ ),);dom = new JSDOM('<!doctype html><div></div>');Object.defineProperties(globalThis, {window: { configurable: true, value: dom.window },document: { configurable: true, value: dom.window.document },navigator: { configurable: true, value: dom.window.navigator },+ DOMParser: { configurable: true, value: dom.window.DOMParser },+ Node: { configurable: true, value: dom.window.Node },+ Element: { configurable: true, value: dom.window.Element },+ HTMLElement: { configurable: true, value: dom.window.HTMLElement },});});@@ -101,3 +105,25 @@ describe('IssueMarkdownEditor extensions', () => {assert.equal(event.defaultPrevented, false);});});++describe('IssueMarkdownEditor markdown round trip', () => {+ // The editor reports a blur only when the document changed, because reading the+ // markdown back does not return the stored text. This pins the reason: drop it and+ // the guard becomes dead weight, keep it and removing the guard saves on every+ // focus.+ it('serialises a bare url back as an autolink', () => {+ const editor = new Editor({+ extensions: [+ StarterKit.configure(issueEditorStarterKitOptions),+ Link.configure({ openOnClick: false, autolink: true }),+ Markdown.configure({ html: true, linkify: true, breaks: true }),+ ],+ content: 'See https://example.com/spec for details.',+ });++ const roundTripped = editor.storage.markdown.getMarkdown();+ assert.equal(roundTripped, 'See <https://example.com/spec> for details.');+ assert.notEqual(roundTripped, 'See https://example.com/spec for details.');+ editor.destroy();+ });+});diff --git a/apps/web/src/features/issue/components/editor/IssueMarkdownEditor.tsx b/apps/web/src/features/issue/components/editor/IssueMarkdownEditor.tsxindex 9a77ec4e..e3724656 100644--- a/apps/web/src/features/issue/components/editor/IssueMarkdownEditor.tsx+++ b/apps/web/src/features/issue/components/editor/IssueMarkdownEditor.tsx@@ -70,6 +70,14 @@ export default function IssueMarkdownEditor({const mentionCandidates = useMentionCandidates();const mentionCandidatesRef = useRef(mentionCandidates);mentionCandidatesRef.current = mentionCandidates;+ // Whether the document has changed since this editor was mounted. The markdown+ // round trip is not an identity: the link extension's autolink parses a bare URL+ // into a link node, which serialises back in angle brackets. A blur reporting every+ // time would hand its caller markdown that differs from the stored text after a+ // focus that changed nothing. Set by onUpdate; a caller keyed on the value it stores+ // (IssueDetailContent, IssueCustomFieldBody) remounts on a save and starts a fresh+ // one, so a save that fails still reports on the next blur.+ const changedRef = useRef(false);const [imagePickerOpen, setImagePickerOpen] = useState(false);// Upload each file and insert it (image/video inline, other files as a link)@@ -154,8 +162,13 @@ export default function IssueMarkdownEditor({return true;},},- onUpdate: ({ editor }) => onChange?.(editor.storage.markdown.getMarkdown()),- onBlur: ({ editor }) => onBlur?.(editor.storage.markdown.getMarkdown()),+ onUpdate: ({ editor }) => {+ changedRef.current = true;+ onChange?.(editor.storage.markdown.getMarkdown());+ },+ onBlur: ({ editor }) => {+ if (changedRef.current) onBlur?.(editor.storage.markdown.getMarkdown());+ },});useEffect(() => {