-
Notifications
You must be signed in to change notification settings - Fork 0
Hasan/feat/recipe frontend integration #58
Conversation
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.
This review was assisted by AI.
SHOULD FIX BEFORE MERGE
-
Every mutation blanks the page (apps/web/src/features/recipes/useRecipeQuery.ts:12)
Each save/unsave/rating bumpsrevision, which is part of the request key.loadingflips to true and the page swaps its content for a spinner.- Detail page: the content unmounts, so the success toast is lost and the servings scaling resets.
- Explore/Cookbook: one Save click replaces the whole grid with "Loading recipes…" and loses scroll position.
- If the refetch fails after a successful mutation, the user sees a full-page error.
Suggested fix: keep the previousdatawhile refetching and expose a separaterefreshingflag.
-
State updates after unmount (apps/web/src/features/recipe-detail/RecipeDetailPage.tsx:231)
performActioncallsinvalidateRecipes(), which unmounts the component. The latersetFeedbackandsetBusy(false)run on a dead instance, so the success toast never shows.openRating()doesn't clearfeedback, so reopening the rating dialog shows a stale error alert.- Errors appear twice, once in the dialog and once in the toast.
-
Double fetch on first load (useRecipeQuery.ts:13)
sessionStatusis in the request key. A hard refresh sends a request while the session is "restoring", aborts it, then sends another.- On the edit page, a late session change can remount
RecipeEditorand wipe what the user has typed.
Suggested fix: don't fetch whilesessionStatus === 'restoring', and drop it from the key.
- On the edit page, a late session change can remount
-
Edit route owner check (apps/web/src/features/recipes/RecipeCreatePage.tsx:531)
- If
query.dataloads beforecurrentUser, the user briefly sees "Recipe unavailable" for their own recipe. - A malformed
/recipes/abc/editURL gets the misleading "You can only edit your own recipes" message. - The 'new' route still subscribes to
revision, so it re-renders on every save elsewhere.
- If
IMAGE UPLOAD: SECURITY AND RESOURCES
-
Uploads are never cleaned up (apps/api/src/features/recipes/imageStorage.ts:97)
Files are written to disk but not tied to a recipe. Replacing or removing an image, cancelling the form, or deleting a recipe all leave the file behind. Registration is open and/uploadshas no per-user quota or rate limit, so a script could fill the disk or therecipe_imagesvolume. -
Uploaded images are public (imageStorage.ts:49)
GET /uploads/<uuid>has no authentication or visibility check. An image for a private recipe stays readable by anyone with the URL, including after the recipe is made private. The response has noCache-Control, even though the UUID filenames never change. -
Unguarded upload response (apps/web/src/features/recipes/recipeImages.ts:27)
response.json()on a 200 response isn't guarded. A proxy returning HTML would show the raw SyntaxError in the crop dialog. A missingimageUrlwould passundefinedtoonChange.- The 5 MB check runs on the original file, but
cropImagere-encodes at full resolution. A large crop can exceed 5 MB and only fail at upload time.
CLEANUP
-
Dead mock code (apps/web/src/features/explore/mockExploreQuery.ts, mockCookbookQuery.ts)
They are now only imported by tests, so the tests cover logic production no longer runs. The diff redeclares local ExploreSort/CookbookSort unions to keep them compiling, and these will drift from the real ones. -
Validation module has a filesystem dependency (apps/api/src/features/recipes/recipeValidation.ts:3)
The pure zod module imports imageStorage.ts (node:fs, auth, cookies) just for a regex.filePatternanduploadedImagePatternare duplicated by hand. If they diverge, a recipe could accept animageUrlthe file route always 404s, or the reverse.
MINOR
- RecipeQueryStatus.tsx:12 hardcodes "Loading recipes…" for the detail and edit pages as well. Combined with 1, screen readers re-announce it after every mutation.
Addresses the integration review feedback:
Includes a migration that imports existing recipe image references. Unreferenced images are cleaned up after 24 hours. Validation: repository checks passed with 206 tests, API/database tests and all 9 browser tests. |
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.
This review was assisted by AI.
Thanks, the previous review points are addressed (query keeps data on refresh, unmount guard and stale errors, session wait, edit route messages, image ownership/visibility, upload response validation, dead mocks removed, image path validation centralised on the API side). Requesting changes for the items below, mostly around the new image storage.
SHOULD FIX BEFORE MERGE
- New image logic is not tested in CI (.github/workflows/ci.yml)
- CI runs types:check, db:check, check and test:e2e. It does not run
npm run test:apiornpm run test:db. - Those two scripts hold all the tests for ownership, privacy, quotas, concurrency, cleanup and the legacy-image migration. imageStorage.test.ts now only tests against a mocked store.
- The browser test skips itself without DATABASE_URL, and I could not find one in ci.yml.
- As it stands, CI can pass without running any of the new image logic.
- CI runs types:check, db:check, check and test:e2e. It does not run
Suggested fix: add test:api and test:db to the workflow, or confirm the runner provides DATABASE_URL.
- One global lock serialises all recipe writes (imageRepository.ts, imageStore.ts, recipeRepository.ts)
- validateImageReference takes the exclusive advisory lock
${schema}:uploaded_imageson every recipe create/update, even without an image. delete takes it too. - upload holds the lock while it runs readdir and stat on up to 1000 files and writes the file.
- cleanup holds it while it runs one or more queries per file, plus the unlinks.
- During the hourly cleanup every recipe write in the app waits, and recipe writes also queue behind each other.
- validateImageReference takes the exclusive advisory lock
Suggested fix: use pg_advisory_xact_lock_shared for recipe writes and keep the exclusive lock for upload/cleanup only, or take the lock only when an image URL is involved.
- Upload limits do not hold against account spam (imageStore.ts DEFAULT_LIMITS)
- Registration is open, so the per-user limits (20/hour, 100 MiB) can be bypassed with new accounts.
- The global limits (1000 files, 1 GiB) then become the failure point: everyone gets 507 until cleanup frees space, which takes 24 hours.
- The global cap also counts referenced images, so the site can never hold more than 1000 recipe images.
- The limits are hard-coded defaults, not configurable.
Suggested fix: throttle registration or uploads per IP, make the limits configurable, and count only unreferenced files towards the abuse cap. If this is out of scope for now, please document the limitation.
|
In addition to the above feedback, I see that quite a few test files are failing? I don't believe those are related to these commits, they also fail on |
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.
LGTM! Throttle registration and lock serialises is something we have agreed to potentially look into at a later time, so we can focus on functionality at this stage.
Adds persistent recipe ratings and image uploads to the frontend integration.
Validation: repository checks passed with 224 tests, API/database tests and all 9 browser tests.
Notes: image URLs are publicly readable, and unreferenced files are retained. Advanced search and sorting remain planned for D3.