Skip to content

Commit

Permalink
hydrating static content
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Jan 21, 2020
1 parent e93c991 commit a643c1d
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/compiler/compile/render_dom/wrappers/Element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ export default class ElementWrapper extends Wrapper {
this.add_classes(block);
this.add_manual_style_scoping(block);

if (nodes && this.renderer.options.hydratable && !this.void) {
if (nodes && this.renderer.options.hydratable && !this.void && !this.can_use_innerhtml) {
block.chunks.claim.push(
b`${this.node.children.length > 0 ? nodes : children}.forEach(@detach);`
);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compile/render_dom/wrappers/shared/Wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class Wrapper {
}
});

this.can_use_innerhtml = !renderer.options.hydratable;
this.can_use_innerhtml = true;
this.is_static_content = !renderer.options.hydratable;

block.wrappers.push(this);
Expand Down
5 changes: 5 additions & 0 deletions test/hydration/samples/static-content/_after.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<p>Hello world</p>
<p>Hello world</p>
<p>Hello world</p>
</div>
5 changes: 5 additions & 0 deletions test/hydration/samples/static-content/_before.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<p>Hello world</p>
<p>Hello world</p>
<p>Hello world</p>
</div>
5 changes: 5 additions & 0 deletions test/hydration/samples/static-content/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<p>Hello world</p>
<p>Hello world</p>
<p>Hello world</p>
</div>
5 changes: 5 additions & 0 deletions test/js/samples/hydrating-static-content/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
options: {
hydratable: true,
},
};
48 changes: 48 additions & 0 deletions test/js/samples/hydrating-static-content/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* generated by Svelte vX.Y.Z */
import {
SvelteComponent,
children,
claim_element,
detach,
element,
init,
insert,
noop,
safe_not_equal
} from "svelte/internal";

function create_fragment(ctx) {
let div;

return {
c() {
div = element("div");

div.innerHTML = `<p>Hello world</p>
<p>Hello world</p>
<p>Hello world</p>`;
},
l(nodes) {
div = claim_element(nodes, "DIV", {});
var div_nodes = children(div);
},
m(target, anchor) {
insert(target, div, anchor);
},
p: noop,
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(div);
}
};
}

class Component extends SvelteComponent {
constructor(options) {
super();
init(this, options, null, create_fragment, safe_not_equal, {});
}
}

export default Component;
5 changes: 5 additions & 0 deletions test/js/samples/hydrating-static-content/input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<p>Hello world</p>
<p>Hello world</p>
<p>Hello world</p>
</div>

0 comments on commit a643c1d

Please sign in to comment.