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

Inconsistent bind:this value on svelte:component this=undefined #6848

Closed
mvolfik opened this issue Oct 16, 2021 · 1 comment
Closed

Inconsistent bind:this value on svelte:component this=undefined #6848

mvolfik opened this issue Oct 16, 2021 · 1 comment

Comments

@mvolfik
Copy link

mvolfik commented Oct 16, 2021

Describe the bug

{#if show}
  <svelte:component this={comp} bind:this={instance} />
{/if}

Start with show=true, comp=Foo. Instance correctly contains the props and state of the component. Now do comp=undefined (or any falsy value, according to docs), the component is unmounted from DOM, state is removed from the instance object, but the rest (such as export function and various internal methods) remains on the object from the last comp before the falsy value.

In the repl linked below, this is checked by calling the exported function - in console you can see it repeatedly logging.

Now if you do show=false, the component is uninitialized and instance becomes null - same as when you have a normal component with bind:this. Now if you do show=true again, instance remains null, until you change comp to an actual component again.

I'd expect that the component should be fully removed and bind:this={instance} set to null as soon as the this={comp} is unset (set to falsy value).


Related to #1489 (old, then fixed - was svelte v2?)

Reproduction

https://svelte.dev/repl/c477b15230e347e19436325f2589665c?version=3.43.2

Logs

No response

System Info

Repl: v3.43.2

  System:
    OS: Linux 5.4 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i3-3110M CPU @ 2.40GHz
    Memory: 227.30 MB / 7.35 GB
    Container: Yes
    Shell: 3.1.0 - /usr/bin/fish
  Binaries:
    Node: 14.18.1 - /usr/bin/node
    Yarn: 1.22.11 - ~/.local/bin/yarn
    npm: 7.24.1 - ~/.local/bin/npm
  Browsers:
    Chromium: 94.0.4606.81
    Firefox: 93.0
  npmPackages:
    svelte: ^3.43.2 => 3.43.2 
    vite: ^2.6.7 => 2.6.7

Severity

annoyance

@dummdidumm
Copy link
Member

Fixed in Svelte 5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants