11/** @import { Snippet } from 'svelte' */
2- /** @import { Effect, TemplateNode } from '#client' */
2+ /** @import { TemplateNode } from '#client' */
33/** @import { Getters } from '#shared' */
44import { EFFECT_TRANSPARENT , ELEMENT_NODE } from '#client/constants' ;
5- import { branch , block , destroy_effect , teardown } from '../../reactivity/effects.js' ;
5+ import { block , teardown } from '../../reactivity/effects.js' ;
66import {
77 dev_current_component_function ,
88 set_dev_current_component_function
@@ -14,8 +14,8 @@ import * as w from '../../warnings.js';
1414import * as e from '../../errors.js' ;
1515import { DEV } from 'esm-env' ;
1616import { get_first_child , get_next_sibling } from '../operations.js' ;
17- import { noop } from '../../../shared/utils.js' ;
1817import { prevent_snippet_stringification } from '../../../shared/validate.js' ;
18+ import { BranchManager } from './branches.js' ;
1919
2020/**
2121 * @template {(node: TemplateNode, ...args: any[]) => void} SnippetFn
@@ -25,33 +25,17 @@ import { prevent_snippet_stringification } from '../../../shared/validate.js';
2525 * @returns {void }
2626 */
2727export function snippet ( node , get_snippet , ...args ) {
28- var anchor = node ;
29-
30- /** @type {SnippetFn | null | undefined } */
31- // @ts -ignore
32- var snippet = noop ;
33-
34- /** @type {Effect | null } */
35- var snippet_effect ;
28+ var branches = new BranchManager ( node ) ;
3629
3730 block ( ( ) => {
38- if ( snippet === ( snippet = get_snippet ( ) ) ) return ;
31+ const snippet = get_snippet ( ) ;
3932
40- if ( snippet_effect ) {
41- destroy_effect ( snippet_effect ) ;
42- snippet_effect = null ;
43- }
44-
45- if ( DEV && snippet == null ) {
33+ if ( snippet == null ) {
4634 e . invalid_snippet ( ) ;
4735 }
4836
49- snippet_effect = branch ( ( ) => /** @type { SnippetFn } */ ( snippet ) ( anchor , ...args ) ) ;
37+ branches . ensure ( snippet , ( anchor ) => snippet ( anchor , ...args ) ) ;
5038 } , EFFECT_TRANSPARENT ) ;
51-
52- if ( hydrating ) {
53- anchor = hydrate_node ;
54- }
5539}
5640
5741/**
0 commit comments