From 1f6a54274851e5c56b4c51734cb58f89e09c9bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBelawski?= Date: Fri, 24 Nov 2023 11:03:00 +0100 Subject: [PATCH 1/9] init --- .../LayoutAnimations/LayoutAnimationsManager.h | 9 ++------- .../cpp/NativeModules/NativeReanimatedModule.cpp | 9 ++++++--- Common/cpp/NativeModules/NativeReanimatedModule.h | 3 +++ .../cpp/ReanimatedRuntime/RNRuntimeDecorator.cpp | 4 +--- Common/cpp/Tools/JSLogger.cpp | 6 ++---- Common/cpp/Tools/JSLogger.h | 4 ---- Common/cpp/Tools/ReanimatedVersion.cpp | 14 +++++++++++--- Common/cpp/Tools/ReanimatedVersion.h | 6 +++--- .../ReanimatedExample.xcodeproj/project.pbxproj | 6 +++++- Example/ios/ReanimatedExample/AppDelegate.mm | 2 +- .../ios/FabricExample.xcodeproj/project.pbxproj | 6 +++++- FabricExample/ios/FabricExample/AppDelegate.mm | 2 +- .../ios/MacOSExample.xcodeproj/project.pbxproj | 6 +++++- MacOSExample/ios/MacOSExample/AppDelegate.mm | 2 +- .../macos/MacOSExample-macOS/AppDelegate.mm | 2 +- .../macos/MacOSExample.xcodeproj/project.pbxproj | 1 + .../ios/TVOSExample.xcodeproj/project.pbxproj | 10 ++++++++-- TVOSExample/ios/TVOSExample/AppDelegate.mm | 2 +- .../platform-specific/checkCppVersion.ts | 7 ++++--- src/reanimated2/shareables.ts | 15 ++++++++++----- 20 files changed, 71 insertions(+), 45 deletions(-) diff --git a/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h b/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h index acfbcaabb1b..d0afb7cb606 100644 --- a/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h +++ b/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h @@ -1,12 +1,9 @@ #pragma once +#include "JSLogger.h" #include "LayoutAnimationType.h" #include "Shareables.h" -#ifndef NDEBUG -#include "JSLogger.h" -#endif - #include #include #include @@ -23,10 +20,8 @@ using namespace facebook; class LayoutAnimationsManager { public: -#ifndef NDEBUG explicit LayoutAnimationsManager(const std::shared_ptr &jsLogger) : jsLogger_(jsLogger) {} -#endif void configureAnimation( int tag, LayoutAnimationType type, @@ -54,8 +49,8 @@ class LayoutAnimationsManager { std::unordered_map> &getConfigsForType( LayoutAnimationType type); -#ifndef NDEBUG std::shared_ptr jsLogger_; +#ifndef NDEBUG // This set's function is to detect duplicate sharedTags on a single screen // it contains strings in form: "reactScreenTag:sharedTag" std::unordered_set screenSharedTagSet_; diff --git a/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/Common/cpp/NativeModules/NativeReanimatedModule.cpp index 06f588de965..91c757614de 100644 --- a/Common/cpp/NativeModules/NativeReanimatedModule.cpp +++ b/Common/cpp/NativeModules/NativeReanimatedModule.cpp @@ -66,9 +66,8 @@ NativeReanimatedModule::NativeReanimatedModule( onRender(timestampMs); }), animatedSensorModule_(platformDepMethodsHolder), -#ifndef NDEBUG - layoutAnimationsManager_(std::make_shared(jsScheduler_)), -#endif + jsLogger_(std::make_shared(jsScheduler_)), + layoutAnimationsManager_(jsLogger_), #ifdef RCT_NEW_ARCH_ENABLED synchronouslyUpdateUIPropsFunction_( platformDepMethodsHolder.synchronouslyUpdateUIPropsFunction), @@ -380,6 +379,10 @@ jsi::Value NativeReanimatedModule::registerSensor( sensorDataHandler); } +std::shared_ptr NativeReanimatedModule::getJSLogger() { + return jsLogger_; +} + void NativeReanimatedModule::unregisterSensor( jsi::Runtime &, const jsi::Value &sensorId) { diff --git a/Common/cpp/NativeModules/NativeReanimatedModule.h b/Common/cpp/NativeModules/NativeReanimatedModule.h index 8a40774ea37..98776b50a31 100644 --- a/Common/cpp/NativeModules/NativeReanimatedModule.h +++ b/Common/cpp/NativeModules/NativeReanimatedModule.h @@ -117,6 +117,8 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec { const jsi::Value &payload, double currentTime); + std::shared_ptr getJSLogger(); + #ifdef RCT_NEW_ARCH_ENABLED bool handleRawEvent(const RawEvent &rawEvent, double currentTime); @@ -185,6 +187,7 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec { volatile bool renderRequested_{false}; const std::function onRenderCallback_; AnimatedSensorModule animatedSensorModule_; + std::shared_ptr jsLogger_; LayoutAnimationsManager layoutAnimationsManager_; #ifdef RCT_NEW_ARCH_ENABLED diff --git a/Common/cpp/ReanimatedRuntime/RNRuntimeDecorator.cpp b/Common/cpp/ReanimatedRuntime/RNRuntimeDecorator.cpp index d2d2b0e86c7..92f01f4f8d8 100644 --- a/Common/cpp/ReanimatedRuntime/RNRuntimeDecorator.cpp +++ b/Common/cpp/ReanimatedRuntime/RNRuntimeDecorator.cpp @@ -1,7 +1,5 @@ #include "RNRuntimeDecorator.h" -#ifndef NDEBUG #include "ReanimatedVersion.h" -#endif // NDEBUG namespace reanimated { @@ -32,7 +30,7 @@ void RNRuntimeDecorator::decorate( rnRuntime.global().setProperty(rnRuntime, "_IS_FABRIC", isFabric); #ifndef NDEBUG - checkJSVersion(rnRuntime); + checkJSVersion(rnRuntime, nativeReanimatedModule->getJSLogger()); #endif // NDEBUG rnRuntime.global().setProperty( diff --git a/Common/cpp/Tools/JSLogger.cpp b/Common/cpp/Tools/JSLogger.cpp index 3c9d923eb2b..3530aee2d90 100644 --- a/Common/cpp/Tools/JSLogger.cpp +++ b/Common/cpp/Tools/JSLogger.cpp @@ -1,18 +1,16 @@ -#ifndef NDEBUG - #include "JSLogger.h" #include namespace reanimated { void JSLogger::warnOnJS(const std::string &warning) const { +#ifndef NDEBUG jsScheduler_->scheduleOnJS([warning](jsi::Runtime &rt) { auto console = rt.global().getPropertyAsObject(rt, "console"); auto warn = console.getPropertyAsFunction(rt, "warn"); warn.call(rt, jsi::String::createFromUtf8(rt, warning)); }); +#endif // NDEBUG } } // namespace reanimated - -#endif // NDEBUG diff --git a/Common/cpp/Tools/JSLogger.h b/Common/cpp/Tools/JSLogger.h index aab9b8d58ca..9ddfc7dec89 100644 --- a/Common/cpp/Tools/JSLogger.h +++ b/Common/cpp/Tools/JSLogger.h @@ -1,5 +1,3 @@ -#ifndef NDEBUG - #pragma once #include "JSScheduler.h" @@ -20,5 +18,3 @@ class JSLogger { }; } // namespace reanimated - -#endif // NDEBUG diff --git a/Common/cpp/Tools/ReanimatedVersion.cpp b/Common/cpp/Tools/ReanimatedVersion.cpp index b0f5a6f83ac..b5c70a5378b 100644 --- a/Common/cpp/Tools/ReanimatedVersion.cpp +++ b/Common/cpp/Tools/ReanimatedVersion.cpp @@ -1,4 +1,6 @@ #include "ReanimatedVersion.h" +#include +#include #include #include @@ -41,26 +43,32 @@ bool matchVersion(const std::string &version1, const std::string &version2) { } } -void checkJSVersion(jsi::Runtime &rnRuntime) { +void checkJSVersion( + jsi::Runtime &rnRuntime, + std::shared_ptr jsLogger) { auto cppVersion = getReanimatedCppVersion(); auto maybeJSVersion = rnRuntime.global().getProperty(rnRuntime, "_REANIMATED_VERSION_JS"); if (maybeJSVersion.isUndefined()) { - throw std::runtime_error( + // throw std::runtime_error( + jsLogger->warnOnJS( std::string( "[Reanimated] C++ side failed to resolve JavaScript code version\n") + "See `https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#c-side-failed-to-resolve-javascript-code-version` for more details."); + return; } auto jsVersion = maybeJSVersion.asString(rnRuntime).utf8(rnRuntime); if (!matchVersion(cppVersion, jsVersion)) { - throw std::runtime_error( + // throw std::runtime_error( + jsLogger->warnOnJS( std::string( "[Reanimated] Mismatch between C++ code version and JavaScript code version (") + cppVersion + " vs. " + jsVersion + " respectively).\n" + "See `https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#mismatch-between-c-code-version-and-javascript-code-version` for more details."); + return; } rnRuntime.global().setProperty( diff --git a/Common/cpp/Tools/ReanimatedVersion.h b/Common/cpp/Tools/ReanimatedVersion.h index b4f4092e0c6..a1cdcac315f 100644 --- a/Common/cpp/Tools/ReanimatedVersion.h +++ b/Common/cpp/Tools/ReanimatedVersion.h @@ -1,7 +1,9 @@ #pragma once #include +#include #include +#include "JSLogger.h" using namespace facebook; @@ -9,9 +11,7 @@ namespace reanimated { std::string getReanimatedCppVersion(); -#ifndef NDEBUG bool matchVersion(const std::string &, const std::string &); -void checkJSVersion(jsi::Runtime &); -#endif // NDEBUG +void checkJSVersion(jsi::Runtime &, std::shared_ptr); }; // namespace reanimated diff --git a/Example/ios/ReanimatedExample.xcodeproj/project.pbxproj b/Example/ios/ReanimatedExample.xcodeproj/project.pbxproj index d196c458f07..791126414ba 100644 --- a/Example/ios/ReanimatedExample.xcodeproj/project.pbxproj +++ b/Example/ios/ReanimatedExample.xcodeproj/project.pbxproj @@ -487,7 +487,10 @@ baseConfigurationReference = 5B7EB9410499542E8C5724F5 /* Pods-ReanimatedExample-ReanimatedExampleTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); INFOPLIST_FILE = ReanimatedExampleTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.4; LD_RUNPATH_SEARCH_PATHS = ( @@ -621,6 +624,7 @@ GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", "$(inherited)", _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION, ); diff --git a/Example/ios/ReanimatedExample/AppDelegate.mm b/Example/ios/ReanimatedExample/AppDelegate.mm index d573152564b..9aad30f5614 100644 --- a/Example/ios/ReanimatedExample/AppDelegate.mm +++ b/Example/ios/ReanimatedExample/AppDelegate.mm @@ -16,7 +16,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { -#ifndef NDEBUG +#if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; diff --git a/FabricExample/ios/FabricExample.xcodeproj/project.pbxproj b/FabricExample/ios/FabricExample.xcodeproj/project.pbxproj index cc468034d20..10869ecefe5 100644 --- a/FabricExample/ios/FabricExample.xcodeproj/project.pbxproj +++ b/FabricExample/ios/FabricExample.xcodeproj/project.pbxproj @@ -482,7 +482,10 @@ baseConfigurationReference = 5B7EB9410499542E8C5724F5 /* Pods-FabricExample-FabricExampleTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); INFOPLIST_FILE = FabricExampleTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.4; LD_RUNPATH_SEARCH_PATHS = ( @@ -616,6 +619,7 @@ GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", "$(inherited)", _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION, ); diff --git a/FabricExample/ios/FabricExample/AppDelegate.mm b/FabricExample/ios/FabricExample/AppDelegate.mm index edf5cf12ed6..7cfe873e105 100644 --- a/FabricExample/ios/FabricExample/AppDelegate.mm +++ b/FabricExample/ios/FabricExample/AppDelegate.mm @@ -16,7 +16,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { -#ifndef NDEBUG +#if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; diff --git a/MacOSExample/ios/MacOSExample.xcodeproj/project.pbxproj b/MacOSExample/ios/MacOSExample.xcodeproj/project.pbxproj index 4a90d6b1c3c..10b7e9ec2c1 100644 --- a/MacOSExample/ios/MacOSExample.xcodeproj/project.pbxproj +++ b/MacOSExample/ios/MacOSExample.xcodeproj/project.pbxproj @@ -433,7 +433,10 @@ baseConfigurationReference = 5B7EB9410499542E8C5724F5 /* Pods-MacOSExample-MacOSExampleTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); INFOPLIST_FILE = MacOSExampleTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.4; LD_RUNPATH_SEARCH_PATHS = ( @@ -567,6 +570,7 @@ GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", "$(inherited)", _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION, ); diff --git a/MacOSExample/ios/MacOSExample/AppDelegate.mm b/MacOSExample/ios/MacOSExample/AppDelegate.mm index 3b50a45bf56..087182219cc 100644 --- a/MacOSExample/ios/MacOSExample/AppDelegate.mm +++ b/MacOSExample/ios/MacOSExample/AppDelegate.mm @@ -16,7 +16,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { -#ifndef NDEBUG +#if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; diff --git a/MacOSExample/macos/MacOSExample-macOS/AppDelegate.mm b/MacOSExample/macos/MacOSExample-macOS/AppDelegate.mm index b7bb2660ddf..1f66841abf0 100644 --- a/MacOSExample/macos/MacOSExample-macOS/AppDelegate.mm +++ b/MacOSExample/macos/MacOSExample-macOS/AppDelegate.mm @@ -16,7 +16,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { -#ifndef NDEBUG +#if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; diff --git a/MacOSExample/macos/MacOSExample.xcodeproj/project.pbxproj b/MacOSExample/macos/MacOSExample.xcodeproj/project.pbxproj index 0c46f65048f..5042534b4d0 100644 --- a/MacOSExample/macos/MacOSExample.xcodeproj/project.pbxproj +++ b/MacOSExample/macos/MacOSExample.xcodeproj/project.pbxproj @@ -474,6 +474,7 @@ GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", "$(inherited)", _LIBCPP_ENABLE_CXX17_REMOVED_UNARY_BINARY_FUNCTION, ); diff --git a/TVOSExample/ios/TVOSExample.xcodeproj/project.pbxproj b/TVOSExample/ios/TVOSExample.xcodeproj/project.pbxproj index 327a926eb1a..a7200b1bb07 100644 --- a/TVOSExample/ios/TVOSExample.xcodeproj/project.pbxproj +++ b/TVOSExample/ios/TVOSExample.xcodeproj/project.pbxproj @@ -680,7 +680,10 @@ baseConfigurationReference = 36771B2C8C43AC6099096637 /* Pods-TVOSExample-TVOSExampleTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; - GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); INFOPLIST_FILE = TVOSExampleTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 10.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -912,7 +915,10 @@ GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = "$(inherited)"; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; diff --git a/TVOSExample/ios/TVOSExample/AppDelegate.mm b/TVOSExample/ios/TVOSExample/AppDelegate.mm index 4bb7bc2e63d..9ec85147bec 100644 --- a/TVOSExample/ios/TVOSExample/AppDelegate.mm +++ b/TVOSExample/ios/TVOSExample/AppDelegate.mm @@ -87,7 +87,7 @@ - (NSDictionary *)prepareInitialProps - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { -#ifndef NDEBUG +#if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; diff --git a/src/reanimated2/platform-specific/checkCppVersion.ts b/src/reanimated2/platform-specific/checkCppVersion.ts index 2cff2af9a71..3b5a42ea45a 100644 --- a/src/reanimated2/platform-specific/checkCppVersion.ts +++ b/src/reanimated2/platform-specific/checkCppVersion.ts @@ -4,16 +4,17 @@ import { jsVersion } from './jsVersion'; export function checkCppVersion() { const cppVersion = global._REANIMATED_VERSION_CPP; if (cppVersion === undefined) { - throw new Error( + console.warn( `[Reanimated] Couldn't determine the version of the native part of Reanimated. -See \`https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#couldnt-determine-the-version-of-the-native-part-of-reanimated\` for more details.` + See \`https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#couldnt-determine-the-version-of-the-native-part-of-reanimated\` for more details.` ); + return; } const ok = matchVersion(jsVersion, cppVersion); if (!ok) { throw new Error( `[Reanimated] Mismatch between JavaScript part and native part of Reanimated (${jsVersion} vs ${cppVersion}). -See \`https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#mismatch-between-javascript-part-and-native-part-of-reanimated\` for more details.` + See \`https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#mismatch-between-javascript-part-and-native-part-of-reanimated\` for more details.` ); } } diff --git a/src/reanimated2/shareables.ts b/src/reanimated2/shareables.ts index 18e6a5b4656..6eb74dfbc6b 100644 --- a/src/reanimated2/shareables.ts +++ b/src/reanimated2/shareables.ts @@ -110,7 +110,9 @@ const VALID_ARRAY_VIEWS_NAMES = [ const DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD = 30; // Below variable stores object that we process in makeShareableCloneRecursive at the specified depth. // We use it to check if later on the function reenters with the same object -let processedObjectAtThresholdDepth: any; +let processedObjectAtThresholdDepth: unknown; + +let shouldWarnAboutBundleFlavor = true; export function makeShareableCloneRecursive( value: any, @@ -179,17 +181,20 @@ Offending code was: \`${getWorkletCode(value)}\``); value.__workletHash, value.__stackDetails ); - delete value.__stackDetails; - } else if (value.__stackDetails) { + } else if (shouldWarnAboutBundleFlavor && value.__stackDetails) { // Detected debug version of the worklet in release bundle. This // might lead to unexpected issues or errors. Probably one of user // dependencies provided transpiled code with debug version of the // Reanimated plugin. - throw new Error( - `[Reanimated] Using dev bundle in a release app build is not supported. + shouldWarnAboutBundleFlavor = false; + console.warn( + `[Reanimated] Using dev bundle in a release app support is limited, it might lead to unexpected issues or errors. We plan to fix this in the future. See \`https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#using-dev-bundle-in-a-release-app-build-is-not-supported\` for more details.` ); } + if (value.__stackDetails) { + delete value.__stackDetails; + } // to save on transferring static __initData field of worklet structure // we request shareable value to persist its UI counterpart. This means // that the __initData field that contains long strings represeting the From b59bac1808d370eb59f74cebd3e38ac6aaf1af6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBelawski?= Date: Fri, 24 Nov 2023 11:04:55 +0100 Subject: [PATCH 2/9] message --- src/reanimated2/shareables.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reanimated2/shareables.ts b/src/reanimated2/shareables.ts index 6eb74dfbc6b..1f4e62ca6a2 100644 --- a/src/reanimated2/shareables.ts +++ b/src/reanimated2/shareables.ts @@ -188,7 +188,7 @@ Offending code was: \`${getWorkletCode(value)}\``); // Reanimated plugin. shouldWarnAboutBundleFlavor = false; console.warn( - `[Reanimated] Using dev bundle in a release app support is limited, it might lead to unexpected issues or errors. We plan to fix this in the future. + `[Reanimated] Using dev bundle in a release app support is limited, it might lead to unexpected issues or errors. See \`https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#using-dev-bundle-in-a-release-app-build-is-not-supported\` for more details.` ); } From 0bbf09d1b056b61ce63fa3d7bb1383dd5d6e70d9 Mon Sep 17 00:00:00 2001 From: Tomek Zawadzki Date: Fri, 24 Nov 2023 11:17:56 +0100 Subject: [PATCH 3/9] Update AboutExample.tsx --- app/src/examples/AboutExample.tsx | 6 +++--- plugin/build/plugin.js | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/src/examples/AboutExample.tsx b/app/src/examples/AboutExample.tsx index 022c1a8b7ad..b646b6a7bcd 100644 --- a/app/src/examples/AboutExample.tsx +++ b/app/src/examples/AboutExample.tsx @@ -18,8 +18,8 @@ function getPlatformVersion() { return Platform.Version; } -function getMode() { - return __DEV__ ? 'Debug' : 'Release'; +function getBundle() { + return __DEV__ ? 'dev' : 'production'; } function getRuntime() { @@ -54,7 +54,7 @@ export default function AboutExample() { {getPlatformVersion()} - Build type: {getMode()} + Bundle: {getBundle()} {!isWeb() && ( <> diff --git a/plugin/build/plugin.js b/plugin/build/plugin.js index 27ea4849a1a..ee94561b7e6 100644 --- a/plugin/build/plugin.js +++ b/plugin/build/plugin.js @@ -32,9 +32,7 @@ var require_utils = __commonJS({ Object.defineProperty(exports2, "__esModule", { value: true }); exports2.isRelease = void 0; function isRelease() { - var _a, _b; - const pattern = /(prod|release|stag[ei])/i; - return !!(((_a = process.env.BABEL_ENV) === null || _a === void 0 ? void 0 : _a.match(pattern)) || ((_b = process.env.NODE_ENV) === null || _b === void 0 ? void 0 : _b.match(pattern))); + return false; } exports2.isRelease = isRelease; } From 9c6bf4f11efd29e64be7091d5b36331f1bd7f222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBelawski?= Date: Fri, 24 Nov 2023 12:34:50 +0100 Subject: [PATCH 4/9] warnele --- src/reanimated2/shareables.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/reanimated2/shareables.ts b/src/reanimated2/shareables.ts index 1f4e62ca6a2..313c4973dc6 100644 --- a/src/reanimated2/shareables.ts +++ b/src/reanimated2/shareables.ts @@ -114,6 +114,8 @@ let processedObjectAtThresholdDepth: unknown; let shouldWarnAboutBundleFlavor = true; +let shouldWarnAboutMissingPluginVersion = true; + export function makeShareableCloneRecursive( value: any, shouldPersistRemote = false, @@ -169,9 +171,12 @@ export function makeShareableCloneRecursive( if (__DEV__) { const babelVersion = value.__initData.version; if (babelVersion === undefined) { - throw new Error(`[Reanimated] Unknown version of Reanimated Babel plugin. -See \`https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#unknown-version-of-reanimated-babel-plugin\` for more details. -Offending code was: \`${getWorkletCode(value)}\``); + if (shouldWarnAboutMissingPluginVersion) { + shouldWarnAboutMissingPluginVersion = false; + console.warn(`[Reanimated] Unknown version of Reanimated Babel plugin. + See \`https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#unknown-version-of-reanimated-babel-plugin\` for more details. + Offending code was: \`${getWorkletCode(value)}\``); + } } else if (babelVersion !== jsVersion) { throw new Error(`[Reanimated] Mismatch between JavaScript code version and Reanimated Babel plugin version (${jsVersion} vs. ${babelVersion}). See \`https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#mismatch-between-javascript-code-version-and-reanimated-babel-plugin-version\` for more details. From 7daf118f83be5b94ea8b1dbbaa3496bf91fe301c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBelawski?= Date: Fri, 24 Nov 2023 12:58:14 +0100 Subject: [PATCH 5/9] review changes --- .../cpp/NativeModules/NativeReanimatedModule.h | 2 +- Common/cpp/Tools/ReanimatedVersion.cpp | 6 ++---- Common/cpp/Tools/ReanimatedVersion.h | 2 +- src/reanimated2/shareables.ts | 16 ++++------------ 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/Common/cpp/NativeModules/NativeReanimatedModule.h b/Common/cpp/NativeModules/NativeReanimatedModule.h index 98776b50a31..a814bc6dc47 100644 --- a/Common/cpp/NativeModules/NativeReanimatedModule.h +++ b/Common/cpp/NativeModules/NativeReanimatedModule.h @@ -187,7 +187,7 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec { volatile bool renderRequested_{false}; const std::function onRenderCallback_; AnimatedSensorModule animatedSensorModule_; - std::shared_ptr jsLogger_; + const std::shared_ptr jsLogger_; LayoutAnimationsManager layoutAnimationsManager_; #ifdef RCT_NEW_ARCH_ENABLED diff --git a/Common/cpp/Tools/ReanimatedVersion.cpp b/Common/cpp/Tools/ReanimatedVersion.cpp index b5c70a5378b..2e43f5c6795 100644 --- a/Common/cpp/Tools/ReanimatedVersion.cpp +++ b/Common/cpp/Tools/ReanimatedVersion.cpp @@ -1,8 +1,8 @@ #include "ReanimatedVersion.h" -#include #include #include #include +#include "JSLogger.h" #ifdef REANIMATED_VERSION #define STRINGIZE(x) #x @@ -45,13 +45,12 @@ bool matchVersion(const std::string &version1, const std::string &version2) { void checkJSVersion( jsi::Runtime &rnRuntime, - std::shared_ptr jsLogger) { + const std::shared_ptr &jsLogger) { auto cppVersion = getReanimatedCppVersion(); auto maybeJSVersion = rnRuntime.global().getProperty(rnRuntime, "_REANIMATED_VERSION_JS"); if (maybeJSVersion.isUndefined()) { - // throw std::runtime_error( jsLogger->warnOnJS( std::string( "[Reanimated] C++ side failed to resolve JavaScript code version\n") + @@ -62,7 +61,6 @@ void checkJSVersion( auto jsVersion = maybeJSVersion.asString(rnRuntime).utf8(rnRuntime); if (!matchVersion(cppVersion, jsVersion)) { - // throw std::runtime_error( jsLogger->warnOnJS( std::string( "[Reanimated] Mismatch between C++ code version and JavaScript code version (") + diff --git a/Common/cpp/Tools/ReanimatedVersion.h b/Common/cpp/Tools/ReanimatedVersion.h index a1cdcac315f..36ad6d42bb9 100644 --- a/Common/cpp/Tools/ReanimatedVersion.h +++ b/Common/cpp/Tools/ReanimatedVersion.h @@ -12,6 +12,6 @@ namespace reanimated { std::string getReanimatedCppVersion(); bool matchVersion(const std::string &, const std::string &); -void checkJSVersion(jsi::Runtime &, std::shared_ptr); +void checkJSVersion(jsi::Runtime &, const std::shared_ptr &); }; // namespace reanimated diff --git a/src/reanimated2/shareables.ts b/src/reanimated2/shareables.ts index 313c4973dc6..7ecbbbe9f5e 100644 --- a/src/reanimated2/shareables.ts +++ b/src/reanimated2/shareables.ts @@ -112,8 +112,6 @@ const DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD = 30; // We use it to check if later on the function reenters with the same object let processedObjectAtThresholdDepth: unknown; -let shouldWarnAboutBundleFlavor = true; - let shouldWarnAboutMissingPluginVersion = true; export function makeShareableCloneRecursive( @@ -186,18 +184,12 @@ Offending code was: \`${getWorkletCode(value)}\``); value.__workletHash, value.__stackDetails ); - } else if (shouldWarnAboutBundleFlavor && value.__stackDetails) { - // Detected debug version of the worklet in release bundle. This - // might lead to unexpected issues or errors. Probably one of user - // dependencies provided transpiled code with debug version of the - // Reanimated plugin. - shouldWarnAboutBundleFlavor = false; - console.warn( - `[Reanimated] Using dev bundle in a release app support is limited, it might lead to unexpected issues or errors. -See \`https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#using-dev-bundle-in-a-release-app-build-is-not-supported\` for more details.` - ); } if (value.__stackDetails) { + // `Error` type of value cannot be copied to the UI thread, so we + // remove it after we handled it in DEV mode or delete it to ignore it in RELEASE. + // Not removing this would cause an infinite loop in RELEASE and it just seems more elegant + // to handle it this way. delete value.__stackDetails; } // to save on transferring static __initData field of worklet structure From fef5e0057e91f84057caef36d4a500498aad3039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBelawski?= Date: Fri, 24 Nov 2023 12:59:42 +0100 Subject: [PATCH 6/9] plugin troll --- plugin/build/plugin.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugin/build/plugin.js b/plugin/build/plugin.js index ee94561b7e6..27ea4849a1a 100644 --- a/plugin/build/plugin.js +++ b/plugin/build/plugin.js @@ -32,7 +32,9 @@ var require_utils = __commonJS({ Object.defineProperty(exports2, "__esModule", { value: true }); exports2.isRelease = void 0; function isRelease() { - return false; + var _a, _b; + const pattern = /(prod|release|stag[ei])/i; + return !!(((_a = process.env.BABEL_ENV) === null || _a === void 0 ? void 0 : _a.match(pattern)) || ((_b = process.env.NODE_ENV) === null || _b === void 0 ? void 0 : _b.match(pattern))); } exports2.isRelease = isRelease; } From 429ea49841c8f31c34b0560a920f1350d6214590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBelawski?= Date: Fri, 24 Nov 2023 13:04:45 +0100 Subject: [PATCH 7/9] tests --- __tests__/checkVersion.test.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/__tests__/checkVersion.test.ts b/__tests__/checkVersion.test.ts index df4e674126a..3434a447c48 100644 --- a/__tests__/checkVersion.test.ts +++ b/__tests__/checkVersion.test.ts @@ -14,12 +14,20 @@ describe('checkCppVersion', () => { }); it('checks version successfully', () => { - expect(checkCppVersion).not.toThrow(); + // eslint-disable-next-line @typescript-eslint/no-empty-function + jest.spyOn(console, 'warn').mockImplementation(() => {}); + checkCppVersion(); + expect(console.warn).not.toBeCalled(); + jest.clearAllMocks(); }); it('throws error when version is undefined', () => { + // eslint-disable-next-line @typescript-eslint/no-empty-function + jest.spyOn(console, 'warn').mockImplementation(() => {}); delete global._REANIMATED_VERSION_CPP; - expect(checkCppVersion).toThrow(); + checkCppVersion(); + expect(console.warn).toBeCalled(); + jest.clearAllMocks(); }); }); From a6edd8a7e2b7beebb61781997a65ca41b849f7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBelawski?= Date: Fri, 24 Nov 2023 13:43:54 +0100 Subject: [PATCH 8/9] review changes --- __tests__/checkVersion.test.ts | 6 ++---- src/reanimated2/shareables.ts | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/__tests__/checkVersion.test.ts b/__tests__/checkVersion.test.ts index 3434a447c48..268553d28a7 100644 --- a/__tests__/checkVersion.test.ts +++ b/__tests__/checkVersion.test.ts @@ -14,16 +14,14 @@ describe('checkCppVersion', () => { }); it('checks version successfully', () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - jest.spyOn(console, 'warn').mockImplementation(() => {}); + jest.spyOn(console, 'warn').mockImplementation(); checkCppVersion(); expect(console.warn).not.toBeCalled(); jest.clearAllMocks(); }); it('throws error when version is undefined', () => { - // eslint-disable-next-line @typescript-eslint/no-empty-function - jest.spyOn(console, 'warn').mockImplementation(() => {}); + jest.spyOn(console, 'warn').mockImplementation(); delete global._REANIMATED_VERSION_CPP; checkCppVersion(); expect(console.warn).toBeCalled(); diff --git a/src/reanimated2/shareables.ts b/src/reanimated2/shareables.ts index 7ecbbbe9f5e..ad04964d177 100644 --- a/src/reanimated2/shareables.ts +++ b/src/reanimated2/shareables.ts @@ -187,9 +187,9 @@ Offending code was: \`${getWorkletCode(value)}\``); } if (value.__stackDetails) { // `Error` type of value cannot be copied to the UI thread, so we - // remove it after we handled it in DEV mode or delete it to ignore it in RELEASE. - // Not removing this would cause an infinite loop in RELEASE and it just seems more elegant - // to handle it this way. + // remove it after we handled it in dev mode or delete it to ignore it in production mode. + // Not removing this would cause an infinite loop in production mode and it just + // seems more elegant to handle it this way. delete value.__stackDetails; } // to save on transferring static __initData field of worklet structure From c9fc8a9deeabf061221a77cf2faddb34cd22e333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=BBelawski?= Date: Fri, 24 Nov 2023 14:01:25 +0100 Subject: [PATCH 9/9] reviewele --- Common/cpp/NativeModules/NativeReanimatedModule.cpp | 4 ---- Common/cpp/NativeModules/NativeReanimatedModule.h | 4 +++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Common/cpp/NativeModules/NativeReanimatedModule.cpp b/Common/cpp/NativeModules/NativeReanimatedModule.cpp index 91c757614de..2a1bd4c2bd4 100644 --- a/Common/cpp/NativeModules/NativeReanimatedModule.cpp +++ b/Common/cpp/NativeModules/NativeReanimatedModule.cpp @@ -379,10 +379,6 @@ jsi::Value NativeReanimatedModule::registerSensor( sensorDataHandler); } -std::shared_ptr NativeReanimatedModule::getJSLogger() { - return jsLogger_; -} - void NativeReanimatedModule::unregisterSensor( jsi::Runtime &, const jsi::Value &sensorId) { diff --git a/Common/cpp/NativeModules/NativeReanimatedModule.h b/Common/cpp/NativeModules/NativeReanimatedModule.h index a814bc6dc47..858b8791a98 100644 --- a/Common/cpp/NativeModules/NativeReanimatedModule.h +++ b/Common/cpp/NativeModules/NativeReanimatedModule.h @@ -117,7 +117,9 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec { const jsi::Value &payload, double currentTime); - std::shared_ptr getJSLogger(); + inline std::shared_ptr getJSLogger() const { + return jsLogger_; + } #ifdef RCT_NEW_ARCH_ENABLED bool handleRawEvent(const RawEvent &rawEvent, double currentTime);