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

[docs] Fix MarkdownElement regression from adding CSS variables #35096

Merged
merged 7 commits into from Nov 14, 2022

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Nov 11, 2022

@siriwatknp siriwatknp added docs Improvements or additions to the documentation regression A bug, but worse labels Nov 11, 2022
Comment on lines 411 to 413
'& :not(pre) > code': {
color: '#fff',
},
Copy link
Member Author

@siriwatknp siriwatknp Nov 11, 2022

Choose a reason for hiding this comment

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

@mui-bot
Copy link

mui-bot commented Nov 11, 2022

Messages
📖 Netlify deploy preview: https://deploy-preview-35096--material-ui.netlify.app/

No bundle size changes

Generated by 🚫 dangerJS against 8404d65

@siriwatknp siriwatknp changed the title [docs] Fix scrolling issue on dark mode [docs] Fix MarkdownElement regression on dark mode Nov 11, 2022
@@ -32,6 +32,7 @@ const StyledMarkdownElement = styled(MarkdownElement)(({ theme }) => ({

const StyledSimpleCodeEditor = styled(SimpleCodeEditor)(({ theme }) => ({
...theme.typography.body2,
letterSpacing: '0.01071em', // must sync with MarkdownElement.js#L42, otherwise the text will overlap when highlight the code.
Copy link
Member

Choose a reason for hiding this comment

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

The regression https://deploy-preview-34976--material-ui.netlify.app/material-ui/react-snackbar/#positioned-snackbars

Screenshot 2022-11-13 at 00 28 31

there is a slight offset.


Why was letterSpacing: '0.01071em', MarkdownElement.js#L42, added in #34976?
It feels like we could solve this in a simpler way: by removing these two letterSpacing CSS properties.

If we really want this style, then it might be better to drop lightTheme.typography.fontFamilyCode (what I did was a bit crap, I shouldn't have imported lightTheme, but likely a clean fontCode object). Once we have this fontCode object, we could then spread it where needed:

-  ...theme.typography.body2,
-  fontSize: theme.typography.pxToRem(13),
-  fontFamily: theme.typography.fontFamilyCode,
-  letterSpacing: '0.01071em', 
+  ...fontCode,

x2

or maybe it should have been a variant, yeah maybe even simpler:

-  ...theme.typography.body2,
-  fontSize: theme.typography.pxToRem(13),
-  fontFamily: theme.typography.fontFamilyCode,
-  letterSpacing: '0.01071em', 
+  ...theme.typography.code,

and then make sure Material UI + branding theme is always the parent context.

Copy link
Member Author

Choose a reason for hiding this comment

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

and then make sure Material UI + branding theme is always the parent context.

Can we not do this? It is very hard to reason about and produce a different result when the component renders in a different context.

The reason I use lightTheme and darkTheme is to make the component agnostic of the context. This means the component can render in any place without the theme context and it still produces the same appearance.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why was letterSpacing: '0.01071em', MarkdownElement.js#L42, added in #34976?

It is because theme.typography.body2 in Material UI contains letterSpacing: '0.01071em' but the branding theme does not so I have to add it here so that we preserve the existing behavior and Argos regression pass.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's break it. I am removing the letter-spacing.

Copy link
Member

Choose a reason for hiding this comment

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

Can we not do this? It is very hard to reason about and produce a different result when the component renders in a different context.

The meat of this proposal was to make the page throw when the theme in the context provided to a docs-infra component (e.g. MarkdownElement) isn't the brandingTheme. For example, why are 1 and 2 having two different values:

  1. https://master--material-ui.netlify.app/blog/making-customizable-components/ padding 20px

Screenshot 2022-11-15 at 00 57 28

  1. https://master--material-ui.netlify.app/material-ui/react-checkbox/#accessibility padding 16px

Screenshot 2022-11-15 at 00 57 40

I shared a possible solution in #34976 (comment). Importing the theme solves the visible problem but it feels like we don't solve the root problem strange context values, e.g. with the sx prop we can't use this approach. We also branch away from the default API we recommend people use the component. I fear that it makes it harder to solve as it hides the instances where the value in the context is wrong.

The flip side is that we are getting closer to https://vanilla-extract.style/ with this theme import approach.

It is because theme.typography.body2 in Material UI contains letterSpacing: '0.01071em' but the branding theme does not so I have to add it here so that we preserve the existing behavior and Argos regression pass.

👍 to remove it. I think that letterSpacing was designed for the roboto font with text but we render code here.

Copy link
Member Author

Choose a reason for hiding this comment

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

The meat of this proposal was to make the page throw when the theme in the context provided to a docs-infra component

Seems like we have different thoughts on this. Better to discuss it in a proper place to include other opinions and create documentation around it 👉 added to Notion page.

Copy link
Member

Choose a reason for hiding this comment

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

@siriwatknp I have added a few comments and options on the Notion page. How do you want to move from there? It could be a use case for the the optional decision making meeting slots.

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. I will start documenting "How it currently works"
  2. Create options that we want to have in the future
  3. Include X and Toolpad team to take a look, give feedback, and discuss until we agree on the final decision.
  4. Start implementing (likely 1st-2nd quarter 2023). Keep in mind that whichever option we choose, might impact the Toolpad and X pages so there will be some migration period.

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.

👍

@oliviertassinari oliviertassinari added the bug 🐛 Something doesn't work label Nov 12, 2022
@oliviertassinari oliviertassinari changed the title [docs] Fix MarkdownElement regression on dark mode [docs] Fix MarkdownElement regression from adding CSS variables Nov 12, 2022
@siriwatknp siriwatknp merged commit b2e781c into mui:master Nov 14, 2022
the-mgi pushed a commit to the-mgi/material-ui that referenced this pull request Nov 17, 2022
daniel-rabe pushed a commit to daniel-rabe/material-ui that referenced this pull request Nov 29, 2022
feliperli pushed a commit to jesrodri/material-ui that referenced this pull request Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work docs Improvements or additions to the documentation regression A bug, but worse
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants