Skip to content

Fix/memory leak admin inventory - #932

Open
thatperplextion wants to merge 9 commits into
parthbuilds-community:mainfrom
thatperplextion:fix/memory-leak-admin-inventory
Open

Fix/memory leak admin inventory#932
thatperplextion wants to merge 9 commits into
parthbuilds-community:mainfrom
thatperplextion:fix/memory-leak-admin-inventory

Conversation

@thatperplextion

Copy link
Copy Markdown

📋 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

  • I've read the CONTRIBUTING guide
  • My code follows the project's style guidelines
  • I've tested my changes locally
  • I've linked the related issue
  • I haven't introduced any new secrets or API keys

Copilot AI lite review requested due to automatic review settings August 9, 2026 10:35
@github-actions github-actions Bot added bug Something isn't working enhancement New feature or request refactor Improve code without changing functionality UI UI-related improvements including layouts, responsiveness, styling, animations, and UX enhancements. frontend labels Aug 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 AbortController into 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request frontend refactor Improve code without changing functionality UI UI-related improvements including layouts, responsiveness, styling, animations, and UX enhancements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants