Skip to content

Commit 316a0d1

Browse files
authored
Merge pull request #59191 from callstack-internal/feature/useOnyx-canBeMissing
2 parents 00a9547 + a6b0dfc commit 316a0d1

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

.eslintrc.changed.js

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
rules: {
88
'deprecation/deprecation': 'error',
99
'rulesdir/no-default-id-values': 'error',
10+
'rulesdir/provide-canBeMissing-in-useOnyx': 'error',
1011
'no-restricted-syntax': [
1112
'error',
1213
{

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@
304304
"electron-builder": "25.0.0",
305305
"eslint": "^8.57.0",
306306
"eslint-config-airbnb-typescript": "^18.0.0",
307-
"eslint-config-expensify": "2.0.75",
307+
"eslint-config-expensify": "2.0.78",
308308
"eslint-config-prettier": "^9.1.0",
309309
"eslint-plugin-deprecation": "^3.0.0",
310310
"eslint-plugin-jest": "^28.6.0",

src/Expensify.tsx

+24-15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {NativeEventSubscription} from 'react-native';
44
import {AppState, Linking, Platform} from 'react-native';
55
import type {OnyxEntry} from 'react-native-onyx';
66
import Onyx, {useOnyx} from 'react-native-onyx';
7+
import alert from './components/Alert';
78
import ConfirmModal from './components/ConfirmModal';
89
import DeeplinkWrapper from './components/DeeplinkWrapper';
910
import EmojiPicker from './components/EmojiPicker/EmojiPicker';
@@ -24,6 +25,7 @@ import * as EmojiPickerAction from './libs/actions/EmojiPickerAction';
2425
import * as Report from './libs/actions/Report';
2526
import * as User from './libs/actions/User';
2627
import * as ActiveClientManager from './libs/ActiveClientManager';
28+
import * as Environment from './libs/Environment/Environment';
2729
import FS from './libs/Fullstory';
2830
import * as Growl from './libs/Growl';
2931
import Log from './libs/Log';
@@ -45,14 +47,21 @@ import type {Route} from './ROUTES';
4547
import SplashScreenStateContext from './SplashScreenStateContext';
4648
import type {ScreenShareRequest} from './types/onyx';
4749

48-
Onyx.registerLogger(({level, message}) => {
50+
Onyx.registerLogger(({level, message, parameters}) => {
4951
if (level === 'alert') {
50-
Log.alert(message);
52+
Log.alert(message, parameters);
5153
console.error(message);
54+
55+
// useOnyx() calls with "canBeMissing" config set to false will display a visual alert in dev environment
56+
// when they don't return data.
57+
const shouldShowAlert = typeof parameters === 'object' && !Array.isArray(parameters) && 'showAlert' in parameters && 'key' in parameters;
58+
if (Environment.isDevelopment() && shouldShowAlert) {
59+
alert(`${message} Key: ${parameters.key as string}`);
60+
}
5261
} else if (level === 'hmmm') {
53-
Log.hmmm(message);
62+
Log.hmmm(message, parameters);
5463
} else {
55-
Log.info(message);
64+
Log.info(message, undefined, parameters);
5665
}
5766
});
5867

@@ -85,17 +94,17 @@ function Expensify() {
8594
const {splashScreenState, setSplashScreenState} = useContext(SplashScreenStateContext);
8695
const [hasAttemptedToOpenPublicRoom, setAttemptedToOpenPublicRoom] = useState(false);
8796
const {translate} = useLocalize();
88-
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
89-
const [session] = useOnyx(ONYXKEYS.SESSION);
90-
const [lastRoute] = useOnyx(ONYXKEYS.LAST_ROUTE);
91-
const [userMetadata] = useOnyx(ONYXKEYS.USER_METADATA);
92-
const [isCheckingPublicRoom] = useOnyx(ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, {initWithStoredValues: false});
93-
const [updateAvailable] = useOnyx(ONYXKEYS.UPDATE_AVAILABLE, {initWithStoredValues: false});
94-
const [updateRequired] = useOnyx(ONYXKEYS.UPDATE_REQUIRED, {initWithStoredValues: false});
95-
const [isSidebarLoaded] = useOnyx(ONYXKEYS.IS_SIDEBAR_LOADED);
96-
const [screenShareRequest] = useOnyx(ONYXKEYS.SCREEN_SHARE_REQUEST);
97-
const [focusModeNotification] = useOnyx(ONYXKEYS.FOCUS_MODE_NOTIFICATION, {initWithStoredValues: false});
98-
const [lastVisitedPath] = useOnyx(ONYXKEYS.LAST_VISITED_PATH);
97+
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});
98+
const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false});
99+
const [lastRoute] = useOnyx(ONYXKEYS.LAST_ROUTE, {canBeMissing: true});
100+
const [userMetadata] = useOnyx(ONYXKEYS.USER_METADATA, {canBeMissing: true});
101+
const [isCheckingPublicRoom] = useOnyx(ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, {initWithStoredValues: false, canBeMissing: false});
102+
const [updateAvailable] = useOnyx(ONYXKEYS.UPDATE_AVAILABLE, {initWithStoredValues: false, canBeMissing: false});
103+
const [updateRequired] = useOnyx(ONYXKEYS.UPDATE_REQUIRED, {initWithStoredValues: false, canBeMissing: false});
104+
const [isSidebarLoaded] = useOnyx(ONYXKEYS.IS_SIDEBAR_LOADED, {canBeMissing: false});
105+
const [screenShareRequest] = useOnyx(ONYXKEYS.SCREEN_SHARE_REQUEST, {canBeMissing: true});
106+
const [focusModeNotification] = useOnyx(ONYXKEYS.FOCUS_MODE_NOTIFICATION, {initWithStoredValues: false, canBeMissing: false});
107+
const [lastVisitedPath] = useOnyx(ONYXKEYS.LAST_VISITED_PATH, {canBeMissing: false});
99108

100109
useDebugShortcut();
101110

0 commit comments

Comments
 (0)