mui / mui/material-ui

Components rendered by React 18 ReactDOMServer don't have CSS classes reflecting their `sx` prop

Open
#32,893 3 comments 4 reactions 1 assignee View on GitHub

@siriwatknp is already working on this.

Since Jun 20, 2022.

external dependency scope: system
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Duplicates
  • I have searched the existing issues
Latest version
  • I have tested the latest version
Current behavior 😯

Components rendered with ReactDOMServer are given a unique CSS class for the style changes in their sx prop, but this CSS class does not actually get created, so the rendered component is unstyled. Excecption: if the component shares an sx prop with another component that is rendered normally, the CSS is added and rendered correctly.

Expected behavior 🤔

Components rendered with ReactDOMServer should have styles that match the sx prop applied.

Steps to reproduce 🕹

I have created a minimal reproduction on CodeSandbox: https://codesandbox.io/s/nervous-benz-354utb?file=/src/Demo.tsx

Context 🔦

I am working with some non-React JS libraries (in this case, Leaflet) that renders raw HTML strings. If I want to render a component within the context of this library, I must first render the component as a string on the client side (with ReactDOMServer.renderToString() and pass this string to the library. Unfortunately, styling via the sx prop is not possible with this method.

I believe this issue is a duplicate of #30865. This issue does not happen on React 17.

Your environment 🌎

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.