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 <script> tags, onerror/onload handlers and
  javascript: links through the real editor and asserts none survive
  into the contenteditable and nothing executes.
- E2E/unit: create button is disabled while the request is in flight.
- Backend: SQL metacharacters in the search term behave as literal
  text and leave the table intact.

Milestone doc updated: QA checklist items now cite their tests, plus a
QA-findings note for the ingest bug.
This commit is contained in:
Daniel Samson committed 2026-10-30 21:58:23 +00:00
1 parent b440809548
commit e62fad4a10
5 files changed
+104 -3

No files matched your search

+9 -1
View File
@@ -149,13 +149,21 @@ function EditorShell({ initialHtml, onChange, placeholder }: EditorShellProps) {
const [editor] = useLexicalComposerContext();
// Load the initial HTML once (empty string -> 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 },
);