-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[Tooltip] Convert to function component #15291
Conversation
@material-ui/core: parsed: -0.27% 😍, gzip: -0.09% 😍 Details of bundle changes.Comparing: 701a61d...f62e92a
|
e554936
to
c4f745a
Compare
87862a6
to
17762f2
Compare
There was a problem hiding this 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 :)
8459d60
to
bd66482
Compare
Whoops, SpeedDial is broken. |
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😅
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 |
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? |
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". |
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');.
} |
Sure. Could you showcase this? 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.
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). |
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. |
Let's continue this in the actual issue. This isn't tied to "[Tooltip] Convert to function component". |
); | ||
} | ||
warning( | ||
!( |
There was a problem hiding this comment.
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.
Well done! Let's mature the warning reflection before committing to any change. |
Closes #15283 (edit @eps1lon)
Breaking Change
The child of the
Tooltip
needs to be able to hold a ref: