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

[joy-ui] Typography crashes if used with dangerouslySetInnerHtml #40058

Open
2 tasks done
MonstraG opened this issue Dec 1, 2023 · 3 comments
Open
2 tasks done

[joy-ui] Typography crashes if used with dangerouslySetInnerHtml #40058

MonstraG opened this issue Dec 1, 2023 · 3 comments
Assignees
Labels
component: Typography The React component. on hold There is a blocker, we need to wait package: joy-ui Specific to @mui/joy

Comments

@MonstraG
Copy link
Contributor

MonstraG commented Dec 1, 2023

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Link to live example:
https://codesandbox.io/p/sandbox/dazzling-visvesvaraya-y9tgkk

Steps:

export default function TypographyBasics() {
  return <Typography dangerouslySetInnerHTML={{ __html: "test" }} />;
}

Current behavior 😯

Uncaught Error: Can only set one of children or props.dangerouslySetInnerHTML.

Expected behavior 🤔

Renders text

Context 🔦

Render md -> html and set it as content of the typography.

I'm not sure how to apply typography's styles to text otherwise

Your environment 🌎

npx @mui/envinfo

System:
OS: Windows 11 10.0.22621
Binaries:
Node: 20.9.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
npm: 10.1.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: Not Found
Edge: Chromium (119.0.2151.97)
npmPackages:
@emotion/react: ^11.11.1 => 11.11.1
@emotion/styled: ^11.11.0 => 11.11.0
@mui/base: 5.0.0-beta.25 => 5.0.0-beta.25
@mui/icons-material: ^5.14.19 => 5.14.19
@mui/joy: 5.0.0-beta.16 => 5.0.0-beta.16
@types/react: ^18.2.39 => 18.2.39
react: ^18.2.0 => 18.2.0
react-dom: ^18.2.0 => 18.2.0
typescript: ^5.3.2 => 5.3.2

@MonstraG MonstraG added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 1, 2023
@MonstraG MonstraG changed the title [Joy] Typography crashes if used with `dangerouslySetInnerHtml [Joy] Typography crashes if used with dangerouslySetInnerHtml Dec 1, 2023
@danilo-leal danilo-leal changed the title [Joy] Typography crashes if used with dangerouslySetInnerHtml [joy-ui] Typography crashes if used with dangerouslySetInnerHtml Dec 4, 2023
@danilo-leal danilo-leal added component: Typography The React component. package: joy-ui Specific to @mui/joy labels Dec 4, 2023
@brijeshb42 brijeshb42 removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 4, 2023
@brijeshb42
Copy link
Contributor

There are 3 undefined values as children when no children are provided resulting in this error. This does not affect material-ui because that only renders a single element.

@brijeshb42 brijeshb42 added the on hold There is a blocker, we need to wait label Dec 4, 2023
@siriwatknp
Copy link
Member

I don't see why you need to use dangerouslySetInnerHTML on the Typography. Why not just use a plain HTML tag?

<p dangerouslySetInnerHTML={{ __html: 'test' }} />

@siriwatknp siriwatknp added the status: waiting for author Issue with insufficient information label Dec 17, 2023
@MonstraG
Copy link
Contributor Author

MonstraG commented Dec 17, 2023

This is sort of what I ended up doing:

<Typography component="div">
    <article dangerouslySetInnerHTML={{ __html: 'test' }} />
</Typography>

but that changes html markup (by adding wrapping div). In my case this is fine, but this might not be fine in all cases.

I want to use dangerouslySetInnerHTML on the Typography because:

  1. I want to render pre-prepared html
  2. I want styles of a typography

this the most direct way to solve this, especially coming from material-ui, where it just worked.

You could also just do something like this :#40221

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Dec 17, 2023
@ZeeshanTamboli ZeeshanTamboli removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Typography The React component. on hold There is a blocker, we need to wait package: joy-ui Specific to @mui/joy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants