Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .maestro/tests/room/search.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
appId: chat.rocket.reactnative
name: Search
onFlowStart:
- runFlow: '../../helpers/setup.yaml'
tags:
- test-13
- android-only

---
- evalScript: ${output.user = output.utils.createUser()}

- runFlow:
file: '../../helpers/login-with-deeplink.yaml'
env:
USERNAME: ${output.user.username}
PASSWORD: ${output.user.password}

- extendedWaitUntil:
visible:
id: 'rooms-list-view-search'
timeout: 60000
- tapOn:
id: rooms-list-view-search
- extendedWaitUntil:
visible:
id: 'rooms-list-view'
timeout: 60000
- extendedWaitUntil:
visible:
id: 'rooms-list-view-search-input'
timeout: 60000
- pressKey: Back
- pressKey: Back
- extendedWaitUntil:
visible:
id: 'rooms-list-view'
timeout: 60000
- extendedWaitUntil:
notVisible:
id: 'rooms-list-view-search-input'
timeout: 60000
16 changes: 14 additions & 2 deletions app/views/RoomsListView/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useNavigation } from '@react-navigation/native';
import React, { memo, useContext } from 'react';
import { FlatList, RefreshControl } from 'react-native';
import React, { memo, useContext, useEffect } from 'react';
import { BackHandler, FlatList, RefreshControl } from 'react-native';
import { useSafeAreaFrame } from 'react-native-safe-area-context';
import { shallowEqual } from 'react-redux';

Expand Down Expand Up @@ -51,6 +51,18 @@ const RoomsListView = memo(function RoomsListView() {
const { refreshing, onRefresh } = useRefresh({ searching });
const supportedVersionsStatus = useAppSelector(state => state.supportedVersions.status);

useEffect(() => {
const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
if (searchEnabled) {
stopSearch();
navigation.goBack();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify navigation stack to prevent unintended app exit.

The PR aims to prevent the app from exiting, but navigation.goBack() could still exit the app if the RoomsListView is at the bottom of the navigation stack. Consider checking navigation.canGoBack() before calling goBack(), or verify that there's always a screen to navigate back to in your navigation structure.

Alternatively, consider this defensive approach:

 		const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
 			if (searchEnabled) {
 				stopSearch();
-				navigation.goBack();
+				if (navigation.canGoBack()) {
+					navigation.goBack();
+				}
 				return true;
 			}
 			return false;

🏁 Script executed:

#!/bin/bash
# Search for navigation setup and how RoomsListView is mounted in the navigation stack
rg -n -C 5 "RoomsListView" --type=typescript --type=tsx -g "!*.test.*" -g "!*.spec.*"

Length of output: 34



---

🏁 Script executed:

```shell
#!/bin/bash
# Search for RoomsListView with corrected rg syntax
rg -n -C 5 "RoomsListView" --type ts --type tsx -g "!*.test.*" -g "!*.spec.*"

Length of output: 27


🏁 Script executed:

#!/bin/bash
# Search for navigation.goBack() calls in the codebase
rg -n "navigation\.goBack" --type ts --type tsx -g "!*.test.*" -g "!*.spec.*"

Length of output: 27


🏁 Script executed:

#!/bin/bash
# Search for navigation.canGoBack usage
rg -n "canGoBack" --type ts --type tsx -g "!*.test.*" -g "!*.spec.*"

Length of output: 27


🏁 Script executed:

#!/bin/bash
# Look for the specific file to examine the current implementation
fd "RoomsListView" --type f

Length of output: 0



---

🏁 Script executed:

```shell
#!/bin/bash
# Search for RoomsListView without type restrictions
rg -n -C 5 "RoomsListView" -g "!*.test.*" -g "!*.spec.*"

Length of output: 11909


🏁 Script executed:

#!/bin/bash
# Search for navigation.goBack without type restrictions
rg -n "navigation\.goBack" -g "!*.test.*" -g "!*.spec.*"

Length of output: 912


🏁 Script executed:

#!/bin/bash
# Look for any tsx or ts files in app directory
fd -e tsx -e ts "." app/ 2>/dev/null | head -20

Length of output: 792


🏁 Script executed:

#!/bin/bash
# Search for RoomsListView with broader pattern
fd "RoomsListView" . 2>/dev/null

Length of output: 26


🏁 Script executed:

#!/bin/bash
# Check if app/views/RoomsListView/index.tsx exists
cat app/views/RoomsListView/index.tsx 2>/dev/null | head -80

Length of output: 3592


Add canGoBack() check before calling navigation.goBack() to prevent unintended app exit.

The current implementation calls navigation.goBack() without verifying the navigation stack state. Since RoomsListView is positioned as the first screen in the navigation stack, calling goBack() when the user triggers back from search mode could exit the app. Add a defensive check:

 		const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
 			if (searchEnabled) {
 				stopSearch();
-				navigation.goBack();
+				if (navigation.canGoBack()) {
+					navigation.goBack();
+				}
 				return true;
 			}
 			return false;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
navigation.goBack();
const subscription = BackHandler.addEventListener('hardwareBackPress', () => {
if (searchEnabled) {
stopSearch();
if (navigation.canGoBack()) {
navigation.goBack();
}
return true;
}
return false;
🤖 Prompt for AI Agents
In app/views/RoomsListView/index.tsx around line 58, the code calls
navigation.goBack() unguarded which can exit the app when this view is the root;
wrap the call in a defensive check by calling navigation.canGoBack() first and
only invoking navigation.goBack() when it returns true (otherwise handle the
back action differently, e.g., dismiss search mode or no-op) so the app cannot
unintentionally close.

return true;
}
return false;
});
return () => subscription.remove();
}, [searchEnabled]);
Comment thread
Rohit3523 marked this conversation as resolved.

const onPressItem = (item = {} as IRoomItem) => {
if (!navigation.isFocused()) {
return;
Expand Down