fix(submit): handle missing title in local drafts#1236
Conversation
Greptile SummaryThis PR fixes a
Confidence Score: 5/5Safe 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
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]
Reviews (2): Last reviewed commit: "test(submit): cover local drafts stored ..." | Re-trigger Greptile |
| const { title = '', tags = [], body = '' } = localDraft; | ||
| onDraftLoaded(title, tags, body); |
There was a problem hiding this comment.
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!
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.
This PR fixes a
TypeError: Cannot read properties of undefined (reading 'slice')that occurred inapplyTitleon the submit page.The root cause was identified as
applyTitlereceivingundefinedwhen a local draft stored inlocalStoragewas missing thetitleproperty. This happened becauselocal-draft-manager.tsdestructuredlocalDraftwithout providing default values for potentially missing fields.The fix involves adding default empty string values for
titleandbody, and an empty array fortags, during the destructuring oflocalDraftinapps/web/src/app/submit/_hooks/local-draft-manager.ts. This ensures thatapplyTitlealways receives a string, preventing theTypeError.Fixes ECENCY-NEXT-1GJC