Skip to content

Commit 73f80f2

Browse files
committed
use a simpler insert and append function when not compile with hydratable
1 parent fdd3d4b commit 73f80f2

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

src/compiler/compile/Component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ export default class Component {
267267
} else {
268268
let name = node.name.slice(1);
269269

270+
if (compile_options.hydratable) {
271+
if (internal_exports.has(`${name}_hydration`)) {
272+
name += '_hydration';
273+
}
274+
}
275+
270276
if (compile_options.dev) {
271277
if (internal_exports.has(`${name}_dev`)) {
272278
name += '_dev';

src/runtime/internal/dev.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { custom_event, append, insert, detach, listen, attr } from './dom';
1+
import { custom_event, append, append_hydration, insert, insert_hydration, detach, listen, attr } from './dom';
22
import { SvelteComponent } from './Component';
33

44
export function dispatch_dev<T=any>(type: string, detail?: T) {
@@ -10,11 +10,21 @@ export function append_dev(target: Node, node: Node) {
1010
append(target, node);
1111
}
1212

13+
export function append_hydration_dev(target: Node, node: Node) {
14+
dispatch_dev('SvelteDOMInsert', { target, node });
15+
append_hydration(target, node);
16+
}
17+
1318
export function insert_dev(target: Node, node: Node, anchor?: Node) {
1419
dispatch_dev('SvelteDOMInsert', { target, node, anchor });
1520
insert(target, node, anchor);
1621
}
1722

23+
export function insert_hydration_dev(target: Node, node: Node, anchor?: Node) {
24+
dispatch_dev('SvelteDOMInsert', { target, node, anchor });
25+
insert_hydration(target, node, anchor);
26+
}
27+
1828
export function detach_dev(node: Node) {
1929
dispatch_dev('SvelteDOMRemove', { node });
2030
detach(node);

src/runtime/internal/dom.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ function init_hydrate(target: NodeEx) {
112112
}
113113
}
114114

115-
export function append(target: NodeEx, node: NodeEx) {
115+
export function append(target: Node, node: Node) {
116+
target.appendChild(node);
117+
}
118+
119+
export function append_hydration(target: NodeEx, node: NodeEx) {
116120
if (is_hydrating) {
117121
init_hydrate(target);
118122

@@ -129,9 +133,13 @@ export function append(target: NodeEx, node: NodeEx) {
129133
}
130134
}
131135

132-
export function insert(target: NodeEx, node: NodeEx, anchor?: NodeEx) {
136+
export function insert(target: Node, node: Node, anchor?: Node) {
137+
target.insertBefore(node, anchor || null);
138+
}
139+
140+
export function insert_hydration(target: NodeEx, node: NodeEx, anchor?: NodeEx) {
133141
if (is_hydrating && !anchor) {
134-
append(target, node);
142+
append_hydration(target, node);
135143
} else if (node.parentNode !== target || node.nextSibling != anchor) {
136144
target.insertBefore(node, anchor || null);
137145
}

0 commit comments

Comments
 (0)