Skip to content

fix: add defensive optional chaining to CommentScreen to prevent crashes on missing params (Issue #2063)#2089

Open
Gurkaran18 wants to merge 1 commit into
SB2318:mainfrom
Gurkaran18:fix-article-comment-like-crash
Open

fix: add defensive optional chaining to CommentScreen to prevent crashes on missing params (Issue #2063)#2089
Gurkaran18 wants to merge 1 commit into
SB2318:mainfrom
Gurkaran18:fix-article-comment-like-crash

Conversation

@Gurkaran18

Copy link
Copy Markdown
Contributor

PR Description

This PR adds defensive optional chaining to CommentScreen.tsx to prevent the application from experiencing a hard-crash when route parameters (like article) are malformed or undefined. This resolves the underlying fatal error reported in Issue #2063 when navigating from ArticleCommentLike notifications. While the routing omission in NotificationScreen was recently patched upstream, these UI safeguards ensure the screen is permanently bulletproof against any future routing parameter anomalies.

Type of Change

  • Bug fix (change which fixes an issue)
  • New feature (change which adds functionality)
  • Documentation update

Select your work-area

  • Frontend
  • Backend
  • Documentation
  • Others

Related Issue

#2063

Add your Work Example

📷 Add a Snapshot
N/A - This is a programmatic safeguard fix, no visual UI changes were made.

Fixes (mention the issue number which this fixes)

Closes #2063

Checklist

  • I have updated my branch and synced it with the project's 'develop' branch before making this PR.
  • I have optimized the file changes.
  • I have added a snapshot of my work example.
  • I have made a PR to the project's develop branch.

Undertaking

  • My code follows the style guidelines of this project.

  • I have performed a self-review of my code.

  • I have commented my code, particularly in hard-to-understand areas.

  • I have made corresponding changes to the documentation.

  • I have checked for plagiarism and assure its authenticity.

  • I have read and followed the code of conduct for this repository. I understand that violation of this undertaking may have legal consequences.

  • I Agree

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Thank you @, for creating the PR and contributing to our UltimateHealth project 💗.
Our team will review the PR and will reach out to you soon! 😇
Make sure that you have marked all the tasks that you are done with ✅.
Thank you for your patience! 😀

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Automated Review Feedback

Provide actionable comments grouped by severity:

Important

The change Number(article?._id) introduces optional chaining, which prevents a crash in CommentScreen if article or _id is undefined. However, if article?._id evaluates to undefined or null, Number() will convert it to NaN or 0 respectively. Passing NaN or 0 as articleId to ArticleScreen is likely to result in an invalid article ID, potentially causing ArticleScreen to crash, display an error, or fetch incorrect data, thus breaking the navigation flow.

Consider adding a more robust check to ensure a valid articleId is passed, or conditionally navigate only when all required parameters are present and valid. For example:

if (article?._id && article?.authorId && article?.pb_recordId) {
  navigation.navigate('ArticleScreen', {
    articleId: Number(article._id),
    authorId: article.authorId.toString(),
    recordId: article.pb_recordId,
  });
} else {
  // Handle the case where article details are missing, e.g., show a toast or log an error.
  console.warn('Cannot navigate to ArticleScreen: Missing article details.');
}

Maintainer Note:

Once the initial automated feedback has been addressed, maintainer @SB2318 will review the pull request for final evaluation.

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.

🐞[Bug]: App Crashes When Tapping "Article Comment Like" Notification Due to Missing Route Parameter

1 participant