Skip to content

Commit

Permalink
Ensure ReanimatedError is added to globals before it is used
Browse files Browse the repository at this point in the history
  • Loading branch information
MatiPl01 committed Aug 19, 2024
1 parent b19a82c commit 386b83a
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 21 deletions.
2 changes: 1 addition & 1 deletion packages/react-native-reanimated/plugin/build/plugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/react-native-reanimated/plugin/src/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ function recursiveTopoSort(
stack: Set<string>
) {
if (stack.has(current.name)) {
throw new Error('[Reanimated] Cycle detected. This should never happen.');
throw new Error('Cycle detected. This should never happen.');
}
if (sorted.find((element) => element.name === current.name)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
import type { StyleLayoutAnimation } from './commonTypes';
import { withTiming } from './timing';
import { ColorProperties, processColor } from '../Colors';
import { logger } from '../logger';

// resolves path to value for nested objects
// if path cannot be resolved returns undefined
Expand Down Expand Up @@ -185,7 +186,7 @@ export function withStyleAnimation(
prevVal = (prevAnimation as any).current;
}
if (prevVal === undefined) {
console.warn(
logger.warn(
`Initial values for animation are missing for property ${currentEntry.path.join(
'.'
)}`
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native-reanimated/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export function registerReanimatedError() {
global.ReanimatedError = ReanimatedErrorFactory;
}

registerReanimatedError();

const _workletStackDetails = new Map<number, WorkletStackDetails>();

export function registerWorkletStackDetails(
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-reanimated/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

import './errors';
import './publicGlobals';
import * as Animated from './Animated';

Expand Down
4 changes: 1 addition & 3 deletions packages/react-native-reanimated/src/initializers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
import { reportFatalErrorOnJS, registerReanimatedError } from './errors';
import { reportFatalErrorOnJS } from './errors';
import { isChromeDebugger, isJest, shouldBeUseWeb } from './PlatformChecker';
import {
runOnJS,
Expand All @@ -9,8 +9,6 @@ import {
} from './threads';
import { mockedRequestAnimationFrame } from './mockedRequestAnimationFrame';

registerReanimatedError();

const IS_JEST = isJest();
const SHOULD_BE_USE_WEB = shouldBeUseWeb();
const IS_CHROME_DEBUGGER = isChromeDebugger();
Expand Down
21 changes: 10 additions & 11 deletions packages/react-native-reanimated/src/js-reanimated/JSReanimated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SensorType } from '../commonTypes';
import type { WebSensor } from './WebSensor';
import { mockedRequestAnimationFrame } from '../mockedRequestAnimationFrame';
import type { WorkletRuntime } from '../runtimes';
import { logger } from '../logger';

// In Node.js environments (like when static rendering with Expo Router)
// requestAnimationFrame is unavailable, so we use our mock.
Expand Down Expand Up @@ -68,15 +69,13 @@ export default class JSReanimated {

enableLayoutAnimations() {
if (isWeb()) {
console.warn('Layout Animations are not supported on web yet.');
logger.warn('Layout Animations are not supported on web yet.');
} else if (isJest()) {
console.warn('Layout Animations are no-ops when using Jest.');
logger.warn('Layout Animations are no-ops when using Jest.');
} else if (isChromeDebugger()) {
console.warn('Layout Animations are no-ops when using Chrome Debugger.');
logger.warn('Layout Animations are no-ops when using Chrome Debugger.');
} else {
console.warn(
'Layout Animations are not supported on this configuration.'
);
logger.warn('Layout Animations are not supported on this configuration.');
}
}

Expand Down Expand Up @@ -106,7 +105,7 @@ export default class JSReanimated {

if (!(this.getSensorName(sensorType) in window)) {
// https://w3c.github.io/sensors/#secure-context
console.warn(
logger.warn(
'Sensor is not available.' +
(isWeb() && location.protocol !== 'https:'
? ' Make sure you use secure origin with `npx expo start --web --https`.'
Expand Down Expand Up @@ -202,15 +201,15 @@ export default class JSReanimated {

subscribeForKeyboardEvents(_: ShareableRef<number>): number {
if (isWeb()) {
console.warn('useAnimatedKeyboard is not available on web yet.');
logger.warn('useAnimatedKeyboard is not available on web yet.');
} else if (isJest()) {
console.warn('useAnimatedKeyboard is not available when using Jest.');
logger.warn('useAnimatedKeyboard is not available when using Jest.');
} else if (isChromeDebugger()) {
console.warn(
logger.warn(
'useAnimatedKeyboard is not available when using Chrome Debugger.'
);
} else {
console.warn(
logger.warn(
'useAnimatedKeyboard is not available on this configuration.'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
AnimationObject,
TransformArrayItem,
} from '../../commonTypes';
import { logger } from '../../logger';

export class EntryExitTransition
extends BaseAnimationBuilder
Expand Down Expand Up @@ -187,9 +188,7 @@ export class EntryExitTransition
).map((value) => {
const objectKeys = Object.keys(value);
if (objectKeys?.length < 1) {
console.error(
`[Reanimated]: \${value} is not a valid Transform object`
);
logger.error(`\${value} is not a valid Transform object`);
return value;
}

Expand Down
3 changes: 2 additions & 1 deletion packages/react-native-reanimated/src/shareables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
shareableMappingCache,
shareableMappingFlag,
} from './shareableMappingCache';
import { logger } from './logger';

// for web/chrome debugger/jest environments this file provides a stub implementation
// where no shareable references are used. Instead, the objects themselves are used
Expand Down Expand Up @@ -340,7 +341,7 @@ function freezeObjectIfDev<T extends object>(value: T) {
return element;
},
set() {
console.warn(
logger.warn(
`Tried to modify key \`${key}\` of an object which has been already passed to a worklet. See
https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-modify-key-of-an-object-which-has-been-converted-to-a-shareable
for more details.`
Expand Down

0 comments on commit 386b83a

Please sign in to comment.