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

NodeViewContent generates an unnecessary div #2675

Closed
2 tasks done
anton-liubushkin opened this issue Apr 3, 2022 · 6 comments
Closed
2 tasks done

NodeViewContent generates an unnecessary div #2675

anton-liubushkin opened this issue Apr 3, 2022 · 6 comments
Labels
Type: Bug The issue or pullrequest is related to a bug

Comments

@anton-liubushkin
Copy link
Contributor

What’s the bug you are facing?

I'm using React and working on a custom extension for tables and encountered that the NodeViewContent component always creates a nested div element.

Screen Shot 2022-04-04 at 12 54 24 AM

Screen Shot 2022-04-04 at 12 55 04 AM

How can we reproduce the bug on our side?

  1. Create a node view with React or add the Node view to a table extension
  2. Use NodeViewContent to render child content
export const TableComponent: FC<NodeViewProps> = (props) => {
 /* Some sort of code */
  return (
    <table>
      <NodeViewContent as="tbody" />
    </table>
  )
}

Can you provide a CodeSandbox?

No response

What did you expect to happen?

I would like to avoid unnecessary elements in the DOM.

Anything to add? (optional)

No response

Did you update your dependencies?

  • Yes, I’ve updated my dependencies to use the latest version of all packages.

Are you sponsoring us?

  • Yes, I’m a sponsor. 💖
@anton-liubushkin anton-liubushkin added the Type: Bug The issue or pullrequest is related to a bug label Apr 3, 2022
@philippkuehn
Copy link
Contributor

Duplicate of #1527

@philippkuehn philippkuehn marked this as a duplicate of #1527 Apr 4, 2022
@anton-liubushkin
Copy link
Contributor Author

@philippkuehn, if I understand correctly, there is no way to get rid of the internal div element?

<NodeViewContent as="table">
converts into

<table as="table" data-node-view-content="" style="white-space: pre-wrap;">
  <div style="white-space: inherit;"> // <-- This ugly wrapper
    /* content */
  </div>
</table>

@henrykuzmick
Copy link

@philippkuehn I don't think this should be closed? #2213 doesn't seem to fix the unnecessary div problem.

This causes a number of issues.

Let's say I want to add some controls around a table. I could extend the Table plugin and add addNodeView.

Inside of the component used I'd render some control handles and <NodeViewContent as="table" /> in the middle.

This in turn breaks the structure of the table and most of the commands from the Table extension.

@sradu
Copy link

sradu commented May 28, 2023

I'm running into too. Any chance this will get merged soon?

@levi-putna
Copy link

levi-putna commented Feb 14, 2024

Beyond tables, this also creates issues when you want to use a CSS grid layout on the children.

You develop an extension and add some controls that enable you to manage the grid layout of your component. You apply your grid class to the NodeViewContent, <NodeViewContent className="grid grid-cols-12 gap-4" />.

Then, an inner div is added, and instead of the grid classes applying to the children, they are applied to the inner div breaking the layout.

<div class="grid grid-cols-12 gap-4" data-node-view-content="" style="white-space: pre-wrap;">
    <div style="white-space: inherit;"> // <-- This ugly div wrapper again.
        <h1 padding="0" span="10" class="col-span-10">Sample Heading</h1>
        <p padding="0" span="10" class="col-span-2">This is some placeholder text...</p>
    </div>
</div>

@ludusrusso
Copy link

@levi-putna I have a similar problem, did you find a way to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug The issue or pullrequest is related to a bug
Projects
None yet
Development

No branches or pull requests

6 participants