diff --git a/apps/common-app/src/examples/EmptyExample.tsx b/apps/common-app/src/examples/EmptyExample.tsx index 0a9a4070680..aa6167a10d5 100644 --- a/apps/common-app/src/examples/EmptyExample.tsx +++ b/apps/common-app/src/examples/EmptyExample.tsx @@ -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 diff --git a/apps/fabric-example/ios/Podfile.lock b/apps/fabric-example/ios/Podfile.lock index 4d4d4bcea67..afb9f4ac5f9 100644 --- a/apps/fabric-example/ios/Podfile.lock +++ b/apps/fabric-example/ios/Podfile.lock @@ -2195,7 +2195,7 @@ SPEC CHECKSUMS: RNScreens: de6e57426ba0e6cbc3fb5b4f496e7f08cb2773c2 RNSVG: 6b65086b51556fd9723d5570a3455e865e1304a3 SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d - Yoga: 132f64c229103548a5c95fe12e2ab492fbd5c793 + Yoga: 1e170d028257c3ceb6e652dd62b2698dbc108a4b PODFILE CHECKSUM: baaf1c2684753f6bff7da2866e138e1af1fe3499 diff --git a/packages/react-native-reanimated/Common/cpp/reanimated/Fabric/ShadowTreeCloner.h b/packages/react-native-reanimated/Common/cpp/reanimated/Fabric/ShadowTreeCloner.h index efa186252f9..e3f9f6d9141 100644 --- a/packages/react-native-reanimated/Common/cpp/reanimated/Fabric/ShadowTreeCloner.h +++ b/packages/react-native-reanimated/Common/cpp/reanimated/Fabric/ShadowTreeCloner.h @@ -4,8 +4,8 @@ #include #include -#include #include +#include #include #include #include @@ -15,8 +15,10 @@ using namespace react; namespace reanimated { -using PropsMap = std::unordered_map>; -using ChildrenMap = std::unordered_map>; +using PropsMap = + std::unordered_map>; +using ChildrenMap = + std::unordered_map>; RootShadowNode::Unshared cloneShadowTreeWithNewProps( const RootShadowNode &oldRootNode, diff --git a/packages/react-native-reanimated/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp b/packages/react-native-reanimated/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp index 75e795e6655..672f04242bc 100644 --- a/packages/react-native-reanimated/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp +++ b/packages/react-native-reanimated/Common/cpp/worklets/WorkletRuntime/WorkletRuntimeDecorator.cpp @@ -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(args.data()), args.size()); + remoteFun.asObject(rt).asFunction(rt).call( + rt, const_cast(args.data()), args.size()); } }); }); diff --git a/packages/react-native-reanimated/jest-setup.js b/packages/react-native-reanimated/jest-setup.js index 0dfbfecaf29..983b977cd31 100644 --- a/packages/react-native-reanimated/jest-setup.js +++ b/packages/react-native-reanimated/jest-setup.js @@ -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)); - } -} diff --git a/packages/react-native-reanimated/jest.config.js b/packages/react-native-reanimated/jest.config.js index 7264cee785c..700df174109 100644 --- a/packages/react-native-reanimated/jest.config.js +++ b/packages/react-native-reanimated/jest.config.js @@ -5,4 +5,7 @@ module.exports = { setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'], testEnvironment: 'node', transformIgnorePatterns: [], + globals: { + ReanimatedError: true + } }; diff --git a/packages/react-native-reanimated/plugin/build/plugin.js b/packages/react-native-reanimated/plugin/build/plugin.js index 3b897753a0a..538da401f5a 100644 --- a/packages/react-native-reanimated/plugin/build/plugin.js +++ b/packages/react-native-reanimated/plugin/build/plugin.js @@ -141,7 +141,8 @@ var require_globals = __commonJS({ "setImmediate", "arguments", "HermesInternal", - "_WORKLET" + "_WORKLET", + "ReanimatedError" ]; var notCapturedIdentifiers_DEPRECATED = [ "_IS_FABRIC", @@ -1485,7 +1486,7 @@ var require_class = __commonJS({ } function recursiveTopoSort(current, toSort, sorted, stack) { 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; diff --git a/packages/react-native-reanimated/plugin/src/class.ts b/packages/react-native-reanimated/plugin/src/class.ts index 88e5dd1c8ab..b358c107dc4 100644 --- a/packages/react-native-reanimated/plugin/src/class.ts +++ b/packages/react-native-reanimated/plugin/src/class.ts @@ -293,7 +293,7 @@ function recursiveTopoSort( stack: Set ) { 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; diff --git a/packages/react-native-reanimated/plugin/src/globals.ts b/packages/react-native-reanimated/plugin/src/globals.ts index dc790c8a812..b9f5ce1566b 100644 --- a/packages/react-native-reanimated/plugin/src/globals.ts +++ b/packages/react-native-reanimated/plugin/src/globals.ts @@ -116,6 +116,7 @@ const notCapturedIdentifiers = [ // Reanimated '_WORKLET', + 'ReanimatedError', ]; /** diff --git a/packages/react-native-reanimated/src/Bezier.ts b/packages/react-native-reanimated/src/Bezier.ts index c9d6d4e0ed4..c4dea99ccc9 100644 --- a/packages/react-native-reanimated/src/Bezier.ts +++ b/packages/react-native-reanimated/src/Bezier.ts @@ -1,7 +1,5 @@ 'use strict'; -import { logger } from './logger'; - /** * https://github.com/gre/bezier-easing * BezierEasing - use bezier curve for transition easing function diff --git a/packages/react-native-reanimated/src/ConfigHelper.ts b/packages/react-native-reanimated/src/ConfigHelper.ts index 00a0be5794b..f42e51e5733 100644 --- a/packages/react-native-reanimated/src/ConfigHelper.ts +++ b/packages/react-native-reanimated/src/ConfigHelper.ts @@ -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) { diff --git a/packages/react-native-reanimated/src/NativeReanimated/NativeReanimated.ts b/packages/react-native-reanimated/src/NativeReanimated/NativeReanimated.ts index c3daf6e2d93..5180f0ca37b 100644 --- a/packages/react-native-reanimated/src/NativeReanimated/NativeReanimated.ts +++ b/packages/react-native-reanimated/src/NativeReanimated/NativeReanimated.ts @@ -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 { diff --git a/packages/react-native-reanimated/src/PropsRegistry.ts b/packages/react-native-reanimated/src/PropsRegistry.ts index 9405cf70ee6..0f56b4f7e28 100644 --- a/packages/react-native-reanimated/src/PropsRegistry.ts +++ b/packages/react-native-reanimated/src/PropsRegistry.ts @@ -1,6 +1,5 @@ 'use strict'; -import { logger } from './logger'; import { isFabric } from './PlatformChecker'; import { runOnUI } from './threads'; diff --git a/packages/react-native-reanimated/src/UpdateProps.ts b/packages/react-native-reanimated/src/UpdateProps.ts index 34eb2c60090..0f43165c8ca 100644 --- a/packages/react-native-reanimated/src/UpdateProps.ts +++ b/packages/react-native-reanimated/src/UpdateProps.ts @@ -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, diff --git a/packages/react-native-reanimated/src/animation/decay/decay.ts b/packages/react-native-reanimated/src/animation/decay/decay.ts index 9096aa53ce5..e5d0cefb90f 100644 --- a/packages/react-native-reanimated/src/animation/decay/decay.ts +++ b/packages/react-native-reanimated/src/animation/decay/decay.ts @@ -14,7 +14,6 @@ import type { InnerDecayAnimation, } from './utils'; import { rigidDecay } from './rigidDecay'; -import { logger } from '../../logger'; export type WithDecayConfig = DecayConfig; diff --git a/packages/react-native-reanimated/src/animation/transformationMatrix/matrixUtils.tsx b/packages/react-native-reanimated/src/animation/transformationMatrix/matrixUtils.tsx index 18f6c69c5e4..8e012426507 100644 --- a/packages/react-native-reanimated/src/animation/transformationMatrix/matrixUtils.tsx +++ b/packages/react-native-reanimated/src/animation/transformationMatrix/matrixUtils.tsx @@ -1,7 +1,5 @@ 'use strict'; -import { logger } from '../../logger'; - type FixedLengthArray< T, L extends number, diff --git a/packages/react-native-reanimated/src/animation/util.ts b/packages/react-native-reanimated/src/animation/util.ts index 90eee131f14..210215f026e 100644 --- a/packages/react-native-reanimated/src/animation/util.ts +++ b/packages/react-native-reanimated/src/animation/util.ts @@ -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%]*)/ diff --git a/packages/react-native-reanimated/src/core.ts b/packages/react-native-reanimated/src/core.ts index c93d27f6d0a..6db2700affb 100644 --- a/packages/react-native-reanimated/src/core.ts +++ b/packages/react-native-reanimated/src/core.ts @@ -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'; diff --git a/packages/react-native-reanimated/src/createAnimatedComponent/createAnimatedComponent.tsx b/packages/react-native-reanimated/src/createAnimatedComponent/createAnimatedComponent.tsx index 236653b148a..9d6acc95cf1 100644 --- a/packages/react-native-reanimated/src/createAnimatedComponent/createAnimatedComponent.tsx +++ b/packages/react-native-reanimated/src/createAnimatedComponent/createAnimatedComponent.tsx @@ -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(); diff --git a/packages/react-native-reanimated/src/errors.ts b/packages/react-native-reanimated/src/errors.ts index db094d43a20..6d055525b37 100644 --- a/packages/react-native-reanimated/src/errors.ts +++ b/packages/react-native-reanimated/src/errors.ts @@ -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(); export function registerWorkletStackDetails( diff --git a/packages/react-native-reanimated/src/fabricUtils.web.ts b/packages/react-native-reanimated/src/fabricUtils.web.ts index 6ca4fcac58d..6cb37728bdc 100644 --- a/packages/react-native-reanimated/src/fabricUtils.web.ts +++ b/packages/react-native-reanimated/src/fabricUtils.web.ts @@ -1,7 +1,5 @@ 'use strict'; -import { logger } from './logger'; - export function getShadowNodeWrapperFromRef() { throw new ReanimatedError( 'Trying to call `getShadowNodeWrapperFromRef` on web.' diff --git a/packages/react-native-reanimated/src/globals.d.ts b/packages/react-native-reanimated/src/globals.d.ts index 37af267dc3f..4870c932c06 100644 --- a/packages/react-native-reanimated/src/globals.d.ts +++ b/packages/react-native-reanimated/src/globals.d.ts @@ -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; @@ -113,5 +113,5 @@ declare global { shadowNodeWrapper: ShadowNodeWrapper, propName: string ) => string; - var ReanimatedError: typeof ReanimatedErrorFactory; + var ReanimatedError: ReanimatedError; } diff --git a/packages/react-native-reanimated/src/hook/useAnimatedStyle.ts b/packages/react-native-reanimated/src/hook/useAnimatedStyle.ts index b1630144d88..ace51d3ff91 100644 --- a/packages/react-native-reanimated/src/hook/useAnimatedStyle.ts +++ b/packages/react-native-reanimated/src/hook/useAnimatedStyle.ts @@ -34,7 +34,6 @@ import type { AnimatedStyle, } from '../commonTypes'; import { isWorkletFunction } from '../commonTypes'; -import { logger } from '../logger'; const SHOULD_BE_USE_WEB = shouldBeUseWeb(); diff --git a/packages/react-native-reanimated/src/hook/utils.ts b/packages/react-native-reanimated/src/hook/utils.ts index 58e39cd292c..b2e9ddbfea4 100644 --- a/packages/react-native-reanimated/src/hook/utils.ts +++ b/packages/react-native-reanimated/src/hook/utils.ts @@ -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( diff --git a/packages/react-native-reanimated/src/index.ts b/packages/react-native-reanimated/src/index.ts index d60e52c851f..d67e031e071 100644 --- a/packages/react-native-reanimated/src/index.ts +++ b/packages/react-native-reanimated/src/index.ts @@ -19,6 +19,7 @@ export { getViewProp, executeOnUIRuntimeSync, } from './core'; +export { ReanimatedError } from './errors'; export type { GestureHandlers, AnimatedRef, diff --git a/packages/react-native-reanimated/src/initializers.ts b/packages/react-native-reanimated/src/initializers.ts index 3c2e919874a..c131bf65415 100644 --- a/packages/react-native-reanimated/src/initializers.ts +++ b/packages/react-native-reanimated/src/initializers.ts @@ -1,5 +1,5 @@ 'use strict'; -import { reportFatalErrorOnJS, ReanimatedError } from './errors'; +import { reportFatalErrorOnJS, registerReanimatedError } from './errors'; import { isChromeDebugger, isJest, shouldBeUseWeb } from './PlatformChecker'; import { runOnJS, @@ -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(); diff --git a/packages/react-native-reanimated/src/interpolateColor.ts b/packages/react-native-reanimated/src/interpolateColor.ts index 62acafabea6..010e4528819 100644 --- a/packages/react-native-reanimated/src/interpolateColor.ts +++ b/packages/react-native-reanimated/src/interpolateColor.ts @@ -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 diff --git a/packages/react-native-reanimated/src/interpolation.ts b/packages/react-native-reanimated/src/interpolation.ts index a489dd0b698..0de7880a421 100644 --- a/packages/react-native-reanimated/src/interpolation.ts +++ b/packages/react-native-reanimated/src/interpolation.ts @@ -1,7 +1,5 @@ 'use strict'; -import { logger } from './logger'; - /** * Extrapolation type. * diff --git a/packages/react-native-reanimated/src/jestUtils.ts b/packages/react-native-reanimated/src/jestUtils.ts index cd5edc26fee..93dfb73dd84 100644 --- a/packages/react-native-reanimated/src/jestUtils.ts +++ b/packages/react-native-reanimated/src/jestUtils.ts @@ -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 { diff --git a/packages/react-native-reanimated/src/js-reanimated/JSReanimated.ts b/packages/react-native-reanimated/src/js-reanimated/JSReanimated.ts index 5c853de3f59..3604a9f75d2 100644 --- a/packages/react-native-reanimated/src/js-reanimated/JSReanimated.ts +++ b/packages/react-native-reanimated/src/js-reanimated/JSReanimated.ts @@ -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. diff --git a/packages/react-native-reanimated/src/layoutReanimation/animationBuilder/BaseAnimationBuilder.ts b/packages/react-native-reanimated/src/layoutReanimation/animationBuilder/BaseAnimationBuilder.ts index e10b768b70c..8e2aad7dc2a 100644 --- a/packages/react-native-reanimated/src/layoutReanimation/animationBuilder/BaseAnimationBuilder.ts +++ b/packages/react-native-reanimated/src/layoutReanimation/animationBuilder/BaseAnimationBuilder.ts @@ -8,7 +8,6 @@ import type { import { ReduceMotion } from '../../commonTypes'; import { getReduceMotionFromConfig } from '../../animation/util'; -import { logger } from '../../logger'; export class BaseAnimationBuilder { durationV?: number; diff --git a/packages/react-native-reanimated/src/layoutReanimation/animationBuilder/Keyframe.ts b/packages/react-native-reanimated/src/layoutReanimation/animationBuilder/Keyframe.ts index aecd8b265a5..b1feba23e1c 100644 --- a/packages/react-native-reanimated/src/layoutReanimation/animationBuilder/Keyframe.ts +++ b/packages/react-native-reanimated/src/layoutReanimation/animationBuilder/Keyframe.ts @@ -18,7 +18,6 @@ import { assertEasingIsWorklet, getReduceMotionFromConfig, } from '../../animation/util'; -import { logger } from '../../logger'; interface KeyframePoint { duration: number; diff --git a/packages/react-native-reanimated/src/layoutReanimation/sharedTransitions/ProgressTransitionManager.ts b/packages/react-native-reanimated/src/layoutReanimation/sharedTransitions/ProgressTransitionManager.ts index 7f830ef5251..5efc025dc89 100644 --- a/packages/react-native-reanimated/src/layoutReanimation/sharedTransitions/ProgressTransitionManager.ts +++ b/packages/react-native-reanimated/src/layoutReanimation/sharedTransitions/ProgressTransitionManager.ts @@ -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; diff --git a/packages/react-native-reanimated/src/layoutReanimation/sharedTransitions/SharedTransition.ts b/packages/react-native-reanimated/src/layoutReanimation/sharedTransitions/SharedTransition.ts index 6c2a2330102..e303637f924 100644 --- a/packages/react-native-reanimated/src/layoutReanimation/sharedTransitions/SharedTransition.ts +++ b/packages/react-native-reanimated/src/layoutReanimation/sharedTransitions/SharedTransition.ts @@ -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', diff --git a/packages/react-native-reanimated/src/logger/logger.ts b/packages/react-native-reanimated/src/logger/logger.ts index f84081e26df..00c32be1cad 100644 --- a/packages/react-native-reanimated/src/logger/logger.ts +++ b/packages/react-native-reanimated/src/logger/logger.ts @@ -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)); } diff --git a/packages/react-native-reanimated/src/mutables.ts b/packages/react-native-reanimated/src/mutables.ts index ddbca230b12..cc4d025b43a 100644 --- a/packages/react-native-reanimated/src/mutables.ts +++ b/packages/react-native-reanimated/src/mutables.ts @@ -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'; diff --git a/packages/react-native-reanimated/src/runtimes.ts b/packages/react-native-reanimated/src/runtimes.ts index 1e5194e06a2..fd556469de3 100644 --- a/packages/react-native-reanimated/src/runtimes.ts +++ b/packages/react-native-reanimated/src/runtimes.ts @@ -9,7 +9,6 @@ import { makeShareableCloneOnUIRecursive, makeShareableCloneRecursive, } from './shareables'; -import { logger } from './logger'; const SHOULD_BE_USE_WEB = shouldBeUseWeb(); diff --git a/packages/react-native-reanimated/src/shareables.ts b/packages/react-native-reanimated/src/shareables.ts index ca83e7debfd..c2abc007af5 100644 --- a/packages/react-native-reanimated/src/shareables.ts +++ b/packages/react-native-reanimated/src/shareables.ts @@ -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 diff --git a/packages/react-native-reanimated/src/threads.ts b/packages/react-native-reanimated/src/threads.ts index af0c5ee5447..7f1985fd383 100644 --- a/packages/react-native-reanimated/src/threads.ts +++ b/packages/react-native-reanimated/src/threads.ts @@ -7,7 +7,9 @@ import { makeShareableCloneRecursive, } from './shareables'; import { isWorkletFunction } from './commonTypes'; +import type { LogData } from './logger'; import { logToLogBoxAndConsole, replaceLoggerImplementation } from './logger'; +import { registerReanimatedError } from './errors'; const IS_JEST = isJest(); const SHOULD_BE_USE_WEB = shouldBeUseWeb(); @@ -260,4 +262,9 @@ export function runOnJS( // Override the logFunction implementation with the one that adds logs // with better stack traces to the LogBox (need to override it after runOnJS // is defined). -replaceLoggerImplementation(runOnJS(logToLogBoxAndConsole)); +replaceLoggerImplementation((data: LogData) => { + 'worklet'; + runOnJS(logToLogBoxAndConsole)(data); +}); +// Register ReanimatedError in the UI global scope +executeOnUIRuntimeSync(registerReanimatedError)(); diff --git a/packages/react-native-reanimated/src/valueUnpacker.ts b/packages/react-native-reanimated/src/valueUnpacker.ts index 8a0404db042..26e8dbe356f 100644 --- a/packages/react-native-reanimated/src/valueUnpacker.ts +++ b/packages/react-native-reanimated/src/valueUnpacker.ts @@ -2,7 +2,6 @@ import { shouldBeUseWeb } from './PlatformChecker'; import { isWorkletFunction } from './commonTypes'; import type { WorkletFunction } from './commonTypes'; -import { logger } from './logger'; function valueUnpacker( objectToUnpack: any, @@ -89,19 +88,19 @@ if (__DEV__ && !shouldBeUseWeb()) { 'worklet'; }) as WorkletFunction<[], void>; if (!isWorkletFunction(testWorklet)) { - throw new ReanimatedError( - `Failed to create a worklet. See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#failed-to-create-a-worklet for more details.` + throw new Error( + `[Reanimated] Failed to create a worklet. See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#failed-to-create-a-worklet for more details.` ); } if (!isWorkletFunction(valueUnpacker)) { - throw new ReanimatedError('`valueUnpacker` is not a worklet'); + throw new Error('[Reanimated] `valueUnpacker` is not a worklet'); } const closure = (valueUnpacker as ValueUnpacker).__closure; if (closure === undefined) { - throw new ReanimatedError('`valueUnpacker` closure is undefined'); + throw new Error('[Reanimated] `valueUnpacker` closure is undefined'); } if (Object.keys(closure).length !== 0) { - throw new ReanimatedError('`valueUnpacker` must have empty closure'); + throw new Error('[Reanimated] `valueUnpacker` must have empty closure'); } }