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

Could I turn off the tracking component from a specific library? #114

Open
zcmgyu opened this issue May 3, 2020 · 12 comments
Open

Could I turn off the tracking component from a specific library? #114

zcmgyu opened this issue May 3, 2020 · 12 comments
Labels
enhancement New feature or request workaround available A workaround is available in the issue's comments

Comments

@zcmgyu
Copy link

zcmgyu commented May 3, 2020

Could I turn off the tracking component from a specific library?

After upgrade to Ant Design v4, the Table component's specification has changed as well. So I need to turn whyDidYouRender warning off for this component.

I know that we could turn off whyDidYouRender by using whyDidYouRender = false on a specific component. How could we do the same for a specific component from the library like Ant Design?

I don't want to set exclude in the configuration of whyDidYouRender, because of the re-rendered component name is quite common (for instance, Body, undefined)

Thank you in advance.

@vzaidman
Copy link
Collaborator

vzaidman commented May 3, 2020

Hey!
Do you track all pure components right now and that's the reason you see all these warnings?

@vzaidman vzaidman added the question Further information is requested label May 3, 2020
@zcmgyu
Copy link
Author

zcmgyu commented May 3, 2020

@vzaidman Yeah, this my current configuration.

    trackAllPureComponents: true,
    trackHooks: true,

@vzaidman
Copy link
Collaborator

vzaidman commented May 3, 2020

I can't think of any better way than something like (i didn't try it):

if (process.env.NODE_ENV === 'development') {
  const antComponents = require('antd');
  Object.values(antComponents).forEach(c => c.whyDidYouRender = false);

  const whyDidYouRender = require('@welldone-software/why-did-you-render');
  whyDidYouRender(React, {
    trackAllPureComponents: true,
  });
}

@zcmgyu
Copy link
Author

zcmgyu commented May 3, 2020

Hey @vzaidman, thank for your suggestion.

I've added a condition before set whyDidYouRender to false.

  const antComponents = require('antd');
  Object.values(antComponents).forEach(c => {
    if (typeof c === 'function') {
      c.whyDidYouRender = false
    }
  });

But it still doesn't work. I think it still couldn't turn off warning of the component inside Table component.

Screen Shot 2020-05-04 at 1 44 17

@vzaidman
Copy link
Collaborator

vzaidman commented May 3, 2020

open the arrow from the log, right click the "body" component and see where it comes from.

@zcmgyu
Copy link
Author

zcmgyu commented May 3, 2020

@vzaidman
It came from rc-table/es/Body/index.js - a dependency used in Table component of Ant Design.

@vzaidman
Copy link
Collaborator

vzaidman commented May 3, 2020

got to import it and set whyDidYouRender = false on it.

I will think of a better way meanwhile.

@vzaidman vzaidman added enhancement New feature or request workaround available A workaround is available in the issue's comments and removed question Further information is requested labels May 3, 2020
@zcmgyu
Copy link
Author

zcmgyu commented May 3, 2020

@vzaidman I don't know why but it still doesn't work although I've imported directly and set whyDidYouRender = false for each component already.

https://codesandbox.io/s/turn-off-specific-component-in-whydidyourender-wdm64?file=/wdyr.js

@vzaidman
Copy link
Collaborator

vzaidman commented May 3, 2020

damn, sadly MemoTableContent is not exported. (that one that is logged as "undefined")

@vzaidman
Copy link
Collaborator

vzaidman commented May 3, 2020

i need to research it a little more.

@0xdevalias
Copy link

Would it be possible to use the exclude option with a RegEx to workaround it in the meantime?

You can include or exclude tracking of components by their displayName using the include and exclude options.

For example, the following code is used to track all redundant re-renders that are caused by older React-Redux:

whyDidYouRender(React, { include: [/^ConnectFunction/] });

Notice: exclude takes priority over both include and manually set whyDidYouRender =

@vzaidman
Copy link
Collaborator

Yes it would, but just in case the library exports components with unique enough names.
In general I see that the new JSX transformation can solve this issue in the future. I hope I'll have time to get to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request workaround available A workaround is available in the issue's comments
Projects
None yet
Development

No branches or pull requests

3 participants