Skip to content

Commit 5e7bd0d

Browse files
committed
protect
protect protect
1 parent 9eeb05a commit 5e7bd0d

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

packages/svelte/src/internal/client/dom/blocks/slot.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { DEV } from 'esm-env';
12
import { hydrate_next, hydrating } from '../hydration.js';
3+
import { validated_snippets } from './snippet.js';
24

35
/**
46
* @param {Comment} anchor
@@ -12,7 +14,18 @@ export function slot(anchor, $$props, name, slot_props, fallback_fn) {
1214
hydrate_next();
1315
}
1416

15-
var slot_fn = $$props.$$slots?.[name] || $$props[name];
17+
var slot_fn = $$props.$$slots?.[name];
18+
19+
if (slot_fn === undefined) {
20+
var possible_snippet = $$props[name];
21+
if (
22+
typeof possible_snippet === 'function' &&
23+
(!DEV || validated_snippets.has(possible_snippet))
24+
) {
25+
slot_fn = possible_snippet;
26+
}
27+
}
28+
1629
// Interop: Can use snippets to fill slots
1730
var is_interop = false;
1831
if (slot_fn === true) {

packages/svelte/src/internal/client/dom/blocks/snippet.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { DEV } from 'esm-env';
1616
import { get_first_child, get_next_sibling } from '../operations.js';
1717
import { noop } from '../../../shared/utils.js';
1818

19+
export var validated_snippets = new WeakSet();
20+
1921
/**
2022
* @template {(node: TemplateNode, ...args: any[]) => void} SnippetFn
2123
* @param {TemplateNode} node
@@ -60,7 +62,7 @@ export function snippet(node, get_snippet, ...args) {
6062
* @param {(node: TemplateNode, ...args: any[]) => void} fn
6163
*/
6264
export function wrap_snippet(component, fn) {
63-
return (/** @type {TemplateNode} */ node, /** @type {any[]} */ ...args) => {
65+
var wrapped_snippet = (/** @type {TemplateNode} */ node, /** @type {any[]} */ ...args) => {
6466
var previous_component_function = dev_current_component_function;
6567
set_dev_current_component_function(component);
6668

@@ -70,6 +72,10 @@ export function wrap_snippet(component, fn) {
7072
set_dev_current_component_function(previous_component_function);
7173
}
7274
};
75+
if (DEV) {
76+
validated_snippets.add(wrapped_snippet);
77+
}
78+
return wrapped_snippet;
7379
}
7480

7581
/**

0 commit comments

Comments
 (0)