I wrote a specific block for a customer. It is working well. I fill the data. I save and when I look on the website, it is quite perfect. But, when I refresh the editor, I am receiving this error.
Thank you so much!
blocks.min.js?ver=9ed25ffa009c799f99a4340915b6dc6a:3 Block validation: Block validation failed for
perso-chacha/bloc-sous-forme-de-template
({name: "perso-chacha/bloc-sous-forme-de-template", icon: {…}, keywords: Array(0), attributes: {…}, providesContext: {…}, …}).
Content generated by save
function:
<section class="chacha-column valign-center chacha-bloc-sous-forme-de-template block_891836fd-a657-41da-ba9b-ab915bfc1308"><style>
section.block_891836fd-a657-41da-ba9b-ab915bfc1308{
--section_background_color: #163F47;
--title-font-family: 'undefined';
--title-font-color: #FFFFFF;
--content_1-font-family: 'undefined';
--content_1-font-color: #BFFFFF;
--content_2-font-family: 'undefined';
--content_2-font-color: #FFFFFF;
--content_3-font-family: 'undefined';
--content_3-font-color: #FFFFFF;
}
</style><div class="container"><h2 class="title">sdfsfsdfsdf</h2><div class="content_1"><p></p></div><div class="chacha-row"><div class="content_2"><p></p></div><div class="content_3"><p></p></div></div></div></section>
Content retrieved from post body:
<section class="chacha-column valign-center chacha-bloc-sous-forme-de-template block_891836fd-a657-41da-ba9b-ab915bfc1308"><style>
section.block_891836fd-a657-41da-ba9b-ab915bfc1308{
--section_background_color: #163F47;
--title-font-family: 'undefined';
--title-font-color: #FFFFFF;
--content_1-font-family: 'undefined';
--content_1-font-color: #BFFFFF;
--content_2-font-family: 'undefined';
--content_2-font-color: #FFFFFF;
--content_3-font-family: 'undefined';
--content_3-font-color: #FFFFFF;
}
</style><div class="container"><h2 class="title">sdfsfsdfsdf</h2><div class="content_1"><p>sdfsdfsdfsf</p><p>sdfsdfsdfsfd</p></div><div class="chacha-row"><div class="content_2"><p>sdfsdfsdfsf</p><p>sdfsdfsdf</p></div><div class="content_3"><p>sdfsdfsdfsf</p><p>sdfsdfsdfsdf</p></div></div></div></section>
This is my save.js
import { RichText } from '@wordpress/block-editor';
export default function Save( props ) {
const notDefined = ( typeof props.className === 'undefined' || !props.className ) ? true : false
const { title_font, subtitle_font, content_font, slogan_font, link_font, title_color, slogan_color } = props.attributes;
const currentDate = new Date();
props = Object.assign(props, {
className: notDefined ? `chacha-column valign-center chacha-notre-approche block_${ currentDate.getTime() }` : `chacha-column valign-center chacha-notre-approche block_${ currentDate.getTime() } ${ props.className }`,
});
var css = `
section.block_`+currentDate.getTime()+`{
--title-font-family: '`+title_font+`';
--title-font-color: `+title_color+`;
--subtitle-font-family: '`+subtitle_font+`';
--content-font-family: '`+content_font+`';
--slogan-color: `+slogan_color+`;
--slogan-font-family: '`+slogan_font+`';
--link-font-family: '`+link_font+`';
}
`;
return (
<section {...props}>
<style>{ css }</style>
<div class="chacha-row wrap">
<div class="chacha-cell">
<RichText.Content
tagName="h2"
className="title"
value={ props.attributes.title }
/>
</div>
<div class="chacha-cell">
<RichText.Content
tagName="h3"
className="subtitle"
value={ props.attributes.subtitle }
/>
<RichText.Content
tagName="p"
className="content"
value={ props.attributes.content }
/>
<RichText.Content
tagName="p"
className="slogan"
value={ props.attributes.slogan }
/>
{props.attributes.link_show && props.attributes.link_text &&
<a
href={ props.attributes.link_url }
className="chacha-row valign-center"
>
{props.attributes.link_icon_id &&
<img
src={ props.attributes.link_icon_url }
alt={ props.attributes.title }
/>
}
<span>{ props.attributes.link_text }</span>
</a>
}
</div>
</div>
</section>
);
};
Edit
link under the list of tags to update your question instead{ ...props }
on the main component returned. This guarantees that your block markup will never match unless the markup was validated at the exact moment the post was saved then never again.props
should be considered immutable and unchangeable in any React component, you can call props that are function but you can never modifyprops
, ever, under any circumstances.useBlockProps
anduseSelect