[HOTE-871] fix: prevent revisiting check-your-answers via browser back#308
[HOTE-871] fix: prevent revisiting check-your-answers via browser back#308ConnorF-NHS wants to merge 7 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the UI journey navigation to prevent users from revisiting the “Check your answers” step after submitting an order by using the browser back button.
Changes:
- Update the
/route redirect to usenavigate(..., { replace: true })so the home entry isn’t left in browser history. - Detect browser “POP” navigation back to
CheckYourAnswersPageafter submission and clear journey/order/postcode state before redirecting to the start. - Add/extend Jest + React Testing Library coverage for the new redirect/reset behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| ui/src/routes/HomePage.tsx | Uses history replace on redirect to reduce back-navigation to /. |
| ui/src/routes/get-self-test-kit-for-HIV-journey/CheckYourAnswersPage.tsx | Clears persisted journey state on browser-back revisit post-submission and redirects to restart the journey. |
| ui/src/tests/routes/HomePage.test.tsx | Adds test asserting redirect uses { replace: true }. |
| ui/src/tests/routes/get-self-test-kit-for-HIV-journey/CheckYourAnswersPage.test.tsx | Adds test asserting state is cleared and redirect occurs when revisiting via browser back after submission. |
ui/src/routes/get-self-test-kit-for-HIV-journey/CheckYourAnswersPage.tsx
Outdated
Show resolved
Hide resolved
…er-order-creation
…er-order-creation
|
|
||
| reset(); | ||
| clearAddresses(); | ||
| sessionService.clearJourneyNavigation(); |
There was a problem hiding this comment.
Calling sessionService.clearJourneyNavigation() here clears sessionStorage but does not reset the in-memory JourneyNavigationProvider state, so the next NavigationContext effect can immediately re-dehydrate the old stepHistory/returnToStep back into sessionStorage and carry stale history into the next journey run. Prefer resetting navigation via the JourneyNavigationContext API (e.g., add/use a dedicated reset method that sets stepHistory to [RoutePath.GetSelfTestKitPage] and returnToStep to null) rather than directly mutating session storage from the page.
| sessionService.clearJourneyNavigation(); |
| reset(); | ||
| clearAddresses(); | ||
| sessionService.clearJourneyNavigation(); | ||
| navigate(RoutePath.GetSelfTestKitPage, { replace: true }); | ||
| }, [clearAddresses, hasSubmittedOrder, navigate, navigationType, reset]); |
There was a problem hiding this comment.
reset() clears orderReferenceNumber, so after this redirect the browser Forward history entry to the OrderSubmitted page will no longer be able to display the reference number (it will fall back to the placeholder). Consider preserving the submitted order reference until the user explicitly starts a new journey, or add a guard on OrderSubmittedPage to redirect away when the reference is missing to avoid showing an empty confirmation.
| reset(); | |
| clearAddresses(); | |
| sessionService.clearJourneyNavigation(); | |
| navigate(RoutePath.GetSelfTestKitPage, { replace: true }); | |
| }, [clearAddresses, hasSubmittedOrder, navigate, navigationType, reset]); | |
| clearAddresses(); | |
| sessionService.clearJourneyNavigation(); | |
| navigate(RoutePath.GetSelfTestKitPage, { replace: true }); | |
| }, [clearAddresses, hasSubmittedOrder, navigate, navigationType]); |
|
| setNavigation({ | ||
| stepHistory: [step], | ||
| returnToStep: null, | ||
| }); | ||
|
|
||
| sessionService.clearJourneyNavigation(); | ||
|
|
||
| if (step !== currentStep || options?.replace === true) { | ||
| navigate(getPathForStep(step), { replace: options?.replace }); | ||
| } |
There was a problem hiding this comment.
resetNavigation sets navigation state before calling navigate; because stepHistory is derived by appending currentStep when the last history entry differs, resetting to a different step can temporarily re-add the previous currentStep (and may briefly re-persist it to sessionStorage) before the location updates.
Consider navigating first (or adding a small “pending reset” guard) so the computed stepHistory doesn’t momentarily include the old step when you’re intentionally clearing history.
| setNavigation({ | |
| stepHistory: [step], | |
| returnToStep: null, | |
| }); | |
| sessionService.clearJourneyNavigation(); | |
| if (step !== currentStep || options?.replace === true) { | |
| navigate(getPathForStep(step), { replace: options?.replace }); | |
| } | |
| if (step !== currentStep || options?.replace === true) { | |
| navigate(getPathForStep(step), { replace: options?.replace }); | |
| } | |
| setNavigation({ | |
| stepHistory: [step], | |
| returnToStep: null, | |
| }); | |
| sessionService.clearJourneyNavigation(); |



Description
When the user clicks the browser back button, they will now be taken to the GetSelfTestKitPage instead of the CheckYourAnswersPage, preventing them from submitting another order immediately. This is a temporary fix; a proper solution will be implemented in beta.
Context
https://nhsd-jira.digital.nhs.uk/browse/HOTE-871
Type of changes
Checklist
Sensitive Information Declaration
To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.