Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A leak is occurring with repeated use:floatingContent. #18

Open
sinbino opened this issue Aug 13, 2024 · 1 comment
Open

A leak is occurring with repeated use:floatingContent. #18

sinbino opened this issue Aug 13, 2024 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@sinbino
Copy link

sinbino commented Aug 13, 2024

This is a slightly modified version of an example from the document.

<script lang="ts">
  import { offset, flip, shift } from "svelte-floating-ui/dom";
  import { createFloatingActions } from "svelte-floating-ui";

  const [ floatingRef, floatingContent ] = createFloatingActions({
    strategy: "absolute",
    placement: "top",
    middleware: [
      offset(6),
      flip(),
      shift(),
    ],
    onComputed() {
      console.log('😡 onComputed!')
    },
  });

  let showTooltip: boolean = false;
</script>

<div style="height: 2000px">
  <button
    on:mouseenter={() => showTooltip = true}
    on:mouseleave={() => showTooltip = false}
    use:floatingRef
  >Hover me</button>

  {#if showTooltip}
    <div style="position:absolute" use:floatingContent>
      Tooltip
    </div>
  {/if}
</div>

Repeat hover to repeatedly create and destroy the DOM containing the use:floatingContent. Then onComputed is verbosely called depending on the number of times the DOM is regenerated.

Is it possible that when the DOM containing the use:floatingContent is destroyed, the floatingContent is not properly cleaned up after?

@sinbino
Copy link
Author

sinbino commented Aug 13, 2024

In svelte-floating-ui/src/lib/index.ts, line 75, the return value of initAutoUpdate seems to expect a cleanup function, but the _autoUpdate function has been processed inside the tick promise, I think it is not passed to autoUpdateDestroy.

@fedorovvvv fedorovvvv added bug Something isn't working help wanted Extra attention is needed labels Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants