mirror of
https://github.com/sveltejs/svelte.git
synced 2024-11-30 08:56:14 +01:00
fix component hydration
This commit is contained in:
parent
0bbd917442
commit
dc29b2d466
@ -113,7 +113,6 @@ export default function visitComponent(
|
||||
}
|
||||
|
||||
const componentInitProperties = [
|
||||
`target: ${!isTopLevel ? state.parentNode : 'null'}`,
|
||||
`_root: ${block.component}._root`,
|
||||
];
|
||||
|
||||
@ -123,7 +122,7 @@ export default function visitComponent(
|
||||
|
||||
const childBlock = node._block;
|
||||
|
||||
node.children.forEach(child => {
|
||||
node.children.forEach((child: Node) => {
|
||||
visit(generator, childBlock, childState, child);
|
||||
});
|
||||
|
||||
@ -224,8 +223,12 @@ export default function visitComponent(
|
||||
|
||||
block.builders.init.addBlock(local.create);
|
||||
|
||||
const targetNode = state.parentNode || block.target;
|
||||
const anchorNode = state.parentNode ? 'null' : 'anchor';
|
||||
|
||||
block.builders.create.addLine(`${name}._fragment.create();`);
|
||||
block.builders.claim.addLine(`${name}._fragment.claim( ${state.parentNodes} );`);
|
||||
block.builders.mount.addLine(`${name}._fragment.mount( ${targetNode}, ${anchorNode} );` );
|
||||
|
||||
if (!local.update.isEmpty()) block.builders.update.addBlock(local.update);
|
||||
}
|
||||
|
@ -83,7 +83,6 @@ export function claimElement (nodes, name, attributes) {
|
||||
}
|
||||
}
|
||||
|
||||
console.trace('creating', name);
|
||||
return createElement(name);
|
||||
}
|
||||
|
||||
|
1
test/hydration/samples/component-in-element/Nested.html
Normal file
1
test/hydration/samples/component-in-element/Nested.html
Normal file
@ -0,0 +1 @@
|
||||
<p>nested</p>
|
3
test/hydration/samples/component-in-element/_after.html
Normal file
3
test/hydration/samples/component-in-element/_after.html
Normal file
@ -0,0 +1,3 @@
|
||||
<div>
|
||||
<p>nested</p>
|
||||
</div>
|
3
test/hydration/samples/component-in-element/_before.html
Normal file
3
test/hydration/samples/component-in-element/_before.html
Normal file
@ -0,0 +1,3 @@
|
||||
<div>
|
||||
<p>nested</p>
|
||||
</div>
|
21
test/hydration/samples/component-in-element/_config.js
Normal file
21
test/hydration/samples/component-in-element/_config.js
Normal file
@ -0,0 +1,21 @@
|
||||
export default {
|
||||
snapshot(target) {
|
||||
const div = target.querySelector('div');
|
||||
const p = target.querySelector('p');
|
||||
|
||||
return {
|
||||
div,
|
||||
p,
|
||||
text: p.childNodes[0]
|
||||
};
|
||||
},
|
||||
|
||||
test(assert, target, snapshot) {
|
||||
const div = target.querySelector('div');
|
||||
const p = target.querySelector('p');
|
||||
|
||||
assert.equal(div, snapshot.div);
|
||||
assert.equal(p, snapshot.p);
|
||||
assert.equal(p.childNodes[0], snapshot.text);
|
||||
}
|
||||
};
|
13
test/hydration/samples/component-in-element/main.html
Normal file
13
test/hydration/samples/component-in-element/main.html
Normal file
@ -0,0 +1,13 @@
|
||||
<div>
|
||||
<Nested/>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
import Nested from './Nested.html';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Nested
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user