You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to get a reference to the svelte component inside of the component file.
I'm using svelte to render customElement (with "tag" option).
The reason for getting a reference was the need for dispatching a composed event which can be picked up by the host page, beyond the web component's shadow DOM.
bind:this
I tried using bind:this on the top level element but that gives a reference to the specific element, not the root web component.
I can use bind:this in a container component like in the example but I would prefer to reference the component from inside the component (file) itself.
The issue #5517 that you linked to would be a better thing to follow for this. $$self isn't part of the API, which should be fairly obvious given the hoops you have to jump through to access it. It could stop working without warning at any time.
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
I wanted to get a reference to the svelte component inside of the component file.
I'm using svelte to render customElement (with "tag" option).
The reason for getting a reference was the need for dispatching a
composed
event which can be picked up by the host page, beyond the web component's shadow DOM.bind:this
I tried using
bind:this
on the top level element but that gives a reference to the specific element, not the root web component.bind:this
in a container component like in the example but I would prefer to reference the component from inside the component (file) itself.$$self
I saw a variable named
$$self
in the scope, which references the webComponent but using it givesValidationError $$self is an illegal variable name
I can turn the error to a warning using the compiler options of
errorMode="warn"
but I would prefer to keep the error mode as it is.
I can also use
eval('$$self')
which works but is not ideal and gives another compiler warningI'm also concerned with using an undocumented variable - I did not find documentation about
$$self
. Is it meant for internal use only?I noticed the
illegal variable name
issue can be resolved by adding$$self
to the list of reserved keywords for the svelte compilerRelated
<svelte:this />
tag rfcs#58Reproduction
https://svelte.dev/repl/71cb45d247f94ea5896f7de2303cbe8a?version=3.42.4
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: