Skip to content

Commit

Permalink
Fix ReanimatedError issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MatiPl01 committed Aug 12, 2024
1 parent f0783ba commit f7ab541
Show file tree
Hide file tree
Showing 40 changed files with 44 additions and 81 deletions.
2 changes: 1 addition & 1 deletion apps/common-app/src/examples/EmptyExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Animated, {
withTiming,
} from 'react-native-reanimated';

const SHOW_EXAMPLE: number = 14;
const SHOW_EXAMPLE: number = -2;

/** [-1]
* Error: [Reanimated] Property `text` was whitelisted both as UI and native prop. Please remove it from
Expand Down
2 changes: 1 addition & 1 deletion apps/fabric-example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2195,7 +2195,7 @@ SPEC CHECKSUMS:
RNScreens: de6e57426ba0e6cbc3fb5b4f496e7f08cb2773c2
RNSVG: 6b65086b51556fd9723d5570a3455e865e1304a3
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
Yoga: 132f64c229103548a5c95fe12e2ab492fbd5c793
Yoga: 1e170d028257c3ceb6e652dd62b2698dbc108a4b

PODFILE CHECKSUM: baaf1c2684753f6bff7da2866e138e1af1fe3499

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/uimanager/UIManager.h>

#include <type_traits>
#include <memory>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>
Expand All @@ -15,8 +15,10 @@ using namespace react;

namespace reanimated {

using PropsMap = std::unordered_map<const ShadowNodeFamily *, std::vector<RawProps>>;
using ChildrenMap = std::unordered_map<const ShadowNodeFamily *, std::unordered_set<int>>;
using PropsMap =
std::unordered_map<const ShadowNodeFamily *, std::vector<RawProps>>;
using ChildrenMap =
std::unordered_map<const ShadowNodeFamily *, std::unordered_set<int>>;

RootShadowNode::Unshared cloneShadowTreeWithNewProps(
const RootShadowNode &oldRootNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ void WorkletRuntimeDecorator::decorate(
for (size_t i = 0; i < argsSize; i++) {
args[i] = argsArray.getValueAtIndex(rt, i);
}
remoteFun.asObject(rt).asFunction(rt).call(rt, const_cast<const jsi::Value *>(args.data()), args.size());
remoteFun.asObject(rt).asFunction(rt).call(
rt, const_cast<const jsi::Value *>(args.data()), args.size());
}
});
});
Expand Down
19 changes: 0 additions & 19 deletions packages/react-native-reanimated/jest-setup.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,2 @@
delete global.MessageChannel;
require('./src/jestUtils').setUpTests();

function formatMessage(msg) {
return `[Reanimated] ${msg}`;
}

global.__reanimatedLogger = {
warn(msg) {
console.warn(formatMessage(msg));
},
error(msg) {
console.log(formatMessage(msg));
},
fatal(msg) {
console.log(formatMessage(msg));
},
newError(msg) {
return new Error(formatMessage(msg));
}
}
3 changes: 3 additions & 0 deletions packages/react-native-reanimated/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ module.exports = {
setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'],
testEnvironment: 'node',
transformIgnorePatterns: [],
globals: {
ReanimatedError: true
}
};
5 changes: 3 additions & 2 deletions 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('Cycle detected. This should never happen.');
throw new Error('[Reanimated] Cycle detected. This should never happen.');
}
if (sorted.find((element) => element.name === current.name)) {
return;
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-reanimated/plugin/src/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const notCapturedIdentifiers = [

// Reanimated
'_WORKLET',
'ReanimatedError',
];

/**
Expand Down
2 changes: 0 additions & 2 deletions packages/react-native-reanimated/src/Bezier.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

import { logger } from './logger';

/**
* https://github.com/gre/bezier-easing
* BezierEasing - use bezier curve for transition easing function
Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/ConfigHelper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
import { PropsAllowlists } from './propsAllowlists';
import { jsiConfigureProps } from './core';
import { logger } from './logger';

function assertNoOverlapInLists() {
for (const key in PropsAllowlists.NATIVE_THREAD_PROPS_WHITELIST) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type React from 'react';
import { getShadowNodeWrapperFromRef } from '../fabricUtils';
import type { LayoutAnimationBatchItem } from '../layoutReanimation/animationBuilder/commonTypes';
import ReanimatedModule from '../specs/NativeReanimatedModule';
import { logger } from '../logger';

// this is the type of `__reanimatedModuleProxy` which is injected using JSI
export interface NativeReanimatedModule {
Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/PropsRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

import { logger } from './logger';
import { isFabric } from './PlatformChecker';
import { runOnUI } from './threads';

Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/UpdateProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type { ReanimatedHTMLElement } from './js-reanimated';
import { _updatePropsJS } from './js-reanimated';
import { isFabric, isJest, shouldBeUseWeb } from './PlatformChecker';
import { runOnUIImmediately } from './threads';
import { logger } from './logger';

let updateProps: (
viewDescriptor: SharedValue<Descriptor[]>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type {
InnerDecayAnimation,
} from './utils';
import { rigidDecay } from './rigidDecay';
import { logger } from '../../logger';

export type WithDecayConfig = DecayConfig;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

import { logger } from '../../logger';

type FixedLengthArray<
T,
L extends number,
Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/animation/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export function recognizePrefixSuffix(
value: string | number
): RecognizedPrefixSuffix {
'worklet';
console.log('recognizePrefixSuffix');
if (typeof value === 'string') {
const match = value.match(
/([A-Za-z]*)(-?\d*\.?\d*)([eE][-+]?[0-9]+)?([A-Za-z%]*)/
Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { makeShareableCloneRecursive } from './shareables';
import { initializeUIRuntime } from './initializers';
import type { LayoutAnimationBatchItem } from './layoutReanimation/animationBuilder/commonTypes';
import { SensorContainer } from './SensorContainer';
import { logger } from './logger';

export { startMapper, stopMapper } from './mappers';
export { runOnJS, runOnUI, executeOnUIRuntimeSync } from './threads';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import { addHTMLMutationObserver } from '../layoutReanimation/web/domUtils';
import { getViewInfo } from './getViewInfo';
import { NativeEventsManager } from './NativeEventsManager';
import type { ReanimatedHTMLElement } from '../js-reanimated';
import { logger } from '../logger';

const IS_WEB = isWeb();

Expand Down
19 changes: 7 additions & 12 deletions packages/react-native-reanimated/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,18 @@ export interface ReanimatedError extends Error {
new (message: string): ReanimatedError;
}

export function ReanimatedError(message: string): ReanimatedError {
const ReanimatedErrorFactory: ReanimatedError = ((message: string) => {
'worklet';
const errorInstance = new Error(`[Reanimated] ${message}`);
Object.setPrototypeOf(errorInstance, ReanimatedError.prototype);
errorInstance.name = 'ReanimatedError';
return errorInstance;
}) as unknown as ReanimatedError;

// Exclude constructor from stack trace if captureStackTrace is available
if (Error.captureStackTrace) {
Error.captureStackTrace(errorInstance, ReanimatedError);
}

return errorInstance as ReanimatedError;
export function registerReanimatedError() {
'worklet';
global.ReanimatedError = ReanimatedErrorFactory;
}

// Ensure the prototype chain is correct
ReanimatedError.prototype = Object.create(Error.prototype);
ReanimatedError.prototype.constructor = ReanimatedError;

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

export function registerWorkletStackDetails(
Expand Down
2 changes: 0 additions & 2 deletions packages/react-native-reanimated/src/fabricUtils.web.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

import { logger } from './logger';

export function getShadowNodeWrapperFromRef() {
throw new ReanimatedError(
'Trying to call `getShadowNodeWrapperFromRef` on web.'
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native-reanimated/src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type { UpdatePropsManager } from './UpdateProps';
import type { callGuardDEV } from './initializers';
import type { WorkletRuntime } from './runtimes';
import type { RNScreensTurboModuleType } from './screenTransition/commonTypes';
import type { ReanimatedError as ReanimatedErrorFactory } from './errors';
import type { ReanimatedError } from './errors';

declare global {
var _REANIMATED_IS_REDUCED_MOTION: boolean | undefined;
Expand Down Expand Up @@ -113,5 +113,5 @@ declare global {
shadowNodeWrapper: ShadowNodeWrapper,
propName: string
) => string;
var ReanimatedError: typeof ReanimatedErrorFactory;
var ReanimatedError: ReanimatedError;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import type {
AnimatedStyle,
} from '../commonTypes';
import { isWorkletFunction } from '../commonTypes';
import { logger } from '../logger';

const SHOULD_BE_USE_WEB = shouldBeUseWeb();

Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/hook/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import type { WorkletFunction } from '../commonTypes';

import type { DependencyList } from './commonTypes';
import { logger } from '../logger';

// Builds one big hash from multiple worklets' hashes.
export function buildWorkletsHash<Args extends unknown[], ReturnValue>(
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
Expand Up @@ -19,6 +19,7 @@ export {
getViewProp,
executeOnUIRuntimeSync,
} from './core';
export { ReanimatedError } from './errors';
export type {
GestureHandlers,
AnimatedRef,
Expand Down
4 changes: 2 additions & 2 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, ReanimatedError } from './errors';
import { reportFatalErrorOnJS, registerReanimatedError } from './errors';
import { isChromeDebugger, isJest, shouldBeUseWeb } from './PlatformChecker';
import {
runOnJS,
Expand All @@ -9,7 +9,7 @@ import {
} from './threads';
import { mockedRequestAnimationFrame } from './mockedRequestAnimationFrame';

global.ReanimatedError = ReanimatedError;
registerReanimatedError();

const IS_JEST = isJest();
const SHOULD_BE_USE_WEB = shouldBeUseWeb();
Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/interpolateColor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { makeMutable } from './core';
import { Extrapolation, interpolate } from './interpolation';
import type { SharedValue } from './commonTypes';
import { useSharedValue } from './hook/useSharedValue';
import { logger } from './logger';

/**
* @deprecated Please use Extrapolation instead
Expand Down
2 changes: 0 additions & 2 deletions packages/react-native-reanimated/src/interpolation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

import { logger } from './logger';

/**
* Extrapolation type.
*
Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/jestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import type {
} from './createAnimatedComponent/commonTypes';
import { isJest } from './PlatformChecker';
import type { DefaultStyle } from './hook/commonTypes';
import { logger } from './logger';

declare global {
namespace jest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {

import { ReduceMotion } from '../../commonTypes';
import { getReduceMotionFromConfig } from '../../animation/util';
import { logger } from '../../logger';

export class BaseAnimationBuilder {
durationV?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
assertEasingIsWorklet,
getReduceMotionFromConfig,
} from '../../animation/util';
import { logger } from '../../logger';

interface KeyframePoint {
duration: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {
import { registerEventHandler, unregisterEventHandler } from '../../core';
import { Platform } from 'react-native';
import { isJest, shouldBeUseWeb } from '../../PlatformChecker';
import { logger } from '../../logger';

type TransitionProgressEvent = {
closing: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { ReduceMotion } from '../../commonTypes';
import { ProgressTransitionManager } from './ProgressTransitionManager';
import { updateLayoutAnimations } from '../../UpdateLayoutAnimations';
import { getReduceMotionFromConfig } from '../../animation/util';
import { logger } from '../../logger';

const SUPPORTED_PROPS = [
'width',
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native-reanimated/src/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ export function logToLogBoxAndConsole(data: LogData) {
}

export function replaceLoggerImplementation(
logFunction: (data: LogData) => void
newLogFunction: (data: LogData) => void
) {
loggerImpl.logFunction = logFunction;
loggerImpl.logFunction = newLogFunction;
shareableMappingCache.set(logger, makeShareableCloneRecursive(logger));
}

Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/mutables.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';
import { shouldBeUseWeb } from './PlatformChecker';
import type { Mutable } from './commonTypes';
import { logger } from './logger';

import { shareableMappingCache } from './shareableMappingCache';
import { makeShareableCloneRecursive } from './shareables';
Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/runtimes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
makeShareableCloneOnUIRecursive,
makeShareableCloneRecursive,
} from './shareables';
import { logger } from './logger';

const SHOULD_BE_USE_WEB = shouldBeUseWeb();

Expand Down
1 change: 0 additions & 1 deletion packages/react-native-reanimated/src/shareables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ 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
Loading

0 comments on commit f7ab541

Please sign in to comment.