Gutenberg: core/heading block causing block validation error in template

Created on 5 Dec 2018  路  7Comments  路  Source: WordPress/gutenberg

Describe the bug
When using the core/heading block in a InnerBlocks template, setting the level causes a block validation error upon saving and refreshing the page. For example, if you set the level to 3, you get the following error:

Expected:<h2>We Build Blocks</h2> Actual: <h3>We Build Blocks</h3>

To Reproduce
To reproduce, create an InnerBlocks template like this:

<InnerBlocks template={[ // Add placeholder blocks ['core/heading', { content: 'Test Block Content', level: '3', }], ]} templateLock={ false } />

Load the block in the editor, save the page, refresh to see the error.

Expected behavior
The block should return the heading level you saved and not produce a block validation error.

[Feature] Nested / Inner Blocks [Type] Help Request

Most helpful comment

Looks like the level attribute for the headings block should be numeric. When I use:
[ 'core/heading', { level: '6', placeholder: 'Enter a heading' } ],
I also get a validation error, but with:
[ 'core/heading', { level: 6, placeholder: 'Enter a heading' } ],
everything works as expected.

All 7 comments

Doesn't it need to be like this?

<InnerBlocks template={[ ['core/heading', { content: 'Test Block Content', attributes: { level: '3', }, }], ]} templateLock={ false } />

With level being inside `attributes? .

@swissspidy Adding the attributes does make the page save successfully, but the block doesn't obey which level you set. It always defaults to level 2.

I am having the exact some issue. When the page is save everything is working, but when a reload the page, it give me :

Expected:
<h2>Title</h2>

Actual:

<h1>Title</h1>

Looks like the level attribute for the headings block should be numeric. When I use:
[ 'core/heading', { level: '6', placeholder: 'Enter a heading' } ],
I also get a validation error, but with:
[ 'core/heading', { level: 6, placeholder: 'Enter a heading' } ],
everything works as expected.

@ahorndesign you are a god

Thank you for helping with the answer to this at https://github.com/WordPress/gutenberg/issues/12606#issuecomment-447648217 @ahorndesign !

@ahorndesign Thanks so much for the tip! Saved me some headaches...

Was this page helpful?
0 / 5 - 0 ratings