Skip to content

Svelte 5: Portal'd content and multiple elements in same conditional #12440

Closed
@techniq

Description

@techniq

Describe the bug

If you portal content with an action, such as a simple:

<script>
  function portal(node) {
    document.body.appendChild(node)
  }
</script>

<div use:portal></div>

or something more robust like Svelte UX's portal and you have more than 1 element in a conditional with the portal'd content, such as

{#if show}
  <div class="backdrop"></div>
  <div class="dialog" use:portal>Dialog</div>
{/if}

then when the item is removed, it will remove more than the portal'd content (usually some subsequent elements).

However, if you put the portal'd content in it's own conditional, it works:

{#if show}
  <div class="backdrop" onclick={() => show = false} role="none"></div>
{/if}
{#if show}
  <div class="dialog" use:portal>Dialog</div>
{/if}

This appears to be the root issue of #12427 and currently affects Dialog and Drawer in Svelte UX (although I might add the workaround soon). See the video in this comment to see the issue visually.

Reproduction

  • Svelte 5 REPL
  • Svelte UX Dialog or or Drawer (or using the Source / Page Source / On this page at the top)

Logs

No response

System Info

`svelte@5.0.0-next.184`

Severity

blocking an upgrade

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting submitterneeds a reproduction, or clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions