Skip to content

Commit 6d16e92

Browse files
Revert hydration optimisation (#6290)
Co-authored-by: haveyaseen <[email protected]>
1 parent 341160f commit 6d16e92

File tree

11 files changed

+66
-45
lines changed

11 files changed

+66
-45
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Svelte changelog
22

3+
## Unreleased
4+
5+
* Revert hydration optimisation for the time being
6+
37
## 3.38.1
48

59
* Fix hydration regression ([#6274](https://github.com/sveltejs/svelte/issues/6274))

src/runtime/internal/Component.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { add_render_callback, flush, schedule_update, dirty_components } from './scheduler';
22
import { current_component, set_current_component } from './lifecycle';
33
import { blank_object, is_empty, is_function, run, run_all, noop } from './utils';
4-
import { children, detach, start_hydrating, end_hydrating } from './dom';
4+
import { children, detach } from './dom';
55
import { transition_in } from './transitions';
66

77
interface Fragment {
@@ -150,7 +150,6 @@ export function init(component, options, instance, create_fragment, not_equal, p
150150

151151
if (options.target) {
152152
if (options.hydrate) {
153-
start_hydrating();
154153
const nodes = children(options.target);
155154
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
156155
$$.fragment && $$.fragment!.l(nodes);
@@ -162,7 +161,6 @@ export function init(component, options, instance, create_fragment, not_equal, p
162161

163162
if (options.intro) transition_in(component.$$.fragment);
164163
mount_component(component, options.target, options.anchor, options.customElement);
165-
end_hydrating();
166164
flush();
167165
}
168166

src/runtime/internal/dom.ts

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,15 @@
11
import { has_prop } from './utils';
22

3-
// Track which nodes are claimed during hydration. Unclaimed nodes can then be removed from the DOM
4-
// at the end of hydration without touching the remaining nodes.
5-
let is_hydrating = false;
6-
const nodes_to_detach = new Set<Node>();
7-
8-
export function start_hydrating() {
9-
is_hydrating = true;
10-
}
11-
export function end_hydrating() {
12-
is_hydrating = false;
13-
14-
for (const node of nodes_to_detach) {
15-
node.parentNode.removeChild(node);
16-
}
17-
18-
nodes_to_detach.clear();
19-
}
20-
213
export function append(target: Node, node: Node) {
22-
if (is_hydrating) {
23-
nodes_to_detach.delete(node);
24-
}
25-
if (node.parentNode !== target) {
26-
target.appendChild(node);
27-
}
4+
target.appendChild(node);
285
}
296

307
export function insert(target: Node, node: Node, anchor?: Node) {
31-
if (is_hydrating) {
32-
nodes_to_detach.delete(node);
33-
}
34-
if (node.parentNode !== target || (anchor && node.nextSibling !== anchor)) {
35-
target.insertBefore(node, anchor || null);
36-
}
8+
target.insertBefore(node, anchor || null);
379
}
3810

3911
export function detach(node: Node) {
40-
if (is_hydrating) {
41-
nodes_to_detach.add(node);
42-
} else if (node.parentNode) {
43-
node.parentNode.removeChild(node);
44-
}
12+
node.parentNode.removeChild(node);
4513
}
4614

4715
export function destroy_each(iterations, detaching) {
@@ -186,9 +154,8 @@ export function children(element) {
186154
}
187155

188156
export function claim_element(nodes, name, attributes, svg) {
189-
while (nodes.length > 0) {
190-
const node = nodes.shift();
191-
157+
for (let i = 0; i < nodes.length; i += 1) {
158+
const node = nodes[i];
192159
if (node.nodeName === name) {
193160
let j = 0;
194161
const remove = [];
@@ -201,10 +168,7 @@ export function claim_element(nodes, name, attributes, svg) {
201168
for (let k = 0; k < remove.length; k++) {
202169
node.removeAttribute(remove[k]);
203170
}
204-
205-
return node;
206-
} else {
207-
detach(node);
171+
return nodes.splice(i, 1)[0];
208172
}
209173
}
210174

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<p>
2+
<span>1</span>
3+
<code>2</code>
4+
</p>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<p>
2+
<span>1</span>
3+
<code>2</code>
4+
</p>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export default {
2+
snapshot(target) {
3+
const p = target.querySelector('p');
4+
5+
return {
6+
p,
7+
span: p.querySelector('span'),
8+
code: p.querySelector('code')
9+
};
10+
},
11+
12+
test(assert, target, snapshot) {
13+
const p = target.querySelector('p');
14+
15+
assert.equal(p, snapshot.p);
16+
assert.equal(p.querySelector('span'), snapshot.span);
17+
assert.equal(p.querySelector('code'), snapshot.code);
18+
}
19+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<p>
2+
<span>1</span>
3+
{#if true}
4+
<code>2</code>
5+
{/if}
6+
</p>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>1 2 <span>3</span></p>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>1 2 <span>3</span></p>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export default {
2+
snapshot(target) {
3+
const p = target.querySelector('p');
4+
5+
return {
6+
p,
7+
text: p.childNodes[0],
8+
span: p.querySelector('span')
9+
};
10+
},
11+
12+
test(assert, target, snapshot) {
13+
const p = target.querySelector('p');
14+
15+
assert.equal(p, snapshot.p);
16+
assert.equal(p.childNodes[0], snapshot.text);
17+
assert.equal(p.querySelector('span'), snapshot.span);
18+
}
19+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>{1} 2 <span>3</span></p>

0 commit comments

Comments
 (0)