Keep rich text when a form is sent before Editor.js has loaded (#42) #45

Merged
miko merged 2 commits from feature/42-description-before-editor-ready into development 2026-11-02 19:11:08 +01:00
Owner

Closes #42.

Summary

A guide, category or step form sent before Editor.js has loaded has no description / content field. The server used to read that as empty and store SQL NULL. A missing rich text field now means "unchanged":

 saveGuide / saveCategory / saveStep
-  description = richTextFromSubmission(formText(formData, "description"))   // missing → "" → DbNull
+  description = richTextFromForm(formData, "description")                    // missing → {unchanged}
   data : {..., description : storedJson(description)}
+  // storedJson({unchanged}) → undefined, which Prisma leaves alone
  • A field that is present but empty still clears the document.
  • Creating a guide with no field stores no description.
  • A step saved with unchanged content builds its search text from the stored content.
  • Step content is included (agreed in the session); a missing lines field still fails as before.

Evidence

e2e/richText.spec.ts blocks the script chunks that contain Editor.js, then saves:

  • Before (fix stashed): both tests fail. getByText('You need a radiator key.') and getByText('Use citric acid, not vinegar.') are not found, because the description and the step content were wiped.
    After: 2 passed.
  • Unit tests in src/richText/submission.test.ts: a form without description gives {unchanged : true}; description="" gives {json : null}.
  • Typecheck, lint and 272 unit tests pass. Full e2e: 8 passed. One earlier run hit the known write conflict in access.spec.ts (#43).

Merge Danger

Door: two-way

No schema change or migration. Reverting restores the old behaviour.

Blast Radius: saving

Affects only saving guides, categories and steps. Risk: a client that leaves the field out on purpose to clear a document would now keep it. No form does that today; clearing sends an empty editor document.

🤖 Generated with Claude Code

Closes #42. ## Summary A guide, category or step form sent before Editor.js has loaded has no `description` / `content` field. The server used to read that as empty and store SQL NULL. A missing rich text field now means "unchanged": ```diff saveGuide / saveCategory / saveStep - description = richTextFromSubmission(formText(formData, "description")) // missing → "" → DbNull + description = richTextFromForm(formData, "description") // missing → {unchanged} data : {..., description : storedJson(description)} + // storedJson({unchanged}) → undefined, which Prisma leaves alone ``` - A field that is present but empty still clears the document. - Creating a guide with no field stores no description. - A step saved with unchanged content builds its search text from the stored content. - Step content is included (agreed in the session); a missing `lines` field still fails as before. ## Evidence `e2e/richText.spec.ts` blocks the script chunks that contain Editor.js, then saves: - **Before** (fix stashed): both tests fail. `getByText('You need a radiator key.')` and `getByText('Use citric acid, not vinegar.')` are not found, because the description and the step content were wiped. **After:** `2 passed`. - Unit tests in `src/richText/submission.test.ts`: a form without `description` gives `{unchanged : true}`; `description=""` gives `{json : null}`. - Typecheck, lint and 272 unit tests pass. Full e2e: 8 passed. One earlier run hit the known write conflict in `access.spec.ts` (#43). ## Merge Danger **Door:** two-way No schema change or migration. Reverting restores the old behaviour. **Blast Radius:** saving Affects only saving guides, categories and steps. Risk: a client that leaves the field out on purpose to clear a document would now keep it. No form does that today; clearing sends an empty editor document. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The guide and category forms only add their description, and the step
form its content, once the editor exists. A form sent earlier had no such
field, which the server read as empty and saved as SQL NULL, wiping the
stored document. A missing rich text field now means "unchanged":
richTextFromForm reports it, and storedJson turns it into undefined, which
Prisma leaves alone. A field that is present but empty still clears it.

e2e/richText.spec.ts saves a guide and a step with Editor.js blocked and
checks that the description and content survive.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
miko merged commit a63cb0050d into development 2026-11-02 19:11:08 +01:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MassiveDynamic/kataba!45
No description provided.