Skip to content

Commit 4e0b923

Browse files
mamanmeta-codesync[bot]
authored andcommitted
Fix prototype check in AnimatedObject.js (#54820)
Summary: `isPlainObject` function defined in `AnimatedObject.js` doesn't handle `Object.create(null)` correctly. this will throws when encountering objects with null prototype: ```js Object.getPrototypeOf(Object.create(null)).isPrototypeOf(Object) // TypeError: Cannot read properties of null (reading 'isPrototypeOf') ``` This breaks compatibility with libraries that use `Object.create(null)` for creating clean dictionary objects. ## Changelog: [GENERAL] [FIXED] - Handle `Object.create(null)` correctly in AnimatedObject.js' `isPlainObject` function Pull Request resolved: #54820 Test Plan: ``` import { isPlainObject } from 'react-native/Libraries/Animated/nodes/AnimatedObject'; // Before: throws TypeError // After: returns true isPlainObject(Object.create(null)); // Existing behavior unchanged isPlainObject({}); // true isPlainObject([]); // false isPlainObject(null); // false isPlainObject(new Date()); // false ``` Reviewed By: zeyap Differential Revision: D88754908 Pulled By: javache fbshipit-source-id: ea48908493b72da67699e48b35a6dc7e6714006d
1 parent f9346fb commit 4e0b923

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

packages/react-native/Libraries/Animated/nodes/AnimatedObject.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@ export function isPlainObject(
2424
/* $FlowFixMe[incompatible-type-guard] - Flow does not know that the prototype
2525
and ReactElement checks preserve the type refinement of `value`. */
2626
): value is $ReadOnly<{[string]: mixed}> {
27+
const proto =
28+
value !== null && typeof value === 'object'
29+
? Object.getPrototypeOf(value)
30+
: undefined;
31+
if (proto === undefined) {
32+
// $FlowFixMe[incompatible-type-guard]
33+
return false;
34+
}
2735
return (
2836
// $FlowFixMe[incompatible-type-guard]
29-
value !== null &&
30-
typeof value === 'object' &&
31-
Object.getPrototypeOf(value).isPrototypeOf(Object) &&
32-
!isValidElement(value)
37+
(proto == null || proto.isPrototypeOf(Object)) && !isValidElement(value)
3338
);
3439
}
3540

0 commit comments

Comments
 (0)