Skip to content

fix(react-devtools-shared): useDebugValue with complex types - #18070

Merged
bvaughn merged 5 commits into
react:masterfrom
eps1lon:test/usedebugvalue-complex
Mar 17, 2020
Merged

bvaughn merged 5 commits into
react:masterfrom
eps1lon:test/usedebugvalue-complex

Conversation

@eps1lon

@eps1lon eps1lon commented Feb 18, 2020 •

Copy link
Copy Markdown
Collaborator

Closes #17955

Using react-devtools-shell:
master:
Screenshot from 2020-03-09 23-01-20

pr:
Screenshot from 2020-03-09 23-00-55

@codesandbox-ci

codesandbox-ci Bot commented Feb 18, 2020 •

Copy link
Copy Markdown

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:

Sandbox Source
empty-flower-t4wly Configuration
useDebugValue complex types Issue #17955

@sizebot

sizebot commented Feb 18, 2020 •

Copy link
Copy Markdown

No significant bundle size changes to report.

Size changes (experimental)

Generated by 🚫 dangerJS against 32bac9e

@sizebot

sizebot commented Feb 18, 2020 •

Copy link
Copy Markdown

No significant bundle size changes to report.

Size changes (stable)

Generated by 🚫 dangerJS against 32bac9e

@bvaughn

bvaughn commented Feb 18, 2020 •

Copy link
Copy Markdown
Contributor

CI is failing on lint btw. Run yarn prettier-all.

Is there a question (for me) on this PR at the moment or...? I'm not sure.

@eps1lon

eps1lon commented Feb 19, 2020

Copy link
Copy Markdown
Collaborator Author

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.

@eps1lon
eps1lon force-pushed the test/usedebugvalue-complex branch from a691661 to a9444d1 Compare February 19, 2020 08:41
@eps1lon eps1lon changed the title test(react-devtools-shared): useDebugValue with complex types fix(react-devtools-shared): useDebugValue with complex types Feb 19, 2020
Comment thread scripts/jest/config.build-devtools.js Resolved
);

it('shows the complex value of custom hooks with sub-hooks', () => {
// props from `InspectedElementContext display complex values of useDebugValue: DisplayedComplexValue 1` snapshot

ghost Feb 19, 2020

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@eps1lon
eps1lon marked this pull request as ready for review February 19, 2020 08:46
@eps1lon
eps1lon requested a review from bvaughn February 19, 2020 08:46
@bvaughn

ghost commented Feb 19, 2020

Copy link
Copy Markdown
Contributor

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.

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.

@eps1lon

ghost commented Feb 19, 2020

Copy link
Copy Markdown
Collaborator Author

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.

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.

Comment thread scripts/jest/config.build-devtools.js Resolved
@eps1lon
eps1lon force-pushed the test/usedebugvalue-complex branch from a9444d1 to 13a9992 Compare March 9, 2020 21:56
@eps1lon

ghost commented Mar 9, 2020

Copy link
Copy Markdown
Collaborator Author

@bvaughn

ghost commented Mar 12, 2020 •

Copy link
Copy Markdown
Contributor

I'm confused. Testing useDebugValue with "complex types" like objects already seems to work in master in both the shell:
Screen Shot 2020-03-12 at 9 22 20 AM

...and the actual extension:
Screen Shot 2020-03-12 at 9 23 18 AM

I can also revert the change to HooksTree and newly added test still passes.

I don't think I understand why this PR is necessary. 😕

@eps1lon

ghost commented Mar 12, 2020

Copy link
Copy Markdown
Collaborator Author

I can also revert the change to HooksTree and newly added test still passes.

There are no tests for HooksTree. There never were. The newly added test passes on master as I said because the problem wasn't in the backend but the view.

...and the actual extension:
Screen Shot 2020-03-12 at 9 23 18 AM

That is what we not want. We want it to be displayed without having to expand.

I'm confused. Testing useDebugValue with "complex types" like objects already seems to work in master in both the shell:
Screen Shot 2020-03-12 at 9 22 20 AM

Not sure where this screenshot is taken from.

The original post has a screenshot of before and after. Maybe this explains it better what was changed?

@bvaughn

ghost commented Mar 12, 2020

Copy link
Copy Markdown
Contributor

There are no tests for HooksTree. There never were. The newly added test passes on master as I said because the problem wasn't in the backend but the view.

Right. Maybe I just don't understand the purpose of the newly added test.

That is what we not want. We want it to be displayed without having to expand.

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.

ghost left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .Value class in HooksTree.css needs to have the following style added to it:

white-space: nowrap;

Otherwise complex value strings line wrap and look bad.

className={name !== '' ? styles.Name : styles.NameAnonymous}>
{name || 'Anonymous'}
</span>
<span className={styles.Value} onClick={toggleIsOpen}>

ghost Mar 17, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

ghost Mar 17, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be clear, the label should work like this when toggling:
Custom hook label

ghost Mar 17, 2020

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

ghost Mar 17, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the string preview just stayed visible but the ability to expand the complex value below was gone. I added it back in 32bac9e 😄

@bvaughn
bvaughn merged commit 756e1ea into react:master Mar 17, 2020
@eps1lon
eps1lon deleted the test/usedebugvalue-complex branch March 17, 2020 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug(devtools): complex types ignored sometimes in useDebugValue

4 participants