How to use FilterProcessResult::createPlaceholder (#lazy_builder) in an input filter?
After several months, I looked at the code again and found the issue. The createPlaceholder method calls addAttachments, but then I call setAttachments, which removes the previous attachment.

I should always use addAttachments as that will merge instead of overwrite.

foreach ($matches['code'] as $i =&gt; $code) {
  $args = [$code, $this-&gt;settings['render_mode']];
  $markup = $result-&gt;createPlaceholder('\Drupal\processing\Plugin\Filter\FilterProcessing::build', $args);
  $text = preg_replace('/\[processing\](?P&lt;code&gt;.*)\[\/processing\]/is', $markup, $text);
}
$result
  -&gt;setProcessedText($text)
  -&gt;addAttachments(['library' =&gt; ['processing/drupalprocessing']])
  -&gt;setCacheTags(['processing']);