Lightbox no longer working?

I was able to duplicate my production site locally and reproduce the issue. Turns out that it is a bug that is surfacing because of some code in a custom theme plugin that I wrote. I still cannot explain why this is breaking Lightbox or why this only recently became a problem. Could be a yet-undiscovered bug in the core?

My plugin code is very simple:

import { apiInitializer } from "discourse/lib/api";

export default apiInitializer("0.11.1", (api) => {
  // Render adjustments for post content
  api.decorateCookedElement(
    (elem) => {
      elem.innerHTML = elem.innerHTML.replace(/Finances/, "Test Str");
    },
    { id: "test-decorator", onlyStream: true }
  );
});

All it is trying to do is a simple string replace in rendered post content. Somehow, this breaks all Lightboxes in all posts (even those which don’t contain the string). Commenting out the elem.innerHTML = ... line causes Lightboxes to work once again.

Note that the above example is simplified (my actual plugin replaces specific rendered links in posts and does other operations on cooked content), but even the very simple code above reproduces the issue I’m seeing.

Is this the correct way to modify cooked content at render time in posts and this is a new core bug related to Lightboxes? Or have I been doing this wrong all along and this never should have worked in the first place?