Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass through the displayName from the mocked component #21429

Closed
wants to merge 4 commits into from

Conversation

quantizor
Copy link

@quantizor quantizor commented Sep 30, 2018

Without this, most tooling will just say "Component" instead of "Text", "View" etc.

Test Plan:

Copied the change over and verified that it worked locally in the styled-components tests.

Release Notes:

[INTERNAL] [BUGFIX] [jest/mockComponent.js] - resume passing the mocked component's displayName through so it will appear in downstream tooling

without this, most tooling will just say "Component" instead of
"Text", "View" etc.
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 30, 2018
@react-native-bot react-native-bot added Missing Changelog This PR appears to be missing a changelog, or they are incorrectly formatted. ✅Release Notes and removed Missing Changelog This PR appears to be missing a changelog, or they are incorrectly formatted. labels Sep 30, 2018
@elicwhite
Copy link
Member

Thanks for contributing! This looks reasonable to me at first glance, but it is hard to tell from your test plan how I can reproduce the issue you are fixing. Can you provide a minimal jest test that reproduces this error if your fix wasn't included? Better yet, can you add a jest test for mockComponent to the codebase to ensure this keeps working in the future?

@quantizor
Copy link
Author

Sure thing, I'll add a test

Copy link

@analysis-bot analysis-bot left a comment

Choose a reason for hiding this comment

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

Code analysis results:

  • eslint found some issues.
  • eslint found some issues.
  • eslint found some issues.

@@ -0,0 +1 @@
export default () => null

Choose a reason for hiding this comment

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

semi: Missing semicolon.

@@ -0,0 +1,13 @@
const mockComponent = require('../mockComponent');
const FakeComponent = require('FakeComponent')

Choose a reason for hiding this comment

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

semi: Missing semicolon.

@@ -0,0 +1,13 @@
const mockComponent = require('../mockComponent');
const FakeComponent = require('FakeComponent')
const TextInput = require('TextInput')

Choose a reason for hiding this comment

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

semi: Missing semicolon.

@quantizor
Copy link
Author

Side question, why was this done? 76eebce#diff-a562e4a7ac9e900c6d2bc644453e9152

The displayName was removed from a bunch of components which is kind of a mistake because it makes them hard to identify in devtools and react warnings.

@elicwhite
Copy link
Member

Our understanding is that React.forwardRef was updated to utilize the displayName of the passed in component so those lines were no longer necessary.

@quantizor
Copy link
Author

quantizor commented Oct 1, 2018 via email

@elicwhite
Copy link
Member

Hmm. I’m not on a computer to test it out but the docs for forwardRef at least seem to indicate that it has some special behavior for displayName. https://reactjs.org/docs/forwarding-refs.html

@quantizor quantizor requested a review from hramos as a code owner October 1, 2018 04:37
@quantizor
Copy link
Author

@TheSavior The behavior is if you set a displayName on the ForwardRef wrapper it'll take it into account in devtools I believe. forwardRef doesn't know what component it's rendering until render is called so there's no way to acquire the underlying component's displayName statically.

@pull-bot
Copy link

pull-bot commented Oct 1, 2018

Warnings
⚠️

🔒 package.json - Changes were made to package.json. This will require a manual import by a Facebook employee.

⚠️

❗ Big PR - This PR is extremely unlikely to get reviewed because it touches 1411 lines.

Generated by 🚫 dangerJS

@elicwhite
Copy link
Member

View and Text both use forwardRef and don't explicitly set a displayName. Using React DevTools with our current production app, I see the proper name in forwardRef:

screen shot 2018-10-01 at 12 57 39 pm

Is this inconsistent with what you are seeing?

@quantizor
Copy link
Author

@TheSavior I think devtools is kind of a special case since it literally executes the render function of the forwardRef to obtain the underlying component and then shows the displayName as a derivation of that. Enzyme and other tooling likely will not go to that length since the fact that forwardRef has a function called "render" is an implementation detail and not part of the public API.

I actually wrote the change that was recently merged into react core to start directly honoring displayName set on forwardRef and this is an extension of that effort.

@elicwhite
Copy link
Member

Okay, so to make sure I understand, is your request that we add back the annotations to all the components that use forwardRef so that tooling like enzyme is able to read those names?

It seems like that will be hard to enforce everywhere forwardRef is used and is a workaround that adds runtime code to help make build and test time tooling easier. Am I misunderstanding something?

@quantizor
Copy link
Author

quantizor commented Oct 2, 2018 via email

@quantizor
Copy link
Author

quantizor commented Oct 2, 2018 via email

@cpojer
Copy link
Contributor

cpojer commented Jan 22, 2019

I'm gonna close this as there hasn't been progress in many months and the conclusion seems to be that this isn't what we want to do.

@cpojer cpojer closed this Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants