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

Root node is replaced by a div when a custom div is in options.components #36

Closed
4 tasks done
nag opened this issue Dec 11, 2021 · 5 comments
Closed
4 tasks done
Labels
💪 phase/solved Post is done

Comments

@nag
Copy link

nag commented Dec 11, 2021

Initial checklist

Affected packages and versions

rehype-react@latest

Link to runnable example

https://codesandbox.io/s/rehype-react-bug-szj7g

Steps to reproduce

I have included a link (you may have to reload the browser page).
If we comment out line 28, the extra div will disappear.

components: {
  div: (props) => createElement("div", props) // try to remove this line
}

Note that there are no div elements in the source HTML.

Expected behavior

The div element should not be created.

Actual behavior

The div element is created.

Runtime

Node v16

Package manager

npm v7

OS

Windows

Build and bundle tools

Parcel, Next.js

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Dec 11, 2021
@wooorm
Copy link
Member

wooorm commented Dec 21, 2021

Yep. See:

// Invert <https://github.com/syntax-tree/hast-to-hyperscript/blob/d227372/index.js#L46-L56>.
.

How is it a problem though?

@nag
Copy link
Author

nag commented Dec 21, 2021

I expected the source HTML and result HTML to be the same. It looks like a side-effect to me. After all, a wrapping element is being implicitly created that shouldn't exist. Maybe there should be a Fragment in place of the div. 🤔

I was surprised to see that the root node gets passed to options.components.div and had to debug this.

@wooorm
Copy link
Member

wooorm commented Dec 22, 2021

Maybe there should be a Fragment in place of the div.

The Fragment is optional.
Did you see the code? The underlying project can only handle elements and text. So a div is created for the root. The code tries to change that to a fragment, but because you pass a component it’s no longer a simple div

@wooorm
Copy link
Member

wooorm commented Dec 22, 2021

I get it’s unexpected, just not sure how to do anything about it

@wooorm
Copy link
Member

wooorm commented Sep 1, 2023

@wooorm wooorm closed this as completed Sep 1, 2023
@wooorm wooorm added the 💪 phase/solved Post is done label Sep 1, 2023
@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 phase/solved Post is done
Development

No branches or pull requests

2 participants