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

[Tooltip] Convert to function component #15291

Merged
merged 12 commits into from
Apr 15, 2019

Conversation

joshwooding
Copy link
Member

@joshwooding joshwooding commented Apr 9, 2019

Closes #15283 (edit @eps1lon)

Breaking Change

The child of the Tooltip needs to be able to hold a ref:

class Component extends React.Component {
  render() {
    return <div />
  }
}
-const MyComponent = props => <div {...props} />
+const MyComponent = React.forwardRef((props, ref) => <div ref={ref} {...props} />);
<Tooltip><Component /></Tooltip>
<Tooltip><MyComponent /></Tooltip>
<Tooltip><div /></Tooltip>

@joshwooding joshwooding added new feature New feature or request component: tooltip This is the name of the generic UI component, not the React module! labels Apr 9, 2019
@mui-pr-bot
Copy link

mui-pr-bot commented Apr 9, 2019

@material-ui/core: parsed: -0.27% 😍, gzip: -0.09% 😍
@material-ui/lab: parsed: -1.15% 😍, gzip: -0.45% 😍

Details of bundle changes.

Comparing: 701a61d...f62e92a

bundle parsed diff gzip diff prev parsed current parsed prev gzip current gzip
@material-ui/core -0.27% -0.09% 318,721 317,854 85,484 85,410
@material-ui/core/Paper 0.00% -0.02% 67,276 67,276 19,958 19,954
@material-ui/core/Paper.esm -0.00% -0.02% 60,641 60,639 18,890 18,886
@material-ui/core/Popper 0.00% -0.02% 34,906 34,906 11,868 11,866
@material-ui/core/styles/createMuiTheme 0.00% +0.07% 🔺 15,898 15,898 5,769 5,773
@material-ui/core/useMediaQuery 0.00% 0.00% 2,463 2,463 1,041 1,041
@material-ui/lab -1.15% -0.45% 146,194 144,519 43,730 43,532
@material-ui/styles 0.00% 0.00% 50,831 50,831 15,013 15,013
@material-ui/system 0.00% +0.10% 🔺 11,765 11,765 3,922 3,926
Button -0.00% +0.02% 🔺 88,560 88,558 26,490 26,496
Modal 0.00% 0.00% 82,538 82,539 24,835 24,835
colorManipulator 0.00% 0.00% 3,904 3,904 1,543 1,543
docs.landing 0.00% 0.00% 50,908 50,908 11,210 11,210
docs.main -0.12% -0.02% 650,169 649,371 202,381 202,331
packages/material-ui/build/umd/material-ui.production.min.js -0.30% -0.09% 295,409 294,535 82,680 82,607

Generated by 🚫 dangerJS against f62e92a

@joshwooding joshwooding force-pushed the tooltip-function-component branch 2 times, most recently from e554936 to c4f745a Compare April 9, 2019 22:14
@joshwooding joshwooding mentioned this pull request Apr 9, 2019
29 tasks
@joshwooding joshwooding requested a review from eps1lon April 9, 2019 22:58
@joshwooding joshwooding marked this pull request as ready for review April 10, 2019 00:09
packages/material-ui/src/Tooltip/Tooltip.js Outdated Show resolved Hide resolved
packages/material-ui/src/Tooltip/Tooltip.js Outdated Show resolved Hide resolved
packages/material-ui/src/Tooltip/Tooltip.js Outdated Show resolved Hide resolved
packages/material-ui/src/Tooltip/Tooltip.js Outdated Show resolved Hide resolved
packages/material-ui/src/Tooltip/Tooltip.test.js Outdated Show resolved Hide resolved
packages/material-ui/src/Tooltip/Tooltip.test.js Outdated Show resolved Hide resolved
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

We need to rebase for #15304 :)

packages/material-ui/src/Tooltip/Tooltip.js Outdated Show resolved Hide resolved
@oliviertassinari oliviertassinari added the PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI label Apr 12, 2019
@joshwooding joshwooding removed the PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI label Apr 12, 2019
@joshwooding
Copy link
Member Author

Whoops, SpeedDial is broken.

@eps1lon eps1lon self-assigned this Apr 13, 2019
Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

About the order: We shouldn't order by the type of hook. We should order by concern. The goal should be to be as close as possible to https://twitter.com/prchdk/status/1056960391543062528

const handleRef = useForkRef(children.ref, handleOwnRef);

React.useEffect(() => {
if (childNode) {
Copy link
Member

Choose a reason for hiding this comment

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

We are mixing the if (x) { warning(message) } and warning(y, message) pattern. We should only use one strategy. React is introducing new helpers: facebook/react#15170. We can start to migrate to if(x) { warn(message) } if you prefer or stick to the existing convention.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did want to refactor this but it's my kryptonite ... Long boolean expressions 😅

packages/material-ui/src/Tooltip/Tooltip.js Show resolved Hide resolved
@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 14, 2019

How do you guys want to handle the warning thing in the future, there is a wide range of different options. Maybe?

import React from 'react';

/* to package into it's own module */
const dedup = {};
function warning(message, type) {
  if (!dedup[type]) {
    React.warn(messasge);
    dedup[type] = 1;
  }
}

function MyComponent() {
  if (foo === bar) {
    warning('No, you should not bazzz', 'MyComponent');.
  }
}

plus https://github.com/oliviertassinari/babel-plugin-transform-dev-warning

@eps1lon
Copy link
Member

eps1lon commented Apr 14, 2019

Don't cache warnings unless it's actually an issue. Or rather don't cache anything unless you need to because caching is hard. Not sure what the issue is all of the sudden?

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 14, 2019

Warning spamming is a true issue. I'm proposing to use the same strategy that React uses for it's warning: raise them once. "Did you fix the warning? Great! Reload the page".

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 14, 2019

Another option:

import React from 'react';

/* to package into it's own module */
const dedup = new WeakMap();
function warning(condition, message) {
  const { current } = React.useRef({});
  if (!condition && !dedup.has(current)) {
    React.warn(messasge);
    dedup.set(current);
  }
}

function MyComponent() {
  warning(foo !== bar, 'No, you should not bazzz');.
}

@eps1lon
Copy link
Member

eps1lon commented Apr 14, 2019

Warning spamming is a true issue.

Sure. Could you showcase this? According to your own standards it shouldn't since nobody reported it.

@oliviertassinari
Copy link
Member

oliviertassinari commented Apr 14, 2019

According to your own standards, it shouldn't since nobody reported it.

Just to clarify, my standard is all about experimenting and gaining knowledge 🔬. The bench is skewed here. We are already deduplicating the Tooltip warning in a did mount. We can't conclude.

Could you showcase this?

We can look at our past experimentations and the solution others are using (React), if often reveal a lot of interesting things (why I benchmark as much as I can).

@oliviertassinari
Copy link
Member

The stack trace is present: https://github.com/facebook/react/pull/15170/files#diff-f49694827a75d846a7c34f03316ecaf1R177. So it's only a dead code elimination & deduplication problem.

@eps1lon
Copy link
Member

eps1lon commented Apr 14, 2019

Let's continue this in the actual issue. This isn't tied to "[Tooltip] Convert to function component".

);
}
warning(
!(
Copy link
Member

Choose a reason for hiding this comment

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

💯 That's is, maybe we can write our own warning method that uses warn internally but reverse the condition logic. It's more intuitive. Maybe we don't need a different if branch. What we need is a direct condition logic, not a reversed one.

@oliviertassinari oliviertassinari merged commit 8e5d48b into mui:next Apr 15, 2019
@oliviertassinari
Copy link
Member

Well done! Let's mature the warning reflection before committing to any change.

@joshwooding joshwooding deleted the tooltip-function-component branch April 15, 2019 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: tooltip This is the name of the generic UI component, not the React module! new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dialog, lazy and Suspense
4 participants