Skip to content

Commit ee4f65f

Browse files
committed
delete delete delete
1 parent 3ea2d51 commit ee4f65f

File tree

13 files changed

+243
-323
lines changed

13 files changed

+243
-323
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
} from '../../runtime.js';
1111
import { destroy_effect, pause_effect, render_effect } from '../../reactivity/effects.js';
1212
import { DESTROYED, INERT } from '../../constants.js';
13-
import { create_block } from './utils.js';
1413

1514
/**
1615
* @template V
@@ -22,8 +21,6 @@ import { create_block } from './utils.js';
2221
* @returns {void}
2322
*/
2423
export function await_block(anchor, get_input, pending_fn, then_fn, catch_fn) {
25-
const block = create_block();
26-
2724
const component_context = current_component_context;
2825

2926
hydrate_block_anchor(anchor);
@@ -48,7 +45,7 @@ export function await_block(anchor, get_input, pending_fn, then_fn, catch_fn) {
4845
set_current_effect(branch);
4946
set_current_reaction(branch); // TODO do we need both?
5047
set_current_component_context(component_context);
51-
var effect = render_effect(() => fn(anchor, value), {}, true);
48+
var effect = render_effect(() => fn(anchor, value), true);
5249
set_current_component_context(null);
5350
set_current_reaction(null);
5451
set_current_effect(null);
@@ -83,7 +80,7 @@ export function await_block(anchor, get_input, pending_fn, then_fn, catch_fn) {
8380
destroy_effect(pending_effect);
8481
}
8582

86-
pending_effect = render_effect(() => pending_fn(anchor), {}, true);
83+
pending_effect = render_effect(() => pending_fn(anchor), true);
8784
}
8885

8986
if (then_effect) pause(then_effect);
@@ -117,10 +114,10 @@ export function await_block(anchor, get_input, pending_fn, then_fn, catch_fn) {
117114
destroy_effect(then_effect);
118115
}
119116

120-
then_effect = render_effect(() => then_fn(anchor, input), {}, true);
117+
then_effect = render_effect(() => then_fn(anchor, input), true);
121118
}
122119
}
123-
}, block);
120+
});
124121

125122
branch.ondestroy = () => {
126123
// TODO this sucks, tidy it up

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

Lines changed: 98 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
import { source, mutable_source, set } from '../../reactivity/sources.js';
2828
import { is_array, is_frozen, map_get, map_set } from '../../utils.js';
2929
import { STATE_SYMBOL } from '../../constants.js';
30-
import { create_block } from './utils.js';
3130

3231
var NEW_ITEM = -1;
3332
var LIS_ITEM = -2;
@@ -56,8 +55,6 @@ export function set_current_each_item(item) {
5655
* @returns {void}
5756
*/
5857
function each(anchor, get_collection, flags, get_key, render_fn, fallback_fn, reconcile_fn) {
59-
var block = create_block();
60-
6158
/** @type {import('#client').EachState} */
6259
var state = { flags, items: [] };
6360

@@ -72,124 +69,116 @@ function each(anchor, get_collection, flags, get_key, render_fn, fallback_fn, re
7269
/** @type {import('#client').Effect | null} */
7370
var fallback = null;
7471

75-
var effect = render_effect(
76-
() => {
77-
var collection = get_collection();
72+
var effect = render_effect(() => {
73+
var collection = get_collection();
7874

79-
var array = is_array(collection)
80-
? collection
81-
: collection == null
82-
? []
83-
: Array.from(collection);
75+
var array = is_array(collection)
76+
? collection
77+
: collection == null
78+
? []
79+
: Array.from(collection);
8480

85-
var keys = get_key === null ? array : array.map(get_key);
81+
var keys = get_key === null ? array : array.map(get_key);
8682

87-
var length = array.length;
83+
var length = array.length;
8884

89-
// If we are working with an array that isn't proxied or frozen, then remove strict equality and ensure the items
90-
// are treated as reactive, so they get wrapped in a signal.
91-
var flags = state.flags;
92-
if ((flags & EACH_IS_STRICT_EQUALS) !== 0 && !is_frozen(array) && !(STATE_SYMBOL in array)) {
93-
flags ^= EACH_IS_STRICT_EQUALS;
85+
// If we are working with an array that isn't proxied or frozen, then remove strict equality and ensure the items
86+
// are treated as reactive, so they get wrapped in a signal.
87+
var flags = state.flags;
88+
if ((flags & EACH_IS_STRICT_EQUALS) !== 0 && !is_frozen(array) && !(STATE_SYMBOL in array)) {
89+
flags ^= EACH_IS_STRICT_EQUALS;
9490

95-
// Additionally if we're in an keyed each block, we'll need ensure the items are all wrapped in signals.
96-
if ((flags & EACH_KEYED) !== 0 && (flags & EACH_ITEM_REACTIVE) === 0) {
97-
flags ^= EACH_ITEM_REACTIVE;
98-
}
91+
// Additionally if we're in an keyed each block, we'll need ensure the items are all wrapped in signals.
92+
if ((flags & EACH_KEYED) !== 0 && (flags & EACH_ITEM_REACTIVE) === 0) {
93+
flags ^= EACH_ITEM_REACTIVE;
9994
}
95+
}
10096

101-
/** `true` if there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */
102-
let mismatch = false;
103-
104-
if (hydrating) {
105-
var is_else =
106-
/** @type {Comment} */ (current_hydration_fragment?.[0])?.data === 'ssr:each_else';
97+
/** `true` if there was a hydration mismatch. Needs to be a `let` or else it isn't treeshaken out */
98+
let mismatch = false;
99+
100+
if (hydrating) {
101+
var is_else =
102+
/** @type {Comment} */ (current_hydration_fragment?.[0])?.data === 'ssr:each_else';
103+
104+
if (is_else !== (length === 0)) {
105+
// hydration mismatch — remove the server-rendered DOM and start over
106+
remove(current_hydration_fragment);
107+
set_current_hydration_fragment(null);
108+
mismatch = true;
109+
} else if (is_else) {
110+
// Remove the each_else comment node or else it will confuse the subsequent hydration algorithm
111+
/** @type {import('#client').TemplateNode[]} */ (current_hydration_fragment).shift();
112+
}
113+
}
107114

108-
if (is_else !== (length === 0)) {
109-
// hydration mismatch — remove the server-rendered DOM and start over
110-
remove(current_hydration_fragment);
111-
set_current_hydration_fragment(null);
115+
// this is separate to the previous block because `hydrating` might change
116+
if (hydrating) {
117+
var b_items = [];
118+
119+
// Hydrate block
120+
var hydration_list = /** @type {import('#client').TemplateNode[]} */ (
121+
current_hydration_fragment
122+
);
123+
var hydrating_node = hydration_list[0];
124+
125+
for (var i = 0; i < length; i++) {
126+
var fragment = get_hydration_fragment(hydrating_node);
127+
set_current_hydration_fragment(fragment);
128+
if (!fragment) {
129+
// If fragment is null, then that means that the server rendered less items than what
130+
// the client code specifies -> break out and continue with client-side node creation
112131
mismatch = true;
113-
} else if (is_else) {
114-
// Remove the each_else comment node or else it will confuse the subsequent hydration algorithm
115-
/** @type {import('#client').TemplateNode[]} */ (current_hydration_fragment).shift();
132+
break;
116133
}
117-
}
118134

119-
// this is separate to the previous block because `hydrating` might change
120-
if (hydrating) {
121-
var b_items = [];
135+
b_items[i] = create_item(array[i], keys?.[i], i, render_fn, flags);
122136

123-
// Hydrate block
124-
var hydration_list = /** @type {import('#client').TemplateNode[]} */ (
125-
current_hydration_fragment
137+
// TODO helperise this
138+
hydrating_node = /** @type {import('#client').TemplateNode} */ (
139+
/** @type {Node} */ (
140+
/** @type {Node} */ (fragment[fragment.length - 1] || hydrating_node).nextSibling
141+
).nextSibling
126142
);
127-
var hydrating_node = hydration_list[0];
128-
129-
for (var i = 0; i < length; i++) {
130-
var fragment = get_hydration_fragment(hydrating_node);
131-
set_current_hydration_fragment(fragment);
132-
if (!fragment) {
133-
// If fragment is null, then that means that the server rendered less items than what
134-
// the client code specifies -> break out and continue with client-side node creation
135-
mismatch = true;
136-
break;
137-
}
138-
139-
b_items[i] = create_item(array[i], keys?.[i], i, render_fn, flags);
140-
141-
// TODO helperise this
142-
hydrating_node = /** @type {import('#client').TemplateNode} */ (
143-
/** @type {Node} */ (
144-
/** @type {Node} */ (fragment[fragment.length - 1] || hydrating_node).nextSibling
145-
).nextSibling
146-
);
147-
}
143+
}
148144

149-
remove_excess_hydration_nodes(hydration_list, hydrating_node);
145+
remove_excess_hydration_nodes(hydration_list, hydrating_node);
150146

151-
state.items = b_items;
152-
}
147+
state.items = b_items;
148+
}
153149

154-
if (!hydrating) {
155-
// TODO add 'empty controlled block' optimisation here
156-
reconcile_fn(array, state, anchor, render_fn, flags, keys);
157-
}
150+
if (!hydrating) {
151+
// TODO add 'empty controlled block' optimisation here
152+
reconcile_fn(array, state, anchor, render_fn, flags, keys);
153+
}
158154

159-
if (fallback_fn !== null) {
160-
if (length === 0) {
161-
if (fallback) {
162-
resume_effect(fallback);
163-
} else {
164-
fallback = render_effect(
165-
() => {
166-
var dom = fallback_fn(anchor);
167-
168-
return () => {
169-
if (dom !== undefined) {
170-
remove(dom);
171-
}
172-
};
173-
},
174-
block,
175-
true
176-
);
177-
}
178-
} else if (fallback !== null) {
179-
pause_effect(fallback, () => {
180-
fallback = null;
181-
});
155+
if (fallback_fn !== null) {
156+
if (length === 0) {
157+
if (fallback) {
158+
resume_effect(fallback);
159+
} else {
160+
fallback = render_effect(() => {
161+
var dom = fallback_fn(anchor);
162+
163+
return () => {
164+
if (dom !== undefined) {
165+
remove(dom);
166+
}
167+
};
168+
}, true);
182169
}
170+
} else if (fallback !== null) {
171+
pause_effect(fallback, () => {
172+
fallback = null;
173+
});
183174
}
175+
}
184176

185-
if (mismatch) {
186-
// Set a fragment so that Svelte continues to operate in hydration mode
187-
set_current_hydration_fragment([]);
188-
}
189-
},
190-
block,
191-
false
192-
);
177+
if (mismatch) {
178+
// Set a fragment so that Svelte continues to operate in hydration mode
179+
set_current_hydration_fragment([]);
180+
}
181+
});
193182

194183
effect.ondestroy = () => {
195184
for (var item of state.items) {
@@ -618,19 +607,15 @@ function create_item(value, key, index, render_fn, flags) {
618607
try {
619608
current_each_item = item;
620609

621-
item.e = render_effect(
622-
() => {
623-
var dom = render_fn(null, item.v, item.i);
610+
item.e = render_effect(() => {
611+
var dom = render_fn(null, item.v, item.i);
624612

625-
return () => {
626-
if (dom !== undefined) {
627-
remove(dom);
628-
}
629-
};
630-
},
631-
item,
632-
true
633-
);
613+
return () => {
614+
if (dom !== undefined) {
615+
remove(dom);
616+
}
617+
};
618+
}, true);
634619

635620
return item;
636621
} finally {

0 commit comments

Comments
 (0)