diff --git a/src/runtime/internal/Component.ts b/src/runtime/internal/Component.ts
index 10588a0804..ea3e9dafea 100644
--- a/src/runtime/internal/Component.ts
+++ b/src/runtime/internal/Component.ts
@@ -56,6 +56,9 @@ export function mount_component(component, target, anchor) {
const { fragment, on_mount, on_destroy, after_update } = component.$$;
fragment && fragment.m(target, anchor);
+
+ // custom element: call onMount in connectedCallback instead
+ if (component.shadowRoot) return;
// onMount happens before the initial afterUpdate
add_render_callback(() => {
@@ -176,6 +179,9 @@ if (typeof HTMLElement === 'function') {
// @ts-ignore todo: improve typings
this.appendChild(this.$$.slotted[key]);
}
+
+ const new_on_destroy = this.$$.on_mount.map(run).filter(is_function);
+ this.$$.on_destroy.push(...new_on_destroy);
}
attributeChangedCallback(attr, _oldValue, newValue) {
diff --git a/test/custom-elements/samples/oncreate/main.svelte b/test/custom-elements/samples/oncreate/main.svelte
index ed3980a28e..9ddf1880ec 100644
--- a/test/custom-elements/samples/oncreate/main.svelte
+++ b/test/custom-elements/samples/oncreate/main.svelte
@@ -4,8 +4,11 @@
import { onMount } from 'svelte';
export let wasCreated;
+ export let propsSetBeforeMount;
+ export let attrs;
onMount(() => {
wasCreated = true;
+ propsSetBeforeMount = attrs === 'should be set';
});
diff --git a/test/custom-elements/samples/oncreate/test.js b/test/custom-elements/samples/oncreate/test.js
index 11d76078f2..a85c09178d 100644
--- a/test/custom-elements/samples/oncreate/test.js
+++ b/test/custom-elements/samples/oncreate/test.js
@@ -2,7 +2,8 @@ import * as assert from 'assert';
import './main.svelte';
export default function (target) {
- target.innerHTML = '';
+ target.innerHTML = '';
const el = target.querySelector('my-app');
assert.ok(el.wasCreated);
+ assert.ok(el.propsSetBeforeMount);
}
\ No newline at end of file