Reorganize inspected element state vars slightly
Brian Vaughn committed
May 24, 2019 at 09:17 UTC
efc2f82da2ca197f848ce36c5908a5b030fa0dfa
1 file changed
+18
-23
src/backend/renderer.js
+18
-23
@@ -1104,15 +1104,14 @@ export function attach(
1104
}
1105
1106
if (
1107
- mostRecentlyInspectedElement !== null &&
1107
+ mostRecentlyInspectedElementID !== null &&
1108
mostRecentlyInspectedElementID ===
1109
getFiberID(getPrimaryFiber(nextFiber)) &&
1110
hasDataChanged(prevFiber, nextFiber)
1111
) {
1112
// If this Fiber has updated, clear cached inspected data.
1113
// If it is inspected again, it may need to be re-run to obtain updated hooks values.
1114
- mostRecentlyInspectedElement = null;
1115
- mostRecentlyInspectedElementID = null;
1114
+ hasElementUpdatedSinceLastInspected = true;
1115
}
1116
1117
const shouldIncludeInTree = !shouldFilterFiber(nextFiber);
@@ -1904,36 +1903,32 @@ export function attach(
1903
}
1904
1905
let mostRecentlyInspectedElementID: number | null = null;
1907
- let mostRecentlyInspectedElement: InspectedElement | null = null;
1906
+ let hasElementUpdatedSinceLastInspected: boolean = false;
1907
1908
function inspectElement(id: number): InspectedElement | number | null {
1909
// If this element has not been updated since it was last inspected, we don't need to re-run it.
1910
// Instead we can just return the ID to indicate that it has not changed.
1912
- if (mostRecentlyInspectedElementID === id) {
1911
+ if (
1912
+ mostRecentlyInspectedElementID === id &&
1913
+ !hasElementUpdatedSinceLastInspected
1914
+ ) {
1915
return id;
1916
}
1917
1918
mostRecentlyInspectedElementID = id;
1917
- mostRecentlyInspectedElement = inspectElementRaw(id);
1918
- if (mostRecentlyInspectedElement === null) {
1919
+ hasElementUpdatedSinceLastInspected = false;
1920
+
1921
+ const inspectedElement = inspectElementRaw(id);
1922
+ if (inspectedElement === null) {
1923
return null;
1924
}
1921
- mostRecentlyInspectedElement.context = cleanForBridge(
1922
- mostRecentlyInspectedElement.context
1923
- );
1924
- mostRecentlyInspectedElement.events = cleanForBridge(
1925
- mostRecentlyInspectedElement.events
1926
- );
1927
- mostRecentlyInspectedElement.hooks = cleanForBridge(
1928
- mostRecentlyInspectedElement.hooks
1929
- );
1930
- mostRecentlyInspectedElement.props = cleanForBridge(
1931
- mostRecentlyInspectedElement.props
1932
- );
1933
- mostRecentlyInspectedElement.state = cleanForBridge(
1934
- mostRecentlyInspectedElement.state
1935
- );
1936
- return mostRecentlyInspectedElement;
1925
+ inspectedElement.context = cleanForBridge(inspectedElement.context);
1926
+ inspectedElement.events = cleanForBridge(inspectedElement.events);
1927
+ inspectedElement.hooks = cleanForBridge(inspectedElement.hooks);
1928
+ inspectedElement.props = cleanForBridge(inspectedElement.props);
1929
+ inspectedElement.state = cleanForBridge(inspectedElement.state);
1930
+
1931
+ return inspectedElement;
1932
}
1933
1934
function logElementToConsole(id) {