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.

Questionable .children requirement for void types

See original GitHub issue

Do you want to request a feature or report a bug?

Not really a bug, more a design consern

What’s the current behavior?

First off, I just want to say that Slate has become really great with the latest release. I am amazed how good the APIs have become, making it a proper editor toolkit with much freedom create the editor you want.

However there is one pretty bad design fault in the latest version in my opinion - and that is the requirement of void nodes to have a .children with at least one Text node inside it. This doesn’t make much sense to me, and seems like something that is forced there to work around the problems we have had with void node selections.

It feels weird to require an arbitrary property and a text node inside our non-text elements (as void blocks are supposed to be), just to support the selection model. Could not this be handled outside the value itself?

This makes it really hard to make the editor a truly controlled component if your value model is slightly different. I’m implementing an editor with the new version of Slate to use Portable Text (https://github.com/portabletext/portabletext) as the native value format. I had great success in this using the new APIs. For instance, I was able to replace the whole built in marks model to fit the marks model of Portable Text and the text blocks are now truly Portable Text inside the editor, meaning we don’t have to convert from and to the different formats.

With this freedom in mind, it feels really limiting that we can’t have a void object in the value with the data structure we’d like. It means that the editor value and the outside value can no longer be the same object anymore if void elements are supposed to have a custom structure. I expected the text blocks to be the problem here, and not the void ones, so this was a big surprise.

What’s the expected behavior?

That we are free to have void blocks or inlines modelled as we’d like in the actual editor value. Say like: {type: 'image', url: 'http...'} and not like {type: 'image', url: 'http...', children: [{text: ''}]}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:10
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
vijaiendransvcommented, Apr 1, 2020

Hi, We are in need of this feature for our project use case. Is there a way for us to have void nodes without children or with empty children array and no empty text nodes inside? Is there any overrides / patches available anywhere that i can refer to?

0reactions
tobiasandersencommented, Feb 17, 2020

You could do this by either making a normalization rule that inserts an empty text below it if it is the only child

FWIW this is what we currently do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Are Void Methods bad? - Towards Data Science
— Well, Yes and No. Generally yes. If you can write a method, that can work without side-effects, then you should definitely, do...
Read more >
For those who are childless, what filled that void for you?
Just to be a bit pedantic, childless implies that someone wants children but can't have them. For those of us who made a...
Read more >
How to specify function types for void (not Void) methods in ...
You are trying to use the wrong interface type. The type Function is not appropriate in this case because it receives a parameter...
Read more >
Parentification: The Dangers of Relying on Your Kids for ...
The more problematic type is “emotional parentification,” in which ... of behaviors, turn to children to fulfill their emotional needs.
Read more >
Helping a Child Cope with an Absent Parent
I encourage you to see what types of local supports are available for you and your family. If you have concerns there may...
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