From c604f10d4a89cac673971fce4a68f09c02d3cf7b Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Tue, 3 Oct 2023 16:04:51 -0700 Subject: [PATCH] Improve Fabric debug logging (#39778) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39778 Used with `IS_DEVELOPMENT_ENVIRONMENT` and `ReactFeatureFlags.enableFabricLogs`. Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D49864983 fbshipit-source-id: bf912abd765ff74e9ed8b94571293f79458feca2 --- .../facebook/react/fabric/StateWrapperImpl.java | 14 ++++++++++++++ .../react/fabric/mounting/MountItemDispatcher.java | 10 ++++------ .../mountitems/IntBufferBatchMountItem.java | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/StateWrapperImpl.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/StateWrapperImpl.java index bccf059340..c1e797f85d 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/StateWrapperImpl.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/StateWrapperImpl.java @@ -83,4 +83,18 @@ public class StateWrapperImpl implements StateWrapper { mHybridData.resetNative(); } } + + @Override + public String toString() { + if (mDestroyed) { + return ""; + } + + ReadableNativeMap map = getStateDataImpl(); + if (map == null) { + return ""; + } + + return map.toString(); + } } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.java index 8b8ae700fa..df2af72411 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.java @@ -247,12 +247,13 @@ public class MountItemDispatcher { // If there are MountItems to dispatch, we make sure all the "pre mount items" are executed // first Collection preMountItemsToDispatch = getAndResetPreMountItems(); - if (preMountItemsToDispatch != null) { Systrace.beginSection( Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManager::mountViews preMountItems"); - for (MountItem preMountItem : preMountItemsToDispatch) { + if (ENABLE_FABRIC_LOGS) { + printMountItem(preMountItem, "dispatchMountItems: Executing preMountItem"); + } executeOrEnqueue(preMountItem); } @@ -330,11 +331,8 @@ public class MountItemDispatcher { } if (ENABLE_FABRIC_LOGS) { - printMountItem( - preMountItemToDispatch, - "dispatchPreMountItems: Dispatching PreAllocateViewMountItem"); + printMountItem(preMountItemToDispatch, "dispatchPreMountItems"); } - executeOrEnqueue(preMountItemToDispatch); } } finally { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/IntBufferBatchMountItem.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/IntBufferBatchMountItem.java index 05b5a5a2f4..ad286fcdd1 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/IntBufferBatchMountItem.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/IntBufferBatchMountItem.java @@ -242,7 +242,7 @@ final class IntBufferBatchMountItem implements BatchMountItem { StateWrapper state = castToState(mObjBuffer[j++]); String stateString = IS_DEVELOPMENT_ENVIRONMENT - ? (state != null ? state.getStateData().toString() : "") + ? (state != null ? state.toString() : "") : ""; s.append(String.format("UPDATE STATE [%d]: %s\n", mIntBuffer[i++], stateString)); } else if (type == INSTRUCTION_UPDATE_LAYOUT) {