From 0852e82b741a6187f1ee178156ec69590f646579 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Sat, 14 Sep 2024 12:14:37 -0700 Subject: [PATCH] Animated: Restore `AnimatedNode.prototype.toJSON` Summary: Looks like this is still necessary because we still run into this error when using the Components tab when using React DevTools: > TypeError: cyclical structure in JSON object This effectively reverts https://github.com/facebook/react-native/pull/46382. Changelog: [General][Changed] - AnimatedNode (and its subclasses) once again implement `toJSON()`. Differential Revision: D62690380 --- .../Libraries/Animated/__tests__/Animated-test.js | 4 ++++ .../react-native/Libraries/Animated/nodes/AnimatedNode.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/packages/react-native/Libraries/Animated/__tests__/Animated-test.js b/packages/react-native/Libraries/Animated/__tests__/Animated-test.js index 354bd521630871..53f2af95717d10 100644 --- a/packages/react-native/Libraries/Animated/__tests__/Animated-test.js +++ b/packages/react-native/Libraries/Animated/__tests__/Animated-test.js @@ -162,6 +162,10 @@ describe('Animated tests', () => { expect(anim.__getValue()).toBe(15); }); + it('convert to JSON', () => { + expect(JSON.stringify(new Animated.Value(10))).toBe('10'); + }); + it('bypasses `setNativeProps` in test environments', async () => { const opacity = new Animated.Value(0); diff --git a/packages/react-native/Libraries/Animated/nodes/AnimatedNode.js b/packages/react-native/Libraries/Animated/nodes/AnimatedNode.js index 1835d43ec67df4..2859c068b6248e 100644 --- a/packages/react-native/Libraries/Animated/nodes/AnimatedNode.js +++ b/packages/react-native/Libraries/Animated/nodes/AnimatedNode.js @@ -189,4 +189,8 @@ export default class AnimatedNode { __setPlatformConfig(platformConfig: ?PlatformConfig) { this._platformConfig = platformConfig; } + + toJSON(): any { + return this.__getValue(); + } }