From e62fad4a10803fe67a0f7a2b0f153ffd16115eb3 Mon Sep 17 00:00:00 2001 From: Daniel Samson Date: Fri, 30 Oct 2026 21:58:23 +0000 Subject: [PATCH] fix: append parsed nodes when loading initial HTML into the Lexical editor EditorShell's ingest called $generateNodesFromDOM but discarded the returned nodes, so stored content never appeared in the WYSIWYG editor in edit mode (the E2E edit test only checked title/points and missed it). The parsed nodes are now appended to the root (kept empty-paragraph default when nothing parses). Hardening tests added while auditing the M6 test checklist: - E2E: edit view asserts the stored body renders in the editor; new hostile-HTML test loads ', + '', + '', + 'click', + ].join(''); + + const dialogs: string[] = []; + const pageErrors: string[] = []; + page.on('dialog', (dialog) => { + dialogs.push(dialog.message()); + void dialog.dismiss(); + }); + page.on('pageerror', (error) => pageErrors.push(error.message)); + + await page.goto('/admin/items/1/edit'); + + const editable = page.getByLabel('Item content'); + await expect(editable).toContainText('Safe'); + + const html = await editable.evaluate((el) => el.innerHTML); + expect(html).not.toContain(' the default empty paragraph). + // $generateNodesFromDOM returns the parsed nodes without attaching them, + // so they must be appended to the root manually. Non-whitelisted markup + // (scripts, event handlers, unknown elements) is dropped by the parser, + // which also acts as the XSS boundary for stored content. useEffect(() => { if (!initialHtml) return; const doc = document.implementation.createHTMLDocument(''); doc.body.innerHTML = initialHtml; editor.update( () => { - $generateNodesFromDOM(editor, doc); + const nodes = $generateNodesFromDOM(editor, doc); + if (nodes.length === 0) return; // keep the default empty paragraph + const root = $getRoot(); + root.clear(); + root.append(...nodes); }, { discrete: true }, ); diff --git a/frontend/src/tests/admin/edit-item-page.test.tsx b/frontend/src/tests/admin/edit-item-page.test.tsx index 6cc8f45..256f898 100644 --- a/frontend/src/tests/admin/edit-item-page.test.tsx +++ b/frontend/src/tests/admin/edit-item-page.test.tsx @@ -179,6 +179,28 @@ describe('EditItemPage (create)', () => { ); }); + it('disables the create button while the request is in flight', async () => { + let resolveCreate!: (value: AdminItem) => void; + vi.mocked(adminCreateItem).mockReturnValueOnce( + new Promise((resolve) => { + resolveCreate = resolve; + }), + ); + renderAt('/admin/items/new'); + await screen.findByTestId('lexical-stub'); + + fireEvent.change(screen.getByLabelText(/^Title/), { + target: { value: 'Pending' }, + }); + screen.getByRole('button', { name: /create item/i }).click(); + + const button = screen.getByRole('button', { name: /create item/i }); + await waitFor(() => expect(button).toBeDisabled()); + + resolveCreate({ ...ITEM, id: 99, title: 'Pending' }); + expect(await screen.findByTestId('dashboard-stub')).toBeInTheDocument(); + }); + it('shows the backend error when the create request fails', async () => { vi.mocked(adminCreateItem).mockRejectedValue( new ApiError(422, 'Validation failed', 'validation_error'), diff --git a/milestones/m6-setup-admin-area-prompt.md b/milestones/m6-setup-admin-area-prompt.md index afd66c6..b03b039 100644 --- a/milestones/m6-setup-admin-area-prompt.md +++ b/milestones/m6-setup-admin-area-prompt.md @@ -302,6 +302,18 @@ Implementation notes (deviations from the prompt sketch, matching project conven - Rate limiting is implemented in-memory (1000 req/60s per admin; 429 on breach) rather than a placeholder. +QA findings from M6 (all fixed): + +- The editor's `initialHtml` ingest called `$generateNodesFromDOM` but + discarded the returned nodes, so stored content never appeared in the + WYSIWYG editor in edit mode. Fixed by appending the parsed nodes to the + root; covered by the E2E edit + hostile-HTML tests. +- XSS: the E2E hostile-HTML test loads `