Skip to content

fix(submit): handle missing title in local drafts#1236

Merged
feruzm merged 2 commits into
developfrom
seer/fix/submit-local-draft-title
Jul 24, 2026
Merged

fix(submit): handle missing title in local drafts#1236
feruzm merged 2 commits into
developfrom
seer/fix/submit-local-draft-title

Conversation

@sentry

@sentry sentry Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

This PR fixes a TypeError: Cannot read properties of undefined (reading 'slice') that occurred in applyTitle on the submit page.

The root cause was identified as applyTitle receiving undefined when a local draft stored in localStorage was missing the title property. This happened because local-draft-manager.ts destructured localDraft without providing default values for potentially missing fields.

The fix involves adding default empty string values for title and body, and an empty array for tags, during the destructuring of localDraft in apps/web/src/app/submit/_hooks/local-draft-manager.ts. This ensures that applyTitle always receives a string, preventing the TypeError.

Fixes ECENCY-NEXT-1GJC

@greptile-apps

greptile-apps Bot commented Jul 23, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes a TypeError: Cannot read properties of undefined (reading 'slice') crash that occurred when /submit was visited after another composer (waves/deck) had persisted a draft to localStorage with only a body field and no title or tags. The single-line change adds default empty values during destructuring, and a new spec file guards the regression with four focused tests.

  • Fix (local-draft-manager.ts): destructuring now uses title = "", tags = [], body = "" so onDraftLoaded always receives typed values regardless of which fields the stored draft contains.
  • Tests (local-draft-manager.spec.ts): four cases cover the regression scenario (title/tags absent), the applyTitle/applyTags consumer path that triggered the crash, a happy-path complete draft, and the no-draft/empty-draft boundary.

Confidence Score: 5/5

Safe to merge — the change is a single-line guard on a destructuring that already had correct surrounding logic.

The fix is minimal and directly targets the confirmed crash path. Default values for title, tags, and body are the correct types expected by onDraftLoaded, and the new test suite reproduces the exact consumer call (value.slice(...)) that was crashing. No other code paths are touched.

No files require special attention.

Important Files Changed

Filename Overview
apps/web/src/app/submit/_hooks/local-draft-manager.ts Minimal one-line fix: adds default empty values for title, tags, and body during localDraft destructuring to prevent TypeError when fields are absent in a stored draft.
apps/web/src/specs/app/submit/local-draft-manager.spec.ts New regression test file with four well-targeted cases: missing-fields substitution, consumer crash reproduction (mirrors applyTitle/applyTags), complete-draft passthrough, and missing/empty-draft boundary.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[useMount fires on /submit] --> B{isEntry or isDraft?}
    B -- yes --> Z[return early]
    B -- no --> C{localDraft missing\nor empty object?}
    C -- yes --> D[setIsDraftEmpty true]
    C -- no --> E["Destructure with defaults\ntitle = '' · tags = [] · body = ''"]
    E --> F[onDraftLoaded title, tags, body]
    F --> G[Loop over localDraft keys]
    G --> H{Any field has\nlength > 0?}
    H -- yes --> I[setIsDraftEmpty false]
    H -- no --> J[no-op]
Loading

Reviews (2): Last reviewed commit: "test(submit): cover local drafts stored ..." | Re-trigger Greptile

Comment on lines 29 to 30
const { title = '', tags = [], body = '' } = localDraft;
onDraftLoaded(title, tags, body);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing regression test for the fix

The CLAUDE.md guidelines state that bug fixes should include regression tests. This fix addresses a crash (TypeError in applyTitle) triggered when localStorage contains a PostBase draft object with missing fields. A Vitest unit test mocking useLocalStorage to return { description: "only this field" } (no title, body, or tags) and asserting that onDraftLoaded is called with ('', [], '') without throwing would guard this path against future regressions.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code

Reproduces ECENCY-NEXT-1GJC: the waves composer and the deck threads form
persist an overflowing post as { ...localDraft, body } into the shared
local draft key, so the stored draft carries neither title nor tags and
applyTitle crashed on undefined.slice. Reverting the defaults fails two of
these four cases with the original TypeError.

Also normalizes the new defaults to the double quotes .prettierrc sets.
@feruzm
feruzm merged commit 5ba4428 into develop Jul 24, 2026
7 checks passed
@feruzm
feruzm deleted the seer/fix/submit-local-draft-title branch July 24, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant