Skip to content

Commit d186f86

Browse files
MatiPl01tjzel
andauthored
chore: Enable strict mode by default, remove fatal log, add missing web check (#6477)
## Summary This PR is just a set of logger implementation improvements. - fixes crash on web caused by missing check before the `executeOnUIRuntimeSync` call (which doesn't exist on web), - enables `strict` mode by default, - removes `fatal` log level as it is not used anywhere. --------- Co-authored-by: Tomasz Żelawski <[email protected]>
1 parent 8daf8fe commit d186f86

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

apps/common-app/src/examples/InvalidValueAccessExample.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import Animated, {
99
} from 'react-native-reanimated';
1010

1111
configureReanimatedLogger({
12-
// change to `false` or remove the `configureReanimatedLogger` call to
13-
// disable the warning
12+
// change to `false` to disable the warning
1413
strict: true,
1514
});
1615

packages/react-native-reanimated/src/ConfigHelper.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { executeOnUIRuntimeSync, jsiConfigureProps } from './core';
44
import { ReanimatedError } from './errors';
55
import { updateLoggerConfig } from './logger';
66
import type { LoggerConfig } from './logger';
7+
import { shouldBeUseWeb } from './PlatformChecker';
8+
9+
const SHOULD_BE_USE_WEB = shouldBeUseWeb();
710

811
function assertNoOverlapInLists() {
912
for (const key in PropsAllowlists.NATIVE_THREAD_PROPS_WHITELIST) {
@@ -54,11 +57,22 @@ export function addWhitelistedUIProps(props: Record<string, boolean>): void {
5457
}
5558
}
5659

60+
/**
61+
* Updates Reanimated logger config with the user-provided configuration. Will
62+
* affect Reanimated code executed after call to this function so it should be
63+
* called before any Reanimated code is executed to take effect. Each call to
64+
* this function will override the previous configuration (it's recommended to
65+
* call it only once).
66+
*
67+
* @param config - The new logger configuration to apply.
68+
*/
5769
export function configureReanimatedLogger(config: LoggerConfig) {
5870
// Update the configuration object in the React runtime
5971
updateLoggerConfig(config);
6072
// Register the updated configuration in the UI runtime
61-
executeOnUIRuntimeSync(updateLoggerConfig)(config);
73+
if (!SHOULD_BE_USE_WEB) {
74+
executeOnUIRuntimeSync(updateLoggerConfig)(config);
75+
}
6276
}
6377

6478
const PROCESSED_VIEW_NAMES = new Set();

packages/react-native-reanimated/src/logger/logger.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ type LogFunction = (data: LogData) => void;
77
export enum LogLevel {
88
warn = 1,
99
error = 2,
10-
fatal = 3,
1110
}
1211

1312
export type LoggerConfig = {
@@ -36,7 +35,7 @@ function logToConsole(data: LogData) {
3635
export const DEFAULT_LOGGER_CONFIG: LoggerConfigInternal = {
3736
logFunction: logToConsole,
3837
level: LogLevel.warn,
39-
strict: false,
38+
strict: true,
4039
};
4140

4241
function formatMessage(message: string) {
@@ -117,7 +116,7 @@ type LogOptions = {
117116
};
118117

119118
function handleLog(
120-
level: Exclude<LogBoxLogLevel, 'syntax'>,
119+
level: Exclude<LogBoxLogLevel, 'syntax' | 'fatal'>,
121120
message: string,
122121
options: LogOptions
123122
) {
@@ -144,8 +143,4 @@ export const logger = {
144143
'worklet';
145144
handleLog('error', message, options);
146145
},
147-
fatal(message: string, options: LogOptions = {}) {
148-
'worklet';
149-
handleLog('fatal', message, options);
150-
},
151146
};

packages/react-native-reanimated/src/mutables.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function shouldWarnAboutAccessDuringRender() {
1818
function checkInvalidReadDuringRender() {
1919
if (shouldWarnAboutAccessDuringRender()) {
2020
logger.warn(
21-
'Reading from `value` during component render. Please ensure that you do not access the `value` property while React is rendering a component.',
21+
'Reading from `value` during component render. Please ensure that you do not access the `value` property or use `get` method of a shared value while React is rendering a component.',
2222
{ strict: true }
2323
);
2424
}
@@ -27,7 +27,7 @@ function checkInvalidReadDuringRender() {
2727
function checkInvalidWriteDuringRender() {
2828
if (shouldWarnAboutAccessDuringRender()) {
2929
logger.warn(
30-
'Writing to `value` during component render. Please ensure that you do not access the `value` property while React is rendering a component.',
30+
'Writing to `value` during component render. Please ensure that you do not access the `value` property or use `set` method of a shared value while React is rendering a component.',
3131
{ strict: true }
3232
);
3333
}

0 commit comments

Comments
 (0)