[ENG-736] Fix Diagnostic Report print in Org level - #16556
Conversation
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Greptile SummaryThis PR fixes the diagnostic report print page crashing when accessed from an organization-level route by swapping
Confidence Score: 4/5Safe to merge — the change is a targeted one-liner that unblocks printing on org-level routes with no risk to facility-level flows. The change is minimal and correct for the bug being fixed. The only concern is that the underlying useCurrentFacilitySilently utility uses a try-catch around hook calls, which is a pre-existing pattern not introduced here; the print page won't remount with a different path type, so no runtime breakage is expected. src/pages/Facility/utils/useCurrentFacility.tsx warrants a follow-up to remove the try-catch hook pattern in favour of an enabled guard. Important Files Changed
Reviews (1): Last reviewed commit: "ENG-736 Fix Diagnostic Report print in O..." | Re-trigger Greptile |
| }) { | ||
| const { t } = useTranslation(); | ||
| const { facility } = useCurrentFacility(); | ||
| const { facility } = useCurrentFacilitySilently(); |
There was a problem hiding this comment.
Hooks called inside try-catch in the underlying utility
useCurrentFacilitySilently wraps useCurrentFacility in a try-catch. Inside useCurrentFacility, useFullPath() runs first, then extractFacilityId throws synchronously before useQuery is reached. This means on a non-facility path only one hook fires, while on a facility path two fire — a conditional hook-count difference that violates React's Rules of Hooks. In practice this is stable here because a print page stays on one path type for its lifetime, but if the component were ever remounted on a different path type React would throw a "Rendered more hooks than during the previous render" error. A safer long-term fix would be to make extractFacilityId return undefined instead of throwing, then pass enabled: !!facilityId to useQuery, avoiding the try-catch entirely.
There was a problem hiding this comment.
Pull request overview
Fixes a crash when rendering/printing a Diagnostic Report from organization-level routes by avoiding the strict “must be within a facility route” constraint when reading the current facility context.
Changes:
- Switched from
useCurrentFacility()touseCurrentFacilitySilently()in the Diagnostic Report print page to prevent route-context errors at org level.
🎭 Playwright Test ResultsStatus: ✅ Passed
📊 Detailed results are available in the playwright-final-report artifact. Run: #10166 |
Proposed Changes
Fix: https://openhealthcarenetwork.atlassian.net/browse/ENG-736
Screen.Recording.2026-07-13.at.7.59.23.PM.mov
Tagging: @ohcnetwork/care-fe-code-reviewers
Merge Checklist
Summary by CodeRabbit