Fix/memory leak admin inventory - #932
Open
thatperplextion wants to merge 9 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR primarily addresses a potential React state-update-after-unmount issue in the Admin Inventory page by aborting the in-flight product fetch on unmount, while also improving user-facing error feedback (replacing alert() with toast notifications), tightening calculator input validation/accessibility, and adding utility JSDoc documentation across the client.
Changes:
- Prevents Admin Inventory’s product fetch from updating state after unmount by wiring
AbortControllerinto the request. - Replaces
alert()error reporting with a Toast UI pattern on multiple pages. - Adds validation/error UI + ARIA attributes to BMI/Calorie calculators, removes verbose client debug logs, and adds JSDoc to several utilities.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| client/src/pages/AdminInventory.jsx | Adds AbortController/signal handling to avoid state updates after unmount during inventory fetch. |
| client/src/pages/HomePage.jsx | Replaces alert() failures with toast notifications for cart actions and renders Toast component. |
| client/src/pages/ProductPage.jsx | Replaces alert() failures with toast notifications for cart actions and renders Toast component. |
| client/src/pages/NotesPage.jsx | Replaces validation alert() with toast notification and renders Toast component. |
| client/src/components/BMICalculator.jsx | Adds input bounds validation, inline error UI, and improved ARIA attributes. |
| client/src/components/CalorieCalculator.jsx | Adds input bounds validation, inline error UI, and improved ARIA attributes. |
| client/src/pages/ExercisePage.jsx | Removes client-side debug logging to reduce console noise. |
| client/src/utils/rewardsUtils.js | Adds JSDoc comments for reward tier/progress/date/transaction helpers. |
| client/src/utils/normalizeProduct.js | Adds JSDoc for product ID normalization helper. |
| client/src/utils/getAuthHeaders.js | Replaces inline comments with a JSDoc block describing header behavior. |
| client/src/utils/formatters.js | Adds JSDoc for INR currency formatter utility. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
127
to
+133
| const headers = await getAuthHeaders(); | ||
| const res = await fetch(`${API_BASE}/products`, { headers }); | ||
| const res = await fetch(`${API_BASE}/products`, { headers, signal }); | ||
| const data = await res.json(); | ||
| setProducts(data); | ||
| setLoading(false); | ||
| if (!signal.aborted) { | ||
| setProducts(data); | ||
| setLoading(false); | ||
| } |
Comment on lines
+142
to
+146
| useEffect(() => { | ||
| const abortController = new AbortController(); | ||
| fetchProducts(abortController.signal); | ||
| return () => abortController.abort(); | ||
| }, []); |
Comment on lines
281
to
285
| } catch (err) { | ||
| console.error("Add to cart failed:", err); | ||
| alert(err.message); | ||
| setToast({ message: err.message || 'Failed to add to cart', type: 'error', visible: true }); | ||
| setTimeout(() => setToast(prev => ({ ...prev, visible: false })), 3000); | ||
| } |
Comment on lines
45
to
48
| if (!title.trim()) { | ||
| alert("Please enter a workout title."); | ||
| setToast({ message: 'Please enter a workout title.', type: 'error', visible: true }); | ||
| setTimeout(() => setToast(prev => ({ ...prev, visible: false })), 3000); | ||
| return; |
Comment on lines
145
to
+148
| } catch (err) { | ||
| console.error("Add to cart failed:", err); | ||
| alert(err.message); | ||
| setToast({ message: err.message || 'Failed to add to cart', type: 'error', visible: true }); | ||
| setTimeout(() => setToast(prev => ({ ...prev, visible: false })), 3000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📋 What does this PR do?
A clear summary of the changes made.
🔗 Related Issue
Closes #
🧪 How was this tested?
Describe how you tested your changes (manual steps, screenshots, etc.)
📸 Screenshots (if UI changes)
Before / After screenshots if you changed any UI.
✅ Checklist