diff --git a/packages/react-native-reanimated/Common/cpp/worklets/SharedItems/Shareables.cpp b/packages/react-native-reanimated/Common/cpp/worklets/SharedItems/Shareables.cpp index 525cd114ebb..12216edfeb4 100644 --- a/packages/react-native-reanimated/Common/cpp/worklets/SharedItems/Shareables.cpp +++ b/packages/react-native-reanimated/Common/cpp/worklets/SharedItems/Shareables.cpp @@ -47,7 +47,12 @@ jsi::Value makeShareableClone( if (value.isObject()) { auto object = value.asObject(rt); if (!object.getProperty(rt, "__workletHash").isUndefined()) { - shareable = std::make_shared(rt, object); + if (shouldRetainRemote.isBool() && shouldRetainRemote.getBool()) { + shareable = + std::make_shared>(rt, object); + } else { + shareable = std::make_shared(rt, object); + } } else if (!object.getProperty(rt, "__init").isUndefined()) { shareable = std::make_shared(rt, object); } else if (object.isFunction(rt)) { diff --git a/packages/react-native-reanimated/src/shareables.ts b/packages/react-native-reanimated/src/shareables.ts index 0bce648a35a..ec4bdea2b33 100644 --- a/packages/react-native-reanimated/src/shareables.ts +++ b/packages/react-native-reanimated/src/shareables.ts @@ -303,7 +303,8 @@ Offending code was: \`${getWorkletCode(value)}\``); } const clone = WorkletsModule.makeShareableClone( clonedProps, - shouldPersistRemote, + // retain all worklets + true, value ) as ShareableRef; shareableMappingCache.set(value, clone);