Skip to content

fix: resolve act warnings and prevent runtime crashes on empty data#1323

Open
MayankSharma-ops wants to merge 1 commit into
AOSSIE-Org:mainfrom
MayankSharma-ops:fix/act-warnings-and-empty-data
Open

fix: resolve act warnings and prevent runtime crashes on empty data#1323
MayankSharma-ops wants to merge 1 commit into
AOSSIE-Org:mainfrom
MayankSharma-ops:fix/act-warnings-and-empty-data

Conversation

@MayankSharma-ops

@MayankSharma-ops MayankSharma-ops commented Jun 16, 2026

Copy link
Copy Markdown

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:

  • Added safety fallbacks (?? []) when dispatching fetched images to Redux in Home.tsx, AITagging.tsx, and MyFav.tsx to prevent components from crashing when the API returns undefined or missing lists.
  • Standardized the default global fetch mock in jest.setup.ts to return { success: true, data: [] } (of type BackendRes) instead of an empty object {}.
  • Updated test blocks in SettingsPage.test.tsx, PageSanity.test.tsx, and allPages.test.tsx to run asynchronously and wait for mount-time fetch microtasks to resolve inside act(), eliminating all act(...) warnings.

Screenshots/Recordings:
N/A (This PR contains non-visual testing fixes, mock updates, and defensive state fallbacks).

Additional Notes:

AI Usage Disclosure:

  • This PR does not contain AI-generated code at all.
  • This PR contains AI-generated code. I have read the AI Usage Policy and this PR complies with this policy. I have tested the code locally and I am responsible for it.
    I have used the following AI models and tools: Gemini (Antigravity AI coding assistant)

Checklist

  • My PR addresses a single issue, fixes a single bug or makes a single improvement.
  • My code follows the project's code style and conventions
  • If applicable, I have made corresponding changes or additions to the documentation
  • If applicable, I have made corresponding changes or additions to tests
  • My changes generate no new warnings or errors
  • I have joined the Discord server and I will share a link to this PR with the project maintainers there
  • My read the Contribution Guidelines
  • Once I submit my PR, CodeRabbit AI will automatically review it and I will address CodeRabbit's comments.
  • I have filled this PR template completely and carefully, and I understand that my PR may be closed without review otherwise.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of missing or null data in image gallery pages to prevent errors and ensure stable behavior when loading gallery images.
  • Tests

    • Updated test suite to properly support asynchronous React component rendering checks.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Three page components (AITagging, Home, MyFav) now use ?? [] fallbacks before dispatching setImages, preventing undefined propagation. The /models/setup fetch mock is updated to return a valid payload. Three test files (PageSanity, SettingsPage, allPages) are converted to async tests using act-wrapped zero-delay timers to suppress React act() warnings.

Changes

Defensive null-safe dispatch and async test stabilization

Layer / File(s) Summary
Null-safe image dispatch and fetch mock
frontend/jest.setup.ts, frontend/src/pages/AITagging/AITagging.tsx, frontend/src/pages/Home/Home.tsx, frontend/src/pages/Home/MyFav.tsx
AITagging, Home, and MyFav replace data?.data as Image[] with (data?.data ?? []) as Image[] in their useEffect dispatch calls. The /models/setup fetch mock is updated from {} to { success: true, data: [] }.
Async act() stabilization in tests
frontend/src/pages/__tests__/PageSanity.test.tsx, frontend/src/pages/__tests__/SettingsPage.test.tsx, frontend/src/pages/__tests__/allPages.test.tsx
All three test files add act to imports. setupTest in SettingsPage.test.tsx is converted to an async helper with an act-wrapped zero-timeout flush; all six call sites are updated to await setupTest(). PageSanity and allPages tests similarly become async and insert await act(async () => ...) deferred waits before assertions.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

TypeScript/JavaScript, Linter

Poem

🐇 A rabbit checks the data flow,
No undefined shall slip below!
?? [] keeps the list in shape,
While act() seals each async escape.
The tests all pass, the warnings gone —
Hop hop hooray, the code hops on! 🌟

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: fixing act warnings and preventing runtime crashes on empty data, which directly aligns with the primary objectives.
Linked Issues check ✅ Passed All objectives from issue #1320 are met: act warnings resolved through async test modifications, defensive fallbacks added via ?? [] nullish coalescing, and standardized mock responses updated.
Out of Scope Changes check ✅ Passed All changes directly address the two stated objectives from issue #1320 with no extraneous modifications outside the scope of fixing act warnings and adding defensive data checks.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

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/setup mock still bypasses the new payload shape

The default fallback at Line 194 won’t apply to /models/setup because Lines 184-189 return earlier. So /models/setup still 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0d0cbec and 3c1a34f.

⛔ Files ignored due to path filters (1)
  • frontend/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • frontend/jest.setup.ts
  • frontend/src/pages/AITagging/AITagging.tsx
  • frontend/src/pages/Home/Home.tsx
  • frontend/src/pages/Home/MyFav.tsx
  • frontend/src/pages/__tests__/PageSanity.test.tsx
  • frontend/src/pages/__tests__/SettingsPage.test.tsx
  • frontend/src/pages/__tests__/allPages.test.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve React act(...) warnings in settings page tests and add defensive API checks

1 participant