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.

Transforms.setNodes causes nodes to disappear

See original GitHub issue

Problem I’m using Transforms.setNodes to update some nodes (specifically link elements). Unfortunately, this results in some weird behavior where the nodes are completely removed instead of being updated.

Codesandbox: https://codesandbox.io/s/gifted-nightingale-shm5b

Basically, I’m trying to modify some metadata inside a link element by using Transforms.setNodes. Unexpectedly, this causes the link to disappear entirely.

The starting editor value is “This is an Example link in a paragraph”, which then turns into “This is an in a paragraph” once the transform runs. This happens both when using slate-react (as demonstrated in Editor.js) as well as headlessly (as demonstrated in Headless.js).

Solution Transforms.setNodes should not delete nodes. It should only update the nodes’ properties.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
marcdavi-escommented, Apr 27, 2022

Update:

I fixed my problem by explicitly returning true from editor.isInline for all images.

When Slate treated them as block void elements, I had the behaviour described above. Now when Slate treats them as inline void elements, it works as intended.

I can’t claim to understand why there was inconsistency, but this fix is good enough for what I’m doing right now.

0reactions
DouglasGabrcommented, Oct 13, 2022

I was having this error trying to apply bold text in the same paragraph as a link, and was able to solve this the same way as @marcdavi-es. I defined a function withInlines:

function withInlines(editor: Editor) {
  editor.isInline = (element) => element.type === 'link';
  return editor;
}

Then applied it to the editor creation:

const [editor] = useState(() => withInlines(withReact(withHistory(createEditor()))));

I also saw that is the exact way that is done in the inlines example

Read more comments on GitHub >

github_iconTop Results From Across the Web

Transforms - Slate
Transforms are helper functions operating on the document. ... Transforms.setNodes(editor: Editor, props: Partial<Node>, options?) Set properties of nodes ...
Read more >
Nodes | Unreal Engine 4.27 Documentation
Node graph that uses events and function calls to perform actions in response to gameplay events associated with the Blueprint.
Read more >
Chapter 2: Inline Styles - Philipp Flenker
Practically, this makes no difference, as the methods from Slate we're ... What setNodes does is that it merges all the affected nodes...
Read more >
Building A Rich Text Editor (WYSIWYG) - Smashing Magazine
We use Transforms.setNodes provided by Slate to update properties on nodes. Our toggleBlockType 's implementation is as below:.
Read more >
Network dismantling | PNAS
It thus makes much more sense to think in terms of good dismantling sets as a whole and not about individual nodes as...
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