Skip to content

LF-5219: Incorrect redirect to create farm page after changing password#4120

Merged
kathyavini merged 2 commits intointegrationfrom
LF-5219/Incorrect_redirect_to_Create_Farm_page_after_changing_password
Apr 14, 2026
Merged

LF-5219: Incorrect redirect to create farm page after changing password#4120
kathyavini merged 2 commits intointegrationfrom
LF-5219/Incorrect_redirect_to_Create_Farm_page_after_changing_password

Conversation

@SayakaOno
Copy link
Copy Markdown
Collaborator

@SayakaOno SayakaOno commented Apr 14, 2026

Description

Fix

Prevent unnecessary Route re-renders when form submissions update Redux state

Problem

When users submit the password reset form (in /password_reset), the Routes component would unexpectedly re-render and redirect them to /welcome, where they should see a modal and then be redirected to /farm_selection.

Root Cause

8bb5402 (Implementing offline navigation logging, v3.10.0 release on Feb 25, 2026)

The useOfflineActivityLogger hook was using useSelector(userFarmSelector), which subscribes to all changes in the userFarm Redux state. When the form submission updated user_id:

const onSubmit = (data) => {
const { password } = data;
dispatch(resetPassword({ reset_token, password, onPasswordResetSuccess, email }));
};

export function* resetPasswordSaga({
payload: { reset_token, password, onPasswordResetSuccess, email },
}) {
try {
const result = yield call(
axios.put,
resetPasswordUrl(),
{ password },
{
headers: {
Authorization: `Bearer ${reset_token}`,
},
},
);
const { id_token } = result.data;
localStorage.setItem('id_token', id_token);
const decoded = decodeToken(id_token);
const { user_id } = decoded;
yield put(loginSuccess({ user_id }));

loginSuccess: (state, { payload: { user_id } }) => {
state.user_id = user_id;
},

it would:

  1. Trigger <App /> to re-render (parent component)
  2. Cause <Routes /> to re-render as a child
  3. Re-evaluate routing logic unnecessarily and render <OnboardingFlow /> which doesn't have /password_reset

} else if (!hasSelectedFarm || !hasFinishedOnBoardingFlow) {
return <OnboardingFlow {...userFarm} />;

  1. Redirect the user unexpectedly

if ((!farm_id || !step_one) && !hasUserFarms) {
return <Redirect to="/welcome" />;
}

Solution

Made the offline activity logger's Redux subscription more granular by changing selector:
Use currentFarmIdSelector instead of userFarmSelector

  • Only subscribes to farm_id changes, not all userFarm state
  • Prevents re-renders from unrelated form submissions

I found this bug while testing the React Router upgrade and wanted to ship a fix as soon as possible.

Jira link: https://lite-farm.atlassian.net/browse/LF-5219

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Passes test case
  • UI components visually reviewed on desktop view
  • UI components visually reviewed on mobile view
  • Other (please explain)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • The precommit and linting ran successfully
  • I have added or updated language tags for text that's part of the UI
  • I have ordered translation keys alphabetically (optional: run pnpm i18n to help with this)
  • I have added the GNU General Public License to all new files

@SayakaOno SayakaOno self-assigned this Apr 14, 2026
@SayakaOno SayakaOno requested review from a team as code owners April 14, 2026 18:40
@SayakaOno SayakaOno added the bug Something isn't working label Apr 14, 2026
@SayakaOno SayakaOno requested review from kathyavini and removed request for a team April 14, 2026 18:40
Copy link
Copy Markdown
Collaborator

@kathyavini kathyavini left a comment

Choose a reason for hiding this comment

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

Ooooh, I would never have come across that on my own or traced the route cause...!

and render <OnboardingFlow /> which doesn't have /password_reset

I'm not great on the logic of the routes files, but you don't think this is also worth fixing on its own, separate from the re-rendering? Am I understanding correctly the re-render exposed a little bit of faulty routing logic in that branch?

And also just checking my understanding that this would be something to watch for as we keep adding custom hooks to App.jsx (as has become a small pattern since the offline release!)... I don't think I was thinking at all about <Routes /> re-rendering when writing selectors in those hooks 🫤

@kathyavini kathyavini added this pull request to the merge queue Apr 14, 2026
Merged via the queue into integration with commit 21b01ba Apr 14, 2026
4 checks passed
@SayakaOno SayakaOno deleted the LF-5219/Incorrect_redirect_to_Create_Farm_page_after_changing_password branch April 16, 2026 15:28
@SayakaOno
Copy link
Copy Markdown
Collaborator Author

SayakaOno commented Apr 16, 2026

@kathyavini You’re right, the same thing happens when you go offline while the modal is shown.
The routing conditions seem quite complex, so I’ve been hesitant to update them 😅 I’ll create a bug ticket to make them more robust!
Ticket: https://lite-farm.atlassian.net/browse/LF-5256

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants