From 3a87e14cbb93794a82af2ef3ff91b8920f6ce199 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Fri, 20 Oct 2023 10:44:55 -0400 Subject: [PATCH] Support Replay RDT fork --- .../src/backend/renderer.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/react-devtools-shared/src/backend/renderer.js b/packages/react-devtools-shared/src/backend/renderer.js index 9219581008836..cb25f213576ab 100644 --- a/packages/react-devtools-shared/src/backend/renderer.js +++ b/packages/react-devtools-shared/src/backend/renderer.js @@ -3698,6 +3698,29 @@ export function attach( // This will enable us to send patches without re-inspecting if hydrated paths are requested. // (Reducing how often we shallow-render is a better DX for function components that use hooks.) const cleanedInspectedElement = {...mostRecentlyInspectedElement}; + + // [FE-1885] Note that the internal.registerPlainObject API is only available for newer Replay Chromium builds. + const getObjectId = __RECORD_REPLAY_ARGUMENTS__.internal + ? __RECORD_REPLAY_ARGUMENTS__.internal.registerPlainObject + : () => null; + + // [FE-1885] React DevTools uses a bespoke format for inspecting props/state/hooks data; + // Replay's React DevTools fork uses the Replay Inspector (and the Replay object preview format) + // For the time being, the backend needs to support both, + // but eventually we can remove a lot of this info from the inspected element payload. + cleanedInspectedElement.contextObjectId = cleanedInspectedElement.context + ? getObjectId(cleanedInspectedElement.context) + : null; + cleanedInspectedElement.hooksObjectId = cleanedInspectedElement.hooks + ? getObjectId(cleanedInspectedElement.hooks) + : null; + cleanedInspectedElement.propsObjectId = cleanedInspectedElement.props + ? getObjectId(cleanedInspectedElement.props) + : null; + cleanedInspectedElement.stateObjectId = cleanedInspectedElement.state + ? getObjectId(cleanedInspectedElement.state) + : null; + // $FlowFixMe[prop-missing] found when upgrading Flow cleanedInspectedElement.context = cleanForBridge( cleanedInspectedElement.context,