Skip to content

Svelte 5: When using svelte:element with this="input" or this="textarea", bind:this does not work. #10993

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

Closed
HighFunctioningSociopathSH opened this issue Mar 30, 2024 · 2 comments
Milestone

Comments

@HighFunctioningSociopathSH
Copy link

HighFunctioningSociopathSH commented Mar 30, 2024

Describe the bug

svelte:element with its this set to "input" or "textarea" doesn't update its bind:this anymore.

Reproduction

+page.svelte

<svelte:options runes />

<script lang="ts">
  let thisRef = $state<HTMLInputElement>();
  $inspect(thisRef); // thisRef remains undefined
</script>

<svelte:element this="input" bind:this={thisRef} />
<!-- <svelte:element this="textarea" bind:this={thisRef} /> -->
<!-- textarea doesn't work either -->

Logs

No response

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i7-12650H
    Memory: 4.71 GB / 15.63 GB
  Binaries:
    Node: 18.14.2 - C:\Program Files\nodejs\node.EXE
    npm: 9.7.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (122.0.2365.80)
    Internet Explorer: 11.0.22621.1
  
  For some reason, the npx command no longer shows my svelte information so my current svelte version is `^5.0.0-next.89`

Severity

blocking an upgrade

@brunnerh
Copy link
Member

Having two this referring to different things is a bit odd to begin with.
Maybe the Svelte 5 release could be used as an opportunity to change that?

E.g. use the tagName property instead:

<svelte:element tagName="input" bind:this={thisRef} />

@Rich-Harris
Copy link
Member

this was chosen because, as a keyword, it's unlikely to be used as a prop name. If we changed it, we would need to change <svelte:component> at the same time, so we would need to come up with two new names that we felt were unlikely to ever clash with prop names.

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

3 participants