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.

Void nodes can contain blocks?

See original GitHub issue

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

Either a bug or a question 😃

What’s the current behavior?

The current behavior is that as of https://github.com/ianstormtaylor/slate/pull/1663/files#diff-4a9856aa0d6cae32f324558beae45156, isVoid blocks can now contain child blocks as opposed to only text nodes. Consider:

/** @jsx h */
import h from '../../helper/hyperscript';

// This test case verifies an image block cannot conatin other block types.
export const input = (
  <value>
    <document>
      <title>Title</title>
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png"><h6>Images - Header</h6></image>
      <image src="https://www.notarealimage.png"><blcode>Images - BlockCode</blcode></image>
      <image src="https://www.notarealimage.png"><quote>Images - Quote</quote></image>
      <image src="https://www.notarealimage.png"><title>Images - Title</title></image>
      <image src="https://www.notarealimage.png"><p>Images - Paragraph</p></image>
      <image src="https://www.notarealimage.png">
        <ol><oli>Images - OrderedListItem</oli></ol>
      </image>
      <image src="https://www.notarealimage.png">
        <ul><uli>Images - OrderedListItem</uli></ul>
      </image>
      <image src="https://www.notarealimage.png"><b><i><u><c>Images - Marks</c></u></i></b></image>
      <image src="https://www.notarealimage.png">
        <table><tr><td>Images - Table</td></tr></table>
      </image>
      <p>Paragraph</p>
    </document>
  </value>
);

export const output = (
  <value>
    <document>
      <title>Title</title>
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <p>Paragraph</p>
    </document>
  </value>
);

This test case (perhaps a bit contrived) verified that malformed image blocks with children would have their children removed by the schema rules. Now what happens is that these non-text-node children are allowed to exist.

What’s the expected behavior?

I’m not sure. The documentation says a void block has one text child, and the PR description seems to indicate that the intention is to give the void block the ability to have arbitrary text, but the removal of the validation rule suggests that the intention is to allow void blocks to have arbitrary children. But I can’t help but wonder what the point of the void node is then in that case?

Happy to submit a PR if that’s the direction we need to go. Just wanted to check in and get my mental model straightened out at least 😃

Thanks for your time

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
camerackercommented, Apr 5, 2018

I’ve been working on an isAtomic schema controlled option for blocks for an issue here: https://github.com/ianstormtaylor/slate/issues/1654

But it’s really early and I’m still working on developing the test cases up front. Lots of corner cases.

0reactions
ianstormtaylorcommented, Apr 5, 2018

I think isVoid will remain as a node whose content is out of the concern of Slate, and treated as a single, atomic block.

We might need to introduce isAtomic or similar if people want to have nodes that are atomic but still controlled by Slate. I haven’t really thought that through though.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a better way to handle void nodes? · Issue #667 - GitHub
From my understanding, void nodes are represented as a block node that contains a single character (with void set to true). When the...
Read more >
Normalizing - Slate
All Element nodes must contain at least one Text descendant — even Void Elements. ... Block nodes can only contain other blocks, or...
Read more >
Structure Void - Minecraft Wiki - Fandom
A structure void is an invisible block that allows existing blocks to remain unchanged rather than be overridden when using the structure block...
Read more >
enumerateChildNodes(withName:using:) - Apple Developer
A block to execute on nodes that match the name parameter. The block has the signature (node: SKNode , stop: UnsafeMutablePointer < ObjCBool...
Read more >
Describing Linked Datasets with the VoID Vocabulary - W3C
VoiD descriptions can be used in many situations, ranging from data discovery to cataloging and archiving of datasets, but most importantly it ...
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