Skip to content

Commit b50a7b3

Browse files
committed
fix: symbol not cloned
1 parent de6235f commit b50a7b3

4 files changed

Lines changed: 27 additions & 13 deletions

File tree

packages/react-native-reanimated/Common/cpp/worklets/SharedItems/Shareables.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ jsi::Value makeShareableClone(
5555
std::shared_ptr<Shareable> shareable;
5656
if (value.isObject()) {
5757
auto object = value.asObject(rt);
58-
if (!object.getProperty(rt, "__workletHash").isUndefined()) {
58+
jsi::PropNameID prop = workletCodePropName(rt);
59+
if (object.hasProperty(rt, prop)) {
60+
jsi::Value code = object.getProperty(rt, prop);
61+
shareable = std::make_shared<ShareableString>(code.asString(rt).utf8(rt));
62+
} else if (!object.getProperty(rt, "__workletHash").isUndefined()) {
5963
shareable = std::make_shared<ShareableWorklet>(rt, object);
6064
} else if (!object.getProperty(rt, "__init").isUndefined()) {
6165
shareable = std::make_shared<ShareableHandle>(rt, object);
@@ -276,7 +280,7 @@ jsi::Value ShareableWorklet::toJSValue(jsi::Runtime &rt) {
276280
jsi::Value obj = ShareableObject::toJSValue(rt);
277281
auto initData = obj.asObject(rt).getProperty(rt, "__initData").asObject(rt);
278282
auto code = std::make_shared<const jsi::StringBuffer>(
279-
"(" + initData.getProperty(rt, workletCodePropName(rt)).asString(rt).utf8(rt) + "\n)");
283+
"(" + initData.getProperty(rt, "__reanimated_workletCode").asString(rt).utf8(rt) + "\n)");
280284

281285
auto sourceURL = initData.getProperty(rt, "location").asString(rt).utf8(rt);
282286
// The code has to be evaluated in the context of the worklet runtime.

packages/react-native-reanimated/plugin/index.js

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-native-reanimated/plugin/src/workletFactory.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,14 @@ export function makeWorkletFactory(
153153
true
154154
);
155155

156-
const initDataObjectExpression = objectExpression([workletCodeProperty]);
156+
const reanimatedWorkletCodeProperty = objectProperty(
157+
identifier('__reanimated_workletCodeWrapper'),
158+
objectExpression([workletCodeProperty])
159+
);
160+
161+
const initDataObjectExpression = objectExpression([
162+
reanimatedWorkletCodeProperty,
163+
]);
157164

158165
// When testing with jest I noticed that environment variables are set later
159166
// than some functions are evaluated. E.g. this cannot be above this function

packages/react-native-reanimated/src/shareables.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,15 @@ Offending code was: \`${getWorkletCode(value)}\``);
201201
if (key === '__initData' && toAdapt.__initData !== undefined) {
202202
continue;
203203
}
204-
toAdapt[key] = makeShareableCloneRecursive(
205-
element,
206-
shouldPersistRemote,
207-
depth + 1
208-
);
209-
}
210-
211-
for (const key of Object.getOwnPropertySymbols(value)) {
212-
const element = value[key];
204+
if (key === '__reanimated_workletCodeWrapper') {
205+
toAdapt.__reanimated_workletCode =
206+
NativeReanimatedModule.makeShareableClone(
207+
element,
208+
shouldPersistRemote,
209+
value
210+
);
211+
continue;
212+
}
213213
toAdapt[key] = makeShareableCloneRecursive(
214214
element,
215215
shouldPersistRemote,

0 commit comments

Comments
 (0)