Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Enable strict mode by default, remove fatal log, add missing web check #6477

Merged
merged 7 commits into from
Sep 9, 2024
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
3 changes: 1 addition & 2 deletions apps/common-app/src/examples/InvalidValueAccessExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import Animated, {
} from 'react-native-reanimated';

configureReanimatedLogger({
// change to `false` or remove the `configureReanimatedLogger` call to
// disable the warning
// change to `false` to disable the warning
strict: true,
});

Expand Down
16 changes: 15 additions & 1 deletion packages/react-native-reanimated/src/ConfigHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { executeOnUIRuntimeSync, jsiConfigureProps } from './core';
import { ReanimatedError } from './errors';
import { updateLoggerConfig } from './logger';
import type { LoggerConfig } from './logger';
import { shouldBeUseWeb } from './PlatformChecker';

const SHOULD_BE_USE_WEB = shouldBeUseWeb();

function assertNoOverlapInLists() {
for (const key in PropsAllowlists.NATIVE_THREAD_PROPS_WHITELIST) {
Expand Down Expand Up @@ -54,11 +57,22 @@ export function addWhitelistedUIProps(props: Record<string, boolean>): void {
}
}

/**
* Updates Reanimated logger config with the user-provided configuration. Will
* affect Reanimated code executed after call to this function so it should be
* called before any Reanimated code is executed to take effect. Each call to
* this function will override the previous configuration (it's recommended to
* call it only once).
*
* @param config - The new logger configuration to apply.
*/
export function configureReanimatedLogger(config: LoggerConfig) {
// Update the configuration object in the React runtime
updateLoggerConfig(config);
// Register the updated configuration in the UI runtime
executeOnUIRuntimeSync(updateLoggerConfig)(config);
if (!SHOULD_BE_USE_WEB) {
executeOnUIRuntimeSync(updateLoggerConfig)(config);
}
MatiPl01 marked this conversation as resolved.
Show resolved Hide resolved
}

const PROCESSED_VIEW_NAMES = new Set();
Expand Down
9 changes: 2 additions & 7 deletions packages/react-native-reanimated/src/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ type LogFunction = (data: LogData) => void;
export enum LogLevel {
warn = 1,
error = 2,
fatal = 3,
}

export type LoggerConfig = {
Expand Down Expand Up @@ -36,7 +35,7 @@ function logToConsole(data: LogData) {
export const DEFAULT_LOGGER_CONFIG: LoggerConfigInternal = {
logFunction: logToConsole,
level: LogLevel.warn,
strict: false,
strict: true,
MatiPl01 marked this conversation as resolved.
Show resolved Hide resolved
};

function formatMessage(message: string) {
Expand Down Expand Up @@ -117,7 +116,7 @@ type LogOptions = {
};

function handleLog(
level: Exclude<LogBoxLogLevel, 'syntax'>,
level: Exclude<LogBoxLogLevel, 'syntax' | 'fatal'>,
MatiPl01 marked this conversation as resolved.
Show resolved Hide resolved
message: string,
options: LogOptions
) {
Expand All @@ -144,8 +143,4 @@ export const logger = {
'worklet';
handleLog('error', message, options);
},
fatal(message: string, options: LogOptions = {}) {
'worklet';
handleLog('fatal', message, options);
},
};
4 changes: 2 additions & 2 deletions packages/react-native-reanimated/src/mutables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function shouldWarnAboutAccessDuringRender() {
function checkInvalidReadDuringRender() {
if (shouldWarnAboutAccessDuringRender()) {
logger.warn(
'Reading from `value` during component render. Please ensure that you do not access the `value` property while React is rendering a component.',
'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.',
{ strict: true }
);
}
Expand All @@ -27,7 +27,7 @@ function checkInvalidReadDuringRender() {
function checkInvalidWriteDuringRender() {
if (shouldWarnAboutAccessDuringRender()) {
logger.warn(
'Writing to `value` during component render. Please ensure that you do not access the `value` property while React is rendering a component.',
'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.',
{ strict: true }
);
}
Expand Down