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

Why is rendered output wrapped in a <span>? #30

Closed
chunfeilung opened this issue Aug 27, 2020 · 5 comments
Closed

Why is rendered output wrapped in a <span>? #30

chunfeilung opened this issue Aug 27, 2020 · 5 comments

Comments

@chunfeilung
Copy link
Contributor

First of all, thanks for making next-mdx-remote; this makes my life so much easier!

One thing I did notice is that hydrate.js wraps the renderedOutput in a span element:

React.createElement('span', {
  dangerouslySetInnerHTML: {
    __html: renderedOutput,
  },
})

Because the renderedOutput may include block-level elements – which are technically not allowed within inline elements like span – the resulting HTML will often be invalid. As far as I can tell this does not cause any actual issues, but it does make me wonder whether this is a bug or a feature. 😄

@jescalan
Copy link
Contributor

Good question! It has to be rendered into something, and we can't render it into a fragment, so it was just an arbitrary choice. I would be fine with changing it to a div, but that could also cause problems if your content was intended to be inline, was the theory. Although with an mdx file, I'm not even sure if its possible to generate inline content, so maybe a div is the better choice?

I'd welcome a PR either way!

@domitriusclark
Copy link

domitriusclark commented Sep 8, 2020

Yeah I think this will cause a constant bloated error message around dangerouslySetInnerHTML not "matching" the server

Dug around a bit and it seems to need a div 🤷‍♂️

Can put up a PR for this if we want?

@domitriusclark
Copy link

Just saw there already is a PR 😅

@stevenmunro
Copy link

stevenmunro commented Sep 20, 2020

I recommend that this <span> or <div> (when it eventually becomes one) is not automatically removed using Javascript. When applying styles to markdown using a parent .markdown class, I rather the styles got applied even when Javascript is disabled.

@jescalan
Copy link
Contributor

Closed by #34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants