fix: resolve act warnings and prevent runtime crashes on empty data#1323
fix: resolve act warnings and prevent runtime crashes on empty data#1323MayankSharma-ops wants to merge 1 commit into
Conversation
WalkthroughThree page components ( ChangesDefensive null-safe dispatch and async test stabilization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
frontend/jest.setup.ts (1)
184-189:⚠️ Potential issue | 🟠 Major | ⚡ Quick win
/models/setupmock still bypasses the new payload shapeThe default fallback at Line 194 won’t apply to
/models/setupbecause Lines 184-189 return earlier. So/models/setupstill returns{ success: true }, not the intended{ success: true, data: [] }.Proposed fix
if (url.includes('/models/setup')) { return Promise.resolve({ ok: true, status: 200, - json: () => Promise.resolve({ success: true }), + json: () => Promise.resolve({ success: true, data: [] }), }); }Also applies to: 194-194
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@frontend/jest.setup.ts` around lines 184 - 189, The `/models/setup` endpoint mock at lines 184-189 returns early with `{ success: true }` and bypasses the default fallback at line 194 which provides the intended payload shape. Update the json response for the `/models/setup` mock to return `{ success: true, data: [] }` instead of just `{ success: true }` to match the new payload structure defined in the default fallback, ensuring consistency across all mock responses.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@frontend/jest.setup.ts`:
- Around line 184-189: The `/models/setup` endpoint mock at lines 184-189
returns early with `{ success: true }` and bypasses the default fallback at line
194 which provides the intended payload shape. Update the json response for the
`/models/setup` mock to return `{ success: true, data: [] }` instead of just `{
success: true }` to match the new payload structure defined in the default
fallback, ensuring consistency across all mock responses.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ca3cbb89-d9a9-4b18-811c-09024ae1aa2f
⛔ Files ignored due to path filters (1)
frontend/package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (7)
frontend/jest.setup.tsfrontend/src/pages/AITagging/AITagging.tsxfrontend/src/pages/Home/Home.tsxfrontend/src/pages/Home/MyFav.tsxfrontend/src/pages/__tests__/PageSanity.test.tsxfrontend/src/pages/__tests__/SettingsPage.test.tsxfrontend/src/pages/__tests__/allPages.test.tsx
Fixes #1320
This pull request resolves multiple React
act(...)console warning traces in the settings page test suite and introduces defensive fallbacks to prevent frontend runtime errors when backend fetch endpoints return empty or unmocked payloads. It includes component-level state mapping fixes, updated test mocks, and async wrapper adjustments in test suites.Defensive state checks and test robustness:
?? []) when dispatching fetched images to Redux inHome.tsx,AITagging.tsx, andMyFav.tsxto prevent components from crashing when the API returns undefined or missing lists.fetchmock injest.setup.tsto return{ success: true, data: [] }(of typeBackendRes) instead of an empty object{}.SettingsPage.test.tsx,PageSanity.test.tsx, andallPages.test.tsxto run asynchronously and wait for mount-time fetch microtasks to resolve insideact(), eliminating allact(...)warnings.Screenshots/Recordings:
N/A (This PR contains non-visual testing fixes, mock updates, and defensive state fallbacks).
Additional Notes:
AI Usage Disclosure:
I have used the following AI models and tools: Gemini (Antigravity AI coding assistant)
Checklist
Summary by CodeRabbit
Bug Fixes
Tests