From 83eb95e72afdf1f112d065e9898483f92d4ee21a Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Sat, 14 Sep 2024 22:21:27 -0700 Subject: [PATCH] Animated: Restore `AnimatedNode.prototype.toJSON` (#46498) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46498 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()`. Reviewed By: javache Differential Revision: D62690380 fbshipit-source-id: d5b7c1d156b49838abefe48a7d7b61471cc3488a --- .../react-native/Libraries/Animated/nodes/AnimatedNode.js | 8 ++++++++ .../__tests__/__snapshots__/public-api-test.js.snap | 1 + 2 files changed, 9 insertions(+) diff --git a/packages/react-native/Libraries/Animated/nodes/AnimatedNode.js b/packages/react-native/Libraries/Animated/nodes/AnimatedNode.js index 6f4ba16ce20378..ff4c7f5d701922 100644 --- a/packages/react-native/Libraries/Animated/nodes/AnimatedNode.js +++ b/packages/react-native/Libraries/Animated/nodes/AnimatedNode.js @@ -203,4 +203,12 @@ export default class AnimatedNode { __setPlatformConfig(platformConfig: ?PlatformConfig) { this._platformConfig = platformConfig; } + + /** + * NOTE: This is intended to prevent `JSON.stringify` from throwing "cyclic + * structure" errors in React DevTools. Avoid depending on this! + */ + toJSON(): mixed { + return this.__getValue(); + } } diff --git a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap index bdba8d92d83758..15a06a9ac22227 100644 --- a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap +++ b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap @@ -930,6 +930,7 @@ exports[`public API should not change unintentionally Libraries/Animated/nodes/A toJSON(): any; __getPlatformConfig(): ?PlatformConfig; __setPlatformConfig(platformConfig: ?PlatformConfig): void; + toJSON(): mixed; } " `;