Refactor: split inspectElementRaw
Dan Abramov committed
Apr 8, 2019 at 16:20 UTC
b176cd44144393439817b0026bd13302139e5550
1 file changed
+18
-7
src/backend/renderer.js
+18
-7
@@ -1410,7 +1410,7 @@ export function attach(
1410
}
1411
}
1412
1413
- function inspectElement(id: number): InspectedElement | null {
1413
+ function inspectElementRaw(id: number): InspectedElement | null {
1414
let fiber = idToFiberMap.get(id);
1415
1416
if (fiber == null) {
@@ -1491,7 +1491,7 @@ export function attach(
1491
if (context !== null) {
1492
// To simplify hydration and display logic for context, wrap in a value object.
1493
// Otherwise simple values (e.g. strings, booleans) become harder to handle.
1494
- context = cleanForBridge({ value: context });
1494
+ context = { value: context };
1495
}
1496
1497
let owners = null;
@@ -1534,12 +1534,10 @@ export function attach(
1534
// TODO Review sanitization approach for the below inspectable values.
1535
context,
1536
hooks: usesHooks
1537
- ? cleanForBridge(
1538
- inspectHooksOfFiber(fiber, (renderer.currentDispatcherRef: any))
1539
- )
1537
+ ? inspectHooksOfFiber(fiber, (renderer.currentDispatcherRef: any))
1538
: null,
1541
- props: cleanForBridge(memoizedProps),
1542
- state: usesHooks ? null : cleanForBridge(memoizedState),
1539
+ props: memoizedProps,
1540
+ state: usesHooks ? null : memoizedState,
1541
1542
// List of owners
1543
owners,
@@ -1549,6 +1547,19 @@ export function attach(
1547
};
1548
}
1549
1550
+ function inspectElement(id: number): InspectedElement | null {
1551
+ let result = inspectElementRaw(id);
1552
+ if (result === null) {
1553
+ return null;
1554
+ }
1555
+ // TODO Review sanitization approach for the below inspectable values.
1556
+ result.context = cleanForBridge(result.context);
1557
+ result.hooks = cleanForBridge(result.hooks);
1558
+ result.props = cleanForBridge(result.props);
1559
+ result.state = cleanForBridge(result.state);
1560
+ return result;
1561
+ }
1562
+
1563
function setInHook(
1564
id: number,
1565
index: number,