Repository navigation
fix(react-devtools-shared): useDebugValue with complex types - #18070
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 32bac9e:
|
|
CI is failing on lint btw. Run Is there a question (for me) on this PR at the moment or...? I'm not sure. |
It looks like the test is already working as expected. I'm asking how I can test the actual react components that render this as it seems like the patch in the OP is the actual fix. |
a691661 to
a9444d1
Compare
| ); | ||
|
|
||
| it('shows the complex value of custom hooks with sub-hooks', () => { | ||
| // props from `InspectedElementContext display complex values of useDebugValue: DisplayedComplexValue 1` snapshot |
There was a problem hiding this comment.
To make it more explicit I could merge the added test from inspectedElementContext and instead of serializing the tree directly pass inspectedElement.hooks to the tested HooksTree. A core member should decide if this coupling should be explicit or not.
commented
Feb 19, 2020
You can use the shell? You can add any hooks you want into the example app code the shell uses to verify the behavior in a real browser. |
commented
Feb 19, 2020
I'll try that. Though the current test makes me pretty confident that this is fixed. I would test it with the shell (hopefully shareable) if this would help you understand the fix. |
a9444d1 to
13a9992
Compare
commented
Mar 9, 2020
|
commented
Mar 12, 2020
commented
Mar 12, 2020
Right. Maybe I just don't understand the purpose of the newly added test.
Ah, your most recent response clarifies something for me. I think you want the stringified version of the object to display when the hook is collapsed. The current design was intentional, to allow you to expand a complex value. I understand why you'd prefer the collapsed view too. I think a compromise between them might be best. Let me revisit your PR to think about that. |
| className={name !== '' ? styles.Name : styles.NameAnonymous}> | ||
| {name || 'Anonymous'} | ||
| </span> | ||
| <span className={styles.Value} onClick={toggleIsOpen}> |
There was a problem hiding this comment.
This should only be shown if the hook is collapsed. Otherwise, the <KeyValue> component should be rendered as it enables the complex value to be expanded and inspected.
So something like this:
<div className={styles.Hook}>
<div ref={contextMenuTriggerRef} className={styles.NameValueRow}>
<ExpandCollapseToggle isOpen={isOpen} setIsOpen={setIsOpen} />
<span
onClick={toggleIsOpen}
className={name !== '' ? styles.Name : styles.NameAnonymous}>
{name || 'Anonymous'}
</span>
<span className={styles.Value} onClick={toggleIsOpen}>
{isOpen || getMetaValueLabel(value)}
</span>
</div>
<div className={styles.Children} hidden={!isOpen}>
<KeyValue
depth={1}
alphaSort={false}
inspectPath={inspectPath}
name="DebugValue"
path={path.concat(['value'])}
pathRoot="hooks"
value={value}
/>
{subHooksView}
</div>
</div>There was a problem hiding this comment.
Yep that's what I wanted. I guess in this PR the debug value is still displayed on the same line as "CustomObject:" when expanded?
There was a problem hiding this comment.
Yeah, the string preview just stayed visible but the ability to expand the complex value below was gone. I added it back in 32bac9e 😄
Only show meta label when collapsed.



Closes #17955
Using

react-devtools-shell:master:pr: