diff --git a/.changeset/young-peaches-agree.md b/.changeset/young-peaches-agree.md new file mode 100644 index 0000000000..59abf5b867 --- /dev/null +++ b/.changeset/young-peaches-agree.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: remove buggy `validate_dynamic_component` check diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js index 43cc7b029f..5b1cfdbb05 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js @@ -348,14 +348,7 @@ export function build_component(node, component_name, context, anchor = context. b.thunk(/** @type {Expression} */ (context.visit(node.expression))), b.arrow( [b.id('$$anchor'), b.id(component_name)], - b.block([ - ...binding_initializers, - b.stmt( - dev - ? b.call('$.validate_dynamic_component', b.thunk(prev(b.id('$$anchor')))) - : prev(b.id('$$anchor')) - ) - ]) + b.block([...binding_initializers, b.stmt(prev(b.id('$$anchor')))]) ) ); }; diff --git a/packages/svelte/src/internal/client/index.js b/packages/svelte/src/internal/client/index.js index 51b9705902..cc7fa03dca 100644 --- a/packages/svelte/src/internal/client/index.js +++ b/packages/svelte/src/internal/client/index.js @@ -144,12 +144,7 @@ export { setContext, hasContext } from './runtime.js'; -export { - validate_binding, - validate_dynamic_component, - validate_each_keys, - validate_prop_bindings -} from './validate.js'; +export { validate_binding, validate_each_keys, validate_prop_bindings } from './validate.js'; export { raf } from './timing.js'; export { proxy } from './proxy.js'; export { create_custom_element } from './dom/elements/custom-element.js'; diff --git a/packages/svelte/src/internal/client/validate.js b/packages/svelte/src/internal/client/validate.js index 8792d02f0d..d8ec8b6900 100644 --- a/packages/svelte/src/internal/client/validate.js +++ b/packages/svelte/src/internal/client/validate.js @@ -14,31 +14,6 @@ function is_void(tag) { return void_element_names.test(tag) || tag.toLowerCase() === '!doctype'; } -/** - * @template Component - * @param {() => Component} component_fn - * @returns {Component} - */ -export function validate_dynamic_component(component_fn) { - try { - const instance = component_fn(); - - if (instance !== undefined && typeof instance !== 'object') { - e.svelte_component_invalid_this_value(); - } - - return instance; - } catch (err) { - const { message } = /** @type {Error} */ (err); - - if (typeof message === 'string' && message.indexOf('is not a function') !== -1) { - e.svelte_component_invalid_this_value(); - } - - throw err; - } -} - /** * @param {() => any} collection * @param {(item: any, index: number) => string} key_fn diff --git a/packages/svelte/tests/runtime-legacy/samples/component-not-constructor-dev/_config.js b/packages/svelte/tests/runtime-legacy/samples/component-not-constructor-dev/_config.js deleted file mode 100644 index a84708a774..0000000000 --- a/packages/svelte/tests/runtime-legacy/samples/component-not-constructor-dev/_config.js +++ /dev/null @@ -1,12 +0,0 @@ -import { test } from '../../test'; - -export default test({ - mode: ['client'], - - compileOptions: { - dev: true - }, - - error: - 'svelte_component_invalid_this_value\nThe `this={...}` property of a `` must be a Svelte component, if defined' -}); diff --git a/packages/svelte/tests/runtime-legacy/samples/component-not-constructor-dev/main.svelte b/packages/svelte/tests/runtime-legacy/samples/component-not-constructor-dev/main.svelte deleted file mode 100644 index 80f9f969e6..0000000000 --- a/packages/svelte/tests/runtime-legacy/samples/component-not-constructor-dev/main.svelte +++ /dev/null @@ -1,5 +0,0 @@ - - - diff --git a/packages/svelte/tests/runtime-legacy/samples/component-not-constructor2-dev/Sub.svelte b/packages/svelte/tests/runtime-legacy/samples/component-not-constructor2-dev/Sub.svelte deleted file mode 100644 index dd6d0bb1a9..0000000000 --- a/packages/svelte/tests/runtime-legacy/samples/component-not-constructor2-dev/Sub.svelte +++ /dev/null @@ -1 +0,0 @@ -
Sub
\ No newline at end of file diff --git a/packages/svelte/tests/runtime-legacy/samples/component-not-constructor2-dev/_config.js b/packages/svelte/tests/runtime-legacy/samples/component-not-constructor2-dev/_config.js deleted file mode 100644 index 9152c96354..0000000000 --- a/packages/svelte/tests/runtime-legacy/samples/component-not-constructor2-dev/_config.js +++ /dev/null @@ -1,24 +0,0 @@ -import { test } from '../../test'; - -export default test({ - compileOptions: { - dev: true - }, - get props() { - return { componentName: 'Sub' }; - }, - html: '
Sub
', - test({ assert, component, target }) { - component.componentName = 'Proxy'; - assert.htmlEqual(target.innerHTML, '
Sub
'); - try { - component.componentName = 'banana'; - throw new Error('Expected an error'); - } catch (err) { - assert.include( - /** @type {Error} */ (err).message, - 'svelte_component_invalid_this_value\nThe `this={...}` property of a `` must be a Svelte component, if defined' - ); - } - } -}); diff --git a/packages/svelte/tests/runtime-legacy/samples/component-not-constructor2-dev/main.svelte b/packages/svelte/tests/runtime-legacy/samples/component-not-constructor2-dev/main.svelte deleted file mode 100644 index 331fdfc385..0000000000 --- a/packages/svelte/tests/runtime-legacy/samples/component-not-constructor2-dev/main.svelte +++ /dev/null @@ -1,14 +0,0 @@ - - -