Hardened the hooks dehydration check
This commit is contained in:
parent
a56fd4c36d
commit
6298fd4248
|
@ -129,7 +129,9 @@ exports[`InspectedElementContext should not dehydrate nested values until explic
|
|||
"id": 0,
|
||||
"isStateEditable": true,
|
||||
"name": "State",
|
||||
"value": {},
|
||||
"value": {
|
||||
"foo": {}
|
||||
},
|
||||
"subHooks": []
|
||||
}
|
||||
],
|
||||
|
@ -153,7 +155,9 @@ exports[`InspectedElementContext should not dehydrate nested values until explic
|
|||
"id": 0,
|
||||
"isStateEditable": true,
|
||||
"name": "State",
|
||||
"value": {},
|
||||
"value": {
|
||||
"foo": {}
|
||||
},
|
||||
"subHooks": []
|
||||
}
|
||||
],
|
||||
|
@ -181,7 +185,9 @@ exports[`InspectedElementContext should not dehydrate nested values until explic
|
|||
"id": 0,
|
||||
"isStateEditable": true,
|
||||
"name": "State",
|
||||
"value": {},
|
||||
"value": {
|
||||
"foo": {}
|
||||
},
|
||||
"subHooks": []
|
||||
}
|
||||
],
|
||||
|
@ -213,7 +219,9 @@ exports[`InspectedElementContext should not dehydrate nested values until explic
|
|||
"id": 0,
|
||||
"isStateEditable": true,
|
||||
"name": "State",
|
||||
"value": {},
|
||||
"value": {
|
||||
"foo": {}
|
||||
},
|
||||
"subHooks": []
|
||||
}
|
||||
],
|
||||
|
|
|
@ -2156,9 +2156,18 @@ export function attach(
|
|||
// Dehydrating the 'subHooks' property makes the HooksTree UI a lot more complicated,
|
||||
// so it's easiest for now if we just don't break on this boundary.
|
||||
// We can always dehydrate a level deeper (in the value object).
|
||||
// TODO (hydration) This check depends on a LEVEL_THRESHOLD of 2 to avoid dehydrating a hook incorrectly.
|
||||
if (isHooksPath && path[path.length - 1] === 'subHooks') {
|
||||
return true;
|
||||
if (isHooksPath) {
|
||||
if (path.length === 1) {
|
||||
// Never dehydrate the hooks object at the top level.
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
path[path.length - 1] === 'subHooks' ||
|
||||
path[path.length - 2] === 'subHooks'
|
||||
) {
|
||||
// Never dehydrate the subHooks array
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
let current =
|
||||
|
|
|
@ -41,9 +41,6 @@ type Dehydrated = {|
|
|||
//
|
||||
// Reducing this threshold will improve the speed of initial component inspection,
|
||||
// but may decrease the responsiveness of expanding objects/arrays to inspect further.
|
||||
//
|
||||
// Note that reducing the threshold to below 2 effectively breaks the inspected hooks interface.
|
||||
// It is only safe to dehydrate hooks within the "value" key, never within the "subHooks" array directly.
|
||||
const LEVEL_THRESHOLD = 2;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue