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: add symbol to components to properly validate them #12452

Next Next commit
fix: more precise validate_dynamic_component
  • Loading branch information
paoloricciuti committed Jul 15, 2024
commit 19f6abb81d8cda4a54e7a7da9c9888cad5fd2a31
5 changes: 5 additions & 0 deletions .changeset/gold-pumpkins-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 1,5 @@
---
'svelte': patch
---

fix: more precise `validate_dynamic_component`
6 changes: 5 additions & 1 deletion packages/svelte/src/internal/client/validate.js
Original file line number Diff line number Diff line change
@@ -1,6 1,7 @@
import { untrack } from './runtime.js';
import { get_descriptor, is_array } from '../shared/utils.js';
import * as e from './errors.js';
import { validate_component } from '../shared/validate.js';

/** regex of all html void element names */
const void_element_names =
Expand Down Expand Up @@ -28,7 29,10 @@ export function validate_dynamic_component(component_fn) {
} catch (err) {
const { message } = /** @type {Error} */ (err);

if (typeof message === 'string' && message.indexOf('is not a function') !== -1) {
if (
typeof message === 'string' &&
message.indexOf(`${validate_component.name}(...) is not a function`) !== -1
) {
e.svelte_component_invalid_this_value();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 1,5 @@
<script>
let { prop } = $props();
</script>

{prop}
Original file line number Diff line number Diff line change
@@ -0,0 1,9 @@
import { test } from '../../test';

export default test({
expect_unhandled_rejections: true,
error: 'is not a function',
compileOptions: {
dev: true
}
});
Original file line number Diff line number Diff line change
@@ -0,0 1,9 @@
<script>
import A from "./A.svelte";
</script>

{#snippet snip(comp, func)}
<svelte:component this={comp} prop={func(10)}></svelte:component>
{/snippet}

{@render snip(A)}
Loading