question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Editor inserts empty paragraph before and after custom node

See original GitHub issue

What’s the bug you are facing?

I have a custom node, with a renderHTML() function which looks like this:

renderHTML({ HTMLAttributes }) {
		const { href, target, style, width, ...imgAttrs } = HTMLAttributes;

		if (href) {
			return [
				'figure',
				{
					style,
					contenteditable: true,
				},
				[
					'a',
					{
						href,
						target,
					},
					[
						'img', mergeAttributes(imgAttrs, { draggable: false, contenteditable: false, width }),
					],
				],
				['figcaption', 0],
			];
		} else {
			return [
				'figure',
				{
					style,
					contenteditable: true,
				},
				[
					'img', mergeAttributes(imgAttrs, { draggable: false, contenteditable: false, width }),
				],
				['figcaption', 0],
			];
		}
	},

Everything with my custom node works just fine but one thing, namely, before and after each ‘figure’-node that is inserted, there is a p-Tag rendered as such, with a line break inside:


<p><br class="ProseMirror-trailingBreak"></p>

In the end, the full HTML for my node, after having inserted it, would be:

<p>
  <br class="ProseMirror-trailingBreak">
</p>
<p>
  <figure style="float: none;" contenteditable="true"><img src="https://something.com/16/32/1d/d2/1644827363/doge.jpg" alt="doge" draggable="false" contenteditable="false" width="auto">
    <figcaption>doge</figcaption>
  </figure>
  <br class="ProseMirror-trailingBreak">
</p>
<p>
  <br class="ProseMirror-trailingBreak">
</p>

Upon content update, tiptap deletes the line break inside the paragraph, but the paragraph itself remains. In the end, every time I update something, the number of empty tags would accumulate and become very numerous. Naturally I can just filter out empty p-tags every time the editor loads, but that’s a dirty approach from my side.

Any idea on why these empy paragraphs might show up in the first place?

How can we reproduce the bug on our side?

Did not manage to create a working sandbox in codesandbox.

In Codesandbox, I here get an error that I do not get locally, with the same versions of the dependencies.

error in mounted hook: SyntaxError mixing inline and block content

Can you provide a CodeSandbox?

No response

What did you expect to happen?

I expected my custom node to be inserted without empty p-Tags before and after.

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. 💖

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:10
  • Comments:5

github_iconTop GitHub Comments

4reactions
tomosterlundcommented, Oct 25, 2022

Any news on this one? Seems to be an issue to at least 9 other devs as well.

0reactions
shekhars094commented, Dec 9, 2022

is anyone has solution?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Empty text node added before paragraph. Why?
The text node is not empty but consists of the (invisible) U+FEFF ZERO WIDTH NO-BREAK SPACE character. It is treated as a data...
Read more >
How to preserve <br> tags in empty paragraphs - Discuss
Hi. In the app I'm working on, the user can click on various HTML elements (currently P and H1-H6) to edit their contents....
Read more >
createParagraphNear – Tiptap Editor
If a block node is currently selected, the createParagraphNear command creates an empty paragraph after the currently selected block node.
Read more >
Insert Empty Paragraph Using Inserthtml - ADocLib
Insert Empty Paragraph Using Inserthtml. Trix will automatically insert a separate <trix-toolbar> before the editor. Trix won't load any HTML content inside ...
Read more >
or "<p>&nbsp;</p>" or "<br />" added to empty textareas ...
The wiered thing is it wasn't doing this initially and then it ... Other editors might see it as an unneeded tag and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found