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

fix: correct parent component link for web components #7069

Closed
wants to merge 2 commits into from

Conversation

jsonn
Copy link

@jsonn jsonn commented Dec 29, 2021

This is a proof of concept for fixing the parent component link for nested web components, e.g. when using

   <my-parent-component>
      <my-child-component></my-child-component>
  </my-parent-component

we want the child to have a parent component link set appropriately, so that e.g. the context API (see #3422) works correctly. The test itself is a bit rough and likely can be optimized by checking for the $$ property first, but I'd like to get idea out first.

When nesting web components, the parent component link is currently not set up correctly. With this change, every parent node will be checked for having the SvelteElement constructor in its prototype chain. This can likely be optimized further by checking for the $$ component first.
}
return component;
}

export function init(component, options, instance, create_fragment, not_equal, props, append_styles, dirty = [-1]) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"init" function call in constructor of SvelteElement, can not get parentNode, so this PR can not fix the issue.

you can get parentNode in connectedCallback.

@baseballyama baseballyama added this to the 4.x milestone Feb 26, 2023
@benmccann benmccann changed the title [fix] [PoC] Fix parent component link for web components fix: correct parent component link for web components Mar 14, 2023
@dummdidumm
Copy link
Member

With #8457 this will be reworked, and it then will be possible to nest regular Svelte components within a Svelte custom element, which should fix the use cases for this. I think it would be a mistake to try to do special things for custom elements that happen to be written in Svelte - custom elements should have as much interoperability as possible and what library they were written in should be an implementation detail. Therefore closing.

@dummdidumm dummdidumm closed this Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants