Skip to content

Comments

fix: prevent state updates after unmount in chapters geoLocData fetch#3831

Closed
khushia3 wants to merge 1 commit intoOWASP:mainfrom
khushia3:fix-geoLocData-unmount-3670
Closed

fix: prevent state updates after unmount in chapters geoLocData fetch#3831
khushia3 wants to merge 1 commit intoOWASP:mainfrom
khushia3:fix-geoLocData-unmount-3670

Conversation

@khushia3
Copy link

@khushia3 khushia3 commented Feb 7, 2026

This PR prevents state updates after component unmount or effect re-run
in the chapters page by adding a safe cancellation pattern to the
geoLocData fetch.

Fixes #3670

@github-actions
Copy link

github-actions bot commented Feb 7, 2026

The linked issue must be assigned to the PR author.

@github-actions github-actions bot closed this Feb 7, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 7, 2026

Caution

Review failed

The pull request is closed.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced reliability of data loading on the chapters page, addressing state management issues that could occur during page navigation.

Walkthrough

The PR adds a mounted ref guard to the chapters page's async data fetching effect. A useRef(true) tracks component mount status, toggled in the effect cleanup. The setGeoLocData state update now executes only when the component is mounted, preventing memory leak warnings and state updates on unmounted components.

Changes

Cohort / File(s) Summary
Mounted Guard for Async Fetch
frontend/src/app/chapters/page.tsx
Added isMountedRef to guard setGeoLocData against post-unmount state updates. Imported useEffect, useRef, and useState hooks; reorganized imports to place useSearchPage after React imports. Effect cleanup flips ref to false; API response handler checks ref before updating state.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

frontend

Suggested reviewers

  • arkid15r
  • kasya
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 7, 2026

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent state updates after unmount in chapters page geoLocData fetch

1 participant