@@ -21,7 +21,6 @@ import { useAuthContext } from "@/features/auth/AuthContext";
2121import { useImagePicker } from "@/hooks/useImagePicker" ;
2222import { useWebNavigation } from "@/hooks/useWebNavigation" ;
2323import errorGraphic from "@/resources/404graphic.png" ;
24- import { lastMobileNavigationRef } from "@/state/webViewState" ;
2524import { theme } from "@/theme" ;
2625import { shouldLoadInWebView } from "@/utils/webViewUrlUtils" ;
2726
@@ -48,15 +47,14 @@ export default function WebEmbed({ path }: WebEmbedProps) {
4847
4948 // Custom hooks for image picking and navigation
5049 const { pickImage } = useImagePicker ( ) ;
51- const { handleNavigationStateChange, canGoBackRef, currentWebPathRef } =
52- useWebNavigation ( {
53- webBaseUrl : WEB_BASE_URL ,
54- currentPath : path ,
55- syncTargetPathRef,
56- onRetryCountReset : ( ) => {
57- retryCountRef . current = 0 ;
58- } ,
59- } ) ;
50+ const { handleNavigationStateChange, canGoBackRef } = useWebNavigation ( {
51+ webBaseUrl : WEB_BASE_URL ,
52+ currentPath : path ,
53+ syncTargetPathRef,
54+ onRetryCountReset : ( ) => {
55+ retryCountRef . current = 0 ;
56+ } ,
57+ } ) ;
6058
6159 // Handle Android hardware back button - go back in WebView if possible
6260 useFocusEffect (
@@ -105,26 +103,10 @@ export default function WebEmbed({ path }: WebEmbedProps) {
105103 return ;
106104 }
107105
108- // Read the current WebView path from the ref (always up-to-date)
109- const currentWebPath = currentWebPathRef . current ;
110-
111- // Strip locales from both paths for comparison
112- const currentRoute = stripLocale ( currentWebPath ) ;
106+ // Strip locale for comparison
113107 const targetRoute = stripLocale ( path ) ;
114108
115- if ( currentRoute === targetRoute ) {
116- // Same route, just different locale or already synced
117- return ;
118- }
119-
120- // Check if we just navigated here from mobile router
121- // If so, skip sync to avoid reload loop (WebView is already navigating there)
122- if ( lastMobileNavigationRef . current === targetRoute ) {
123- lastMobileNavigationRef . current = null ; // Clear so next change is synced
124- return ;
125- }
126-
127- // Routes differ - sync WebView, using mobile i18n language as source of truth
109+ // Sync WebView, using mobile i18n language as source of truth
128110 // This ensures language selection persists across tab switches
129111 const currentLocale = i18n . language !== "en" ? i18n . language : null ;
130112 const targetPath = currentLocale
@@ -138,7 +120,7 @@ export default function WebEmbed({ path }: WebEmbedProps) {
138120 window.postMessage(${ JSON . stringify ( { type : "MOBILE_NAVIGATE" , path : targetPath } ) } , "*");
139121 true;
140122 ` ) ;
141- } , [ path , WEB_BASE_URL , stripLocale , i18n . language , currentWebPathRef ] ) ;
123+ } , [ path , stripLocale , i18n . language ] ) ;
142124
143125 // Sync WebView when screen comes back into focus (tab switch)
144126 useFocusEffect (
@@ -148,19 +130,10 @@ export default function WebEmbed({ path }: WebEmbedProps) {
148130 return ;
149131 }
150132
151- // Read the current WebView path from the ref (always up-to-date)
152- const currentWebPath = currentWebPathRef . current ;
153-
154- // Strip locales from both paths for comparison
155- const currentRoute = stripLocale ( currentWebPath ) ;
133+ // Strip locale for comparison
156134 const targetRoute = stripLocale ( path ) ;
157135
158- if ( currentRoute === targetRoute ) {
159- // Same route, just different locale or already synced
160- return ;
161- }
162-
163- // Routes differ - sync WebView, using mobile i18n language as source of truth
136+ // Sync WebView, using mobile i18n language as source of truth
164137 // This ensures language selection persists across tab switches
165138 const currentLocale = i18n . language !== "en" ? i18n . language : null ;
166139 const targetPath = currentLocale
@@ -174,7 +147,7 @@ export default function WebEmbed({ path }: WebEmbedProps) {
174147 window.postMessage(${ JSON . stringify ( { type : "MOBILE_NAVIGATE" , path : targetPath } ) } , "*");
175148 true;
176149 ` ) ;
177- } , [ path , stripLocale , i18n . language , currentWebPathRef ] ) ,
150+ } , [ path , stripLocale , i18n . language ] ) ,
178151 ) ;
179152
180153 // Send result back to web app
0 commit comments