The solution for me to have decorateCookedElement run only once for a specific type, and when the last cooked content is ready, was as simple as that:
<script type="text/discourse-plugin" version="0.11">
api.decorateCookedElement((callback, opts) => {
if(opts?.widget?.dirtyKeys?.name === 'post-stream') {
if(this?.cooking) clearTimeout(this.cooking);
this.cooking = setTimeout(() => {
console.log('All cooking is done, update new content..');
});
}
});
</script>
Please correct me if there is anything wrong or there are any pitfalls in this code.