I needed to support mermaid in my documentation site but could not get rehype-mermaidjs to work correctly. The maintainer of the plugin helped with troubleshooting and found that the way Astro preprocesses the hast seems to be incompatible with the plugin, because mermaidjs searches for pre and code elements but Astro turns them into raw nodes. He mentioned this is a bug in Astro and suggested I ask here instead.
https://github.com/remcohaszing/remark-mermaidjs/issues/23#issuecomment-1704861113