Gh05d
Gh05d

Reputation: 8962

prop gets lost when matomo is executed in svelte

I have encountered a really weird bug when passing props. This is the parent component:

<script>
 export let close;
  let showDownload = false;
  let validOS;
  let userID;
  let downloads;

  async function setData(args) {
    // do logic
    downloads = args;
    showDownload = true;
  }
</script>

<Modal {close}>
  {#if showDownload}
    <Download {userID} {downloads} {close} />
  {:else}
    <Register {validOS} {setData} {close} />
  {/if}
</Modal>

Basically the problem is that my close function gets lost in the Download Component. The flow is that first the Register Component is rendered, does some logic and after it is done, the Download Component gets rendered with values passed from the Register Component. After finishing some logic, close is called. But it is undefined. The problem seems to be this onMount function in the Download Component:

<script>
   export let close
</script

  onMount(() => {
    let element = document.createElement("a");
    element.setAttribute("href", "some url", "download");
    element.style.display = "none";
    document.body.appendChild(element);
    element.click();
    document.body.removeChild(element);

    _paq.push(["trackLink", href, "download"]);
  });

I was able to narrow the problem down to the _paq function (it is from Matomo, a global function on the window object). When I remove this function, then everything works. So does anybody has an idea what is going wrong here?

Upvotes: 0

Views: 193

Answers (0)

Related Questions