Skip to content

[Tabs] Fix ":first-child is potentially unsafe" error#28890

Merged
hbjORbj merged 6 commits intomui:masterfrom
hbjORbj:tabs-console-error
Oct 8, 2021
Merged

[Tabs] Fix ":first-child is potentially unsafe" error#28890
hbjORbj merged 6 commits intomui:masterfrom
hbjORbj:tabs-console-error

Conversation

@hbjORbj
Copy link
Contributor

@hbjORbj hbjORbj commented Oct 7, 2021

Closes #24894

Problem:

The pseudo class ":first-child" is potentially unsafe when doing server-side rendering. Try changing it to ":first-of-type"

Solution:

@hbjORbj hbjORbj added the scope: tabs Changes related to the tabs. label Oct 7, 2021
@hbjORbj hbjORbj changed the title [Tabs] Remove ":first-child is potentially unsafe" error [Tabs] Fix ":first-child is potentially unsafe" error Oct 7, 2021
@mui-pr-bot
Copy link

mui-pr-bot commented Oct 7, 2021

Details of bundle changes

Generated by 🚫 dangerJS against 7f39f87

@hbjORbj hbjORbj force-pushed the tabs-console-error branch from a543b1e to 4699d15 Compare October 7, 2021 12:02
const label = typeof labelProp === 'string' && !!icon ? <span>{labelProp}</span> : labelProp;
const label =
typeof labelProp === 'string' && !!icon ? (
<span className="MuiTab-iconLabel">{labelProp}</span>
Copy link
Member

Choose a reason for hiding this comment

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

Almost there :)
Just don't hardcode the class but add it to tabClasses.ts and reference it from there.

Copy link
Contributor Author

@hbjORbj hbjORbj Oct 7, 2021

Choose a reason for hiding this comment

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

How's this instead? I think this is more simple.

Copy link
Member

Choose a reason for hiding this comment

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

I think I've only ever seen labels that accompany inputs. I don't think it's valid to have it standalone (see https://www.w3.org/TR/WCAG20-TECHS/H44.html). I'd go with a class instead, as I originally suggested. Best to create a new slot in useUtilityClasses, I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, thanks. I made a change and updated the code sandbox.

@hbjORbj hbjORbj force-pushed the tabs-console-error branch from 53690bb to d949825 Compare October 7, 2021 12:51
@hbjORbj hbjORbj force-pushed the tabs-console-error branch from 1c48b0b to 729aab3 Compare October 7, 2021 15:28
[P in K]?: T[P] | undefined;
} &
Omit<T, K>;
} & Omit<T, K>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

From running prettier.

@hbjORbj hbjORbj force-pushed the tabs-console-error branch from b2a9940 to 2eefe59 Compare October 7, 2021 16:06
@hbjORbj hbjORbj force-pushed the tabs-console-error branch from cf704d5 to 07337d9 Compare October 7, 2021 17:58
Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

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

👍

@hbjORbj hbjORbj merged commit 5e6086a into mui:master Oct 8, 2021
@mnajdova
Copy link
Member

mnajdova commented Oct 8, 2021

A bit late to the party, but I was chatting now with Mateusz and he point me to this special flag that is used to disable these warnings - https://github.com/emotion-js/emotion/blob/main/packages/react/__tests__/warnings.js#L87 I wish I knew this earlier.

If we replace each of our selectors to contain this comment, we would get rid of the warnings without doing any change in the styles themself. I would prefer this, mainly because each change in the styles could break something for the developers, especially if they have some style overrides for that component. More over, here we are adding new element, which is changing the DOM tree of the components itself.

cc @michaldudak @siriwatknp @hbjORbj

@hbjORbj
Copy link
Contributor Author

hbjORbj commented Oct 8, 2021

@mnajdova Yep, I think that's better. I will create a separate PR.

@michaldudak
Copy link
Member

Even though it says warning-please-do-not-use-this-the-warning-exists-for-a-reason?

@oliviertassinari oliviertassinari added the type: bug It doesn't behave as expected. label Oct 8, 2021
@mnajdova
Copy link
Member

mnajdova commented Oct 8, 2021

@michaldudak we have never supported zero config SSR. We have a documentation of how SSR should be configured - https://mui.com/guides/server-rendering/#mui-on-the-server so I believe it is safe to use it.

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.

While we are looking at this issue, I think that it's a good opportunity to make sure that we could support #11653 too in the future without having to change the approach.

Regarding why the warning exists, looking at the source https://github.com/emotion-js/emotion/blob/eda5e687c0bc4eddcafb243a2b1028296fb45cba/packages/styled/src/base.js#L144, it seems that the motivation for emotion is in case somebody provides a child icon element to the <Tab> that is a styled(), where the first child would be a <style> element, not the actual icon element.

Regarding the No SSR configuration support. I personally think that we should discourage it. But not supporting it? I don't know, we have tried in the past, by fixing similar warnings. In #26561 people are advocating for simpler integration.

@mnajdova
Copy link
Member

mnajdova commented Oct 8, 2021

@hbjORbj you've created a PR faster than us deciding what is the best strategy 😄 If there is a real use-case for adding the wrapper, for example supporting a new scenario for the icon position, then I am all for it. My point was that it's probably not the best idea to change the structure of the component, just for us to be able to fix the warning. There are other strategies that would allow us not to change the dom rendered, like cloning an element and adding a new class name. Not saying this is better, but at least something to consider. Anyway, would be great if we can at least address the comments added in the last reviews.

@hbjORbj
Copy link
Contributor Author

hbjORbj commented Oct 9, 2021

@mnajdova I agree. The sole purpose of the wrapper was to target a specific classname, so it's not the best approach. I think it's safer to clone icon and add a classname to it so that the dom rendered doesn't change.

However, I didn't fully understand the downsides of using the disabling comment you suggested (https://github.com/emotion-js/emotion/blob/main/packages/react/__tests__/warnings.js#L87). This looks the most simple solution to me.

p.s. I addressed your comments in a local branch. Will include them in a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: tabs Changes related to the tabs. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Tabs] pseudo class ":first-child" is potentially unsafe

6 participants