Modal closes up on updates from server, if it was not opened using `show_modal` function!

Hey Guys,

I’m building a command palette.

It however closes on update from server, when I open the command palette using normal javascript & hook.

const CommandPalette = {
  mounted() {
    document.addEventListener("keydown", (e) => {
      if (e.key === "k" && e.metaKey) {

        const bg = document.querySelector(`#${}-bg`);
        const container = document.querySelector(`#${}-container`);
        const content = document.querySelector(`#${}-content`);
        const focusable = content.querySelector(
          'button, [href], input, [tabindex="0"]'
        ); = "block"; = "block";
        bg.classList.add("opacity-100"); = "block";

export default CommandPalette;

But when it’s opened using show_modal function, it stays open even after updates from server.

How to prevent it from closing?

@cmo answered this in another thread.