I solved it with an “update” button in the block. It is a bit weird because I need to send “fake” attributes to re-render it. But it works.
var el = wp.element.createElement;
var registerBlockType = wp.blocks.registerBlockType;
var BlockControls = wp.blockEditor.BlockControls;
var ServerSideRender = wp.serverSideRender;
var Toolbar = wp.components.Toolbar;
var IconButton = wp.components.Button;
function sendfakeAttribute(props) {
// this actually triggers the ServerSideRender again ¯\_(ツ)_/¯
props.setAttributes({ updated: Date.now() });
}
registerBlockType( 'simpletoc/toc', {
title: __( 'SimpleTOC', 'simpletoc' ),
icon: listul,
category: 'layout',
edit: function( props ) {
return [
el(
BlockControls,
{ key: 'controls' },
el(
Toolbar,
null,
el(
IconButton,
{
className: 'components-icon-button components-toolbar__control',
label: 'update',
onClick: function() { sendfakeAttribute(props) },
icon: 'update'
}
)
)
),
el(
ServerSideRender,
{
block: props.name,
attributes: props.attributes
}
)
];
},
save: props => {
return null;
},
} );