From 3b9d19c57bcda83cb758f16a24a16ba9ee784a2c Mon Sep 17 00:00:00 2001 From: DSingh0304 Date: Thu, 13 Nov 2025 15:31:26 +0530 Subject: [PATCH 1/4] fix: sync profile email when user loads after mount (#6303) This fixes an issue where the email field would be empty when navigating to the profile screen immediately after app launch, before the user object has finished loading from the server. The fix adds a useEffect hook that watches user.emails and reactively updates the form field when the user object becomes available. The update only occurs if the email field is empty to avoid overwriting user edits. --- app/views/ProfileView/index.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/views/ProfileView/index.tsx b/app/views/ProfileView/index.tsx index e5206058ea5..dd631dbc590 100644 --- a/app/views/ProfileView/index.tsx +++ b/app/views/ProfileView/index.tsx @@ -1,6 +1,6 @@ import { type NativeStackNavigationOptions, type NativeStackNavigationProp } from '@react-navigation/native-stack'; import { sha256 } from 'js-sha256'; -import React, { useCallback, useLayoutEffect, useRef, useState } from 'react'; +import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'; import { Keyboard, ScrollView, View, type TextInput } from 'react-native'; import { useDispatch } from 'react-redux'; import * as yup from 'yup'; @@ -286,6 +286,17 @@ const ProfileView = ({ navigation }: IProfileViewProps): React.ReactElement => { }, []) ); + // Sync form values when user data loads (fixes race condition on app startup) + useEffect(() => { + if (user?.emails?.[0]?.address) { + const currentEmail = getValues('email'); + // Only update if email is missing/null but user has email data + if (!currentEmail && user.emails[0].address) { + setValue('email', user.emails[0].address, { shouldValidate: false, shouldDirty: false }); + } + } + }, [user?.emails, setValue, getValues]); + return ( From f9e2a7c0aaf0de5d8d07c5f3d3fa1da213bb4762 Mon Sep 17 00:00:00 2001 From: DSingh0304 Date: Thu, 13 Nov 2025 20:31:27 +0530 Subject: [PATCH 2/4] refactor: address CodeRabbit feedback on profile email sync - Remove redundant user.emails[0].address check in useEffect - Fix useFocusEffect to call reset() with current user data instead of stale defaultValues - This ensures email field is properly restored on re-navigation --- app/views/ProfileView/index.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/views/ProfileView/index.tsx b/app/views/ProfileView/index.tsx index dd631dbc590..92318299260 100644 --- a/app/views/ProfileView/index.tsx +++ b/app/views/ProfileView/index.tsx @@ -282,8 +282,15 @@ const ProfileView = ({ navigation }: IProfileViewProps): React.ReactElement => { useFocusEffect( useCallback(() => { - reset(); - }, []) + reset({ + name: user?.name as string, + username: user?.username, + email: user?.emails?.[0]?.address || null, + currentPassword: null, + newPassword: null, + avatar: null + }); + }, [user?.name, user?.username, user?.emails, reset]) ); // Sync form values when user data loads (fixes race condition on app startup) @@ -291,7 +298,7 @@ const ProfileView = ({ navigation }: IProfileViewProps): React.ReactElement => { if (user?.emails?.[0]?.address) { const currentEmail = getValues('email'); // Only update if email is missing/null but user has email data - if (!currentEmail && user.emails[0].address) { + if (!currentEmail) { setValue('email', user.emails[0].address, { shouldValidate: false, shouldDirty: false }); } } From cd1d12ad6e0f2612619f0fcd22e482a72260d932 Mon Sep 17 00:00:00 2001 From: DSingh0304 Date: Thu, 13 Nov 2025 20:45:43 +0530 Subject: [PATCH 3/4] fix: align reset() call with form schema in ProfileView - Remove non-schema fields (newPassword, avatar) from reset payload - Add missing schema fields (bio, nickname, saving) to reset - Include bio and nickname from user object - Set saving to false to properly reset form state - Update dependencies array to include bio and nickname --- app/views/ProfileView/index.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/views/ProfileView/index.tsx b/app/views/ProfileView/index.tsx index 92318299260..1069e13ab1e 100644 --- a/app/views/ProfileView/index.tsx +++ b/app/views/ProfileView/index.tsx @@ -287,10 +287,11 @@ const ProfileView = ({ navigation }: IProfileViewProps): React.ReactElement => { username: user?.username, email: user?.emails?.[0]?.address || null, currentPassword: null, - newPassword: null, - avatar: null + bio: user?.bio, + nickname: user?.nickname, + saving: false }); - }, [user?.name, user?.username, user?.emails, reset]) + }, [user?.name, user?.username, user?.emails, user?.bio, user?.nickname, reset]) ); // Sync form values when user data loads (fixes race condition on app startup) From a47c2bfbbeccab354339d9796806bb32a4d39da4 Mon Sep 17 00:00:00 2001 From: DSingh0304 Date: Sat, 29 Nov 2025 01:54:09 +0530 Subject: [PATCH 4/4] feat: Add docker-compose setup for Rocket.Chat development and remove email sync useEffect from ProfileView. --- app/views/ProfileView/index.tsx | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/app/views/ProfileView/index.tsx b/app/views/ProfileView/index.tsx index 1069e13ab1e..9156ccac268 100644 --- a/app/views/ProfileView/index.tsx +++ b/app/views/ProfileView/index.tsx @@ -1,6 +1,6 @@ import { type NativeStackNavigationOptions, type NativeStackNavigationProp } from '@react-navigation/native-stack'; import { sha256 } from 'js-sha256'; -import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'; +import React, { useCallback, useLayoutEffect, useRef, useState } from 'react'; import { Keyboard, ScrollView, View, type TextInput } from 'react-native'; import { useDispatch } from 'react-redux'; import * as yup from 'yup'; @@ -294,16 +294,7 @@ const ProfileView = ({ navigation }: IProfileViewProps): React.ReactElement => { }, [user?.name, user?.username, user?.emails, user?.bio, user?.nickname, reset]) ); - // Sync form values when user data loads (fixes race condition on app startup) - useEffect(() => { - if (user?.emails?.[0]?.address) { - const currentEmail = getValues('email'); - // Only update if email is missing/null but user has email data - if (!currentEmail) { - setValue('email', user.emails[0].address, { shouldValidate: false, shouldDirty: false }); - } - } - }, [user?.emails, setValue, getValues]); + return (