Skip to content

fix: correct parent component link for web components #7069

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
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/runtime/internal/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,24 @@ function make_dirty(component, i) {
component.$$.dirty[(i / 31) | 0] |= (1 << (i % 31));
}

function is_svelte_element(component) {
while (component) {
if (component.constructor === SvelteElement)
return true;
component = Object.getPrototypeOf(component);
}
return false;
}

function find_containing_component(component) {
while (component && !is_svelte_element(component)) {
component = component.parentNode;
}
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.

const parent_component = current_component;
const parent_component = options.customElement ? find_containing_component(component.parentNode) : current_component;
set_current_component(component);

const $$: T$$ = component.$$ = {
Expand Down