-
Notifications
You must be signed in to change notification settings - Fork 553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix page crash due to patient user context #9836
Conversation
WalkthroughThis pull request introduces a new Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for care-ohc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Deploying care-fe with
|
Latest commit: |
bbb8b02
|
Status: | ✅ Deploy successful! |
Preview URL: | https://47dbd077.care-fe.pages.dev |
Branch Preview URL: | https://fix-patient-context-error.care-fe.pages.dev |
CARE
|
Project |
CARE
|
Branch Review |
fix-patient-context-error
|
Run status |
|
Run duration | 01m 15s |
Commit |
|
Committer | Shivank Kacker |
View all properties for this run ↗︎ |
Test results | |
---|---|
|
0
|
|
0
|
|
0
|
|
0
|
|
4
|
View all changes introduced in this branch ↗︎ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/hooks/usePatientUser.ts (1)
15-21
: LGTM! Consider adding JSDoc comments.The implementation correctly addresses the page crash by providing a nullable alternative to
usePatientContext
. This is a good pattern for handling optional contexts.Consider adding JSDoc comments to document the behavior:
+/** + * Hook to access the PatientUserContext without throwing when context is missing. + * @returns The patient user context if available, null otherwise + */ export function useNullablePatientContext() { const ctx = useContext(PatientUserContext); if (!ctx) { return null; } return ctx; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/components/ui/sidebar/app-sidebar.tsx
(2 hunks)src/hooks/usePatientUser.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: OSSAR-Scan
🔇 Additional comments (1)
src/components/ui/sidebar/app-sidebar.tsx (1)
27-27
: LGTM! Verify crash resolution.The switch to
useNullablePatientContext
and the safe handling of null values should effectively prevent the page crash.Let's verify this fixes all potential crash scenarios by checking for any unguarded context usage:
Also applies to: 146-146
✅ Verification successful
✅ Crash prevention verified
All uses of
patientUserContext
are properly guarded with null checks, preventing any potential crashes from accessing properties on undefined/null values.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for direct property access on patientUserContext that might crash rg "patientUserContext\." src/components/ui/sidebar/app-sidebar.tsx # Search for potential usage of context without null checks ast-grep --pattern 'patientUserContext && $_' src/components/ui/sidebar/app-sidebar.tsxLength of output: 1594
@shivankacker Can't we return null in usePatientContext itself instead of creating a new one, also is it only erroring out here? |
Solved with b7d8b6b |
Screen.Recording.2025-01-08.at.4.33.18.AM.mov
Possible fix
@ohcnetwork/care-fe-code-reviewers
Merge Checklist
Summary by CodeRabbit
New Features
Refactor