Skip to content

Commit b49c0de

Browse files
authored
Fix configuring unconfigurable properties (#6098)
## Summary Fixes #6066. When implementing more meaningful way of shareable freezing I overlooked the case when some properties would be unconfigurable. This PR fixes this. ## Test plan New button in `ShareableFreezing` example checks that it doesn't throw anymore.
1 parent 7697afd commit b49c0de

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

apps/common-app/src/examples/ShareableFreezingExample.tsx

+23-4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ export default function FreezingShareables() {
6868
onPress={tryModifyConvertedInt32Array}
6969
/>
7070
</View>
71+
<View style={styles.textAndButton}>
72+
<Text style={styles.text}>🤫</Text>
73+
<Button
74+
title="Modify unconfigurable object"
75+
onPress={tryModifyUnconfigurableObject}
76+
/>
77+
</View>
7178
</View>
7279
);
7380
}
@@ -92,7 +99,7 @@ function tryModifyConvertedHostObject() {
9299
return;
93100
}
94101
makeShareableCloneRecursive(obj);
95-
// @ts-expect-error
102+
// @ts-expect-error It's ok
96103
obj.prop = 2; // shouldn't warn because it's not frozen
97104
}
98105

@@ -107,21 +114,22 @@ function tryModifyConvertedPlainObject() {
107114
function tryModifyConvertedRegExpLiteral() {
108115
const obj = /a/;
109116
makeShareableCloneRecursive(obj);
110-
// @ts-expect-error
117+
// @ts-expect-error It's ok
111118
obj.prop = 2; // shouldn't warn because it's not frozen
112119
}
113120

114121
function tryModifyConvertedRegExpInstance() {
122+
// eslint-disable-next-line prefer-regex-literals
115123
const obj = new RegExp('a');
116124
makeShareableCloneRecursive(obj);
117-
// @ts-expect-error
125+
// @ts-expect-error It's ok
118126
obj.prop = 2; // shouldn't warn because it's not frozen
119127
}
120128

121129
function tryModifyConvertedArrayBuffer() {
122130
const obj = new ArrayBuffer(8);
123131
makeShareableCloneRecursive(obj);
124-
// @ts-expect-error
132+
// @ts-expect-error It's ok
125133
obj.prop = 2; // shouldn't warn because it's not frozen
126134
}
127135

@@ -131,6 +139,17 @@ function tryModifyConvertedInt32Array() {
131139
obj[1] = 2; // shouldn't warn because it's not frozen
132140
}
133141

142+
function tryModifyUnconfigurableObject() {
143+
const obj = {};
144+
Object.defineProperty(obj, 'prop', {
145+
value: 1,
146+
writable: false,
147+
enumerable: true,
148+
configurable: false,
149+
});
150+
makeShareableCloneRecursive(obj);
151+
}
152+
134153
const styles = StyleSheet.create({
135154
container: {
136155
flex: 1,

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

+4
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ function freezeObjectIfDev<T extends object>(value: T) {
318318
return;
319319
}
320320
Object.entries(value).forEach(([key, element]) => {
321+
const descriptor = Object.getOwnPropertyDescriptor(value, key)!;
322+
if (!descriptor.configurable) {
323+
return;
324+
}
321325
Object.defineProperty(value, key, {
322326
get() {
323327
return element;

0 commit comments

Comments
 (0)