-
Notifications
You must be signed in to change notification settings - Fork 0
feat(recipe): persist recipe drafts across navigation and reload #115
Conversation
Rows could only be reordered by dragging (fails WCAG 2.2 SC 2.5.7) and used array indexes as React keys, so DOM state could stay behind when rows moved. Each row now has a stable key, and Move up / Move down buttons that keep focus on the moved row (or its other button at the first/last place) and announce the new position in a live region. Drag-and-drop still works. On phones the row buttons move to their own line under the fields. The test named 'button-based reordering' (which actually dragged) is renamed and a keyboard test is added. Closes #104
"Save draft" only showed a message; the draft was lost on navigation or reload. Drafts are now stored in localStorage per user and recipe (lib/recipeDrafts.ts). Opening the form offers to restore or discard a saved draft, warns when the recipe changed after the draft was saved, leaves out an uploaded image that no longer loads, and clears the draft after a successful save. Signing out removes the user's drafts. Closes #105
The test timed out on the CI runner (5056 ms of 5000 ms) because it typed every field character by character. It now fills fields with fireEvent.change and keeps real keyboard interaction for the moves it tests; it runs in about 0.4 s locally. Refs #104
Keeps the draft tests well under the CI runner's 5 s test limit, like the reordering test. Refs #105
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The draft persistence implementation introduces a few issues that should be addressed before merging:
- Image restoration race condition (
RecipeCreatePage.tsx:215–221): Users can save before the image finishes loading, potentially losing the draft image. A late callback can also overwrite a newly selected image. - Incomplete draft validation (
recipeDrafts.ts:65–80): Malformed stored fields can pass validation and cause runtime errors when restoring or saving a recipe. - Misleading save confirmation (
RecipeCreatePage.tsx): Changing tags, images, or adding/removing steps doesn't reset the "Draft saved" status, potentially misleading users into thinking their latest changes are stored. - Sign-out cleanup race condition (
store.ts:89–97): The user ID is retrieved after the async sign-out request, risking incorrect draft cleanup if authentication state changes. - Multi-tab draft loss (
RecipeCreatePage.tsx:224–227): Discarding an older draft in one tab can silently delete a newer draft saved in another tab.
I'd recommend fixing the image restoration and validation issues before merging, and addressing the remaining cases to avoid unexpected data loss and misleading feedback.
- Restoring a draft image blocks Save draft and submit until the image check finishes; choosing or removing an image cancels the check, so a late answer can no longer replace the user's newer choice. - Drafts are validated field by field when loaded; malformed ones are dropped instead of breaking restore or save. - "Draft saved" is only shown while the form still matches what was saved, so changing tags, the image, or adding/removing/moving rows hides it. - Sign-out reads the user id before awaiting the request. - Discard and successful save only remove a draft version this tab offered or saved; a newer draft from another tab is kept (and the user is told).
|
Thanks, all five were real. Fixed in the latest commit:
Tests: 16 new ones (page,
|
…ent-drafts # Conflicts: # apps/web/src/features/recipes/RecipeCreatePage.css # apps/web/src/features/recipes/RecipeCreatePage.test.tsx # apps/web/src/features/recipes/RecipeCreatePage.tsx # apps/web/src/store.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the previous review findings. The original issues appear resolved.
Two minor follow-ups worth considering:
- Image restoration: If the image check never completes, Save draft and Publish/Save changes can remain disabled. A timeout or skip option would improve resilience.
- Cross-tab sign-out: Another open tab can retain stale authentication state and recreate drafts after sign-out. Consider synchronizing logout across tabs to strengthen the shared-computer privacy behavior.
Neither needs to block this PR.
…ent-drafts # Conflicts: # apps/web/src/features/recipes/RecipeCreatePage.test.tsx
|
Merged after updating from The two non-blocking follow-ups from the last review are not in this PR and are still open:
|
Changes
localStorage(apps/web/src/lib/recipeDrafts.ts), scoped by user and recipe id (newfor a new recipe).updatedAt), the message becomes a warning ("Outdated draft found") explaining that restoring replaces the form with the older draft.Validation
npm run checkpasses (219 unit tests), incl. new tests: save → remount (reload) → restore restores title and steps; discard removes it; outdated draft warning; draft cleared after "Save changes"; per-user/per-recipe storage; damaged drafts; sign-out clears only that user's drafts.AI usage
Written with Claude Code (Anthropic) to address a teammate's review of the final-delivery findings. Please review the diff as you would any other contribution.
Closes #105