Skip to content

Mountng component on iFrame does not change the scope. #15500

@jjagielka

Description

@jjagielka

Describe the bug

When component is mounted in the iframe and internally it uses the document, that document points to parent instance not to the iframe one.

Expected behavour:
Component inside iframe should have its scope as iframe not the parent scope.

Reproduction

<!-- Component.svelte -->
<script>
  import { onMount } from "svelte";

  let { name } = $props();

  onMount(() => {
    document.querySelector("#target").textContent = "target=" + name;
  });
</script>

{name}
<q><span id="target">inital text</span></q>
<!--  App.svelte -->
<script>
   import Comp from "Comp.svelte";

  function onload(ev) {
    mount(Comp, { target: ev.target.contentDocument?.body });
  }
</script>

<Comp />

<iframe {onload} title="iframe"></iframe>

Output

direct "target=iframe"
iframe "initial text"

Logs

System Info

System:
    OS: Linux 6.12 Arch Linux
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-11390H @ 3.40GHz
    Memory: 11.06 GB / 31.09 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 23.9.0 - /usr/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 11.2.0 - /usr/bin/npm
    pnpm: 10.6.2 - /usr/bin/pnpm
  Browsers:
    Chromium: 134.0.6998.88
  npmPackages:
    svelte: ^5.23.0 => 5.23.0

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions