Skip to content

Commit

Permalink
ignore noscript when claiming
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau committed Feb 22, 2020
1 parent 98d58e0 commit 83fb842
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
7 changes: 1 addition & 6 deletions src/compiler/compile/render_dom/wrappers/Element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,7 @@ export default class ElementWrapper extends Wrapper {
render(block: Block, parent_node: Identifier, parent_nodes: Identifier) {
const { renderer } = this;

if (this.node.name === 'noscript') {
if (renderer.options.hydratable) {
block.chunks.claim.push(b`@claim_noscript(${parent_nodes});`);
}
return;
}
if (this.node.name === 'noscript') return;

if (this.slot_block) {
block = this.slot_block;
Expand Down
4 changes: 0 additions & 4 deletions src/runtime/internal/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ export function claim_space(nodes) {
return claim_text(nodes, ' ');
}

export function claim_noscript(nodes) {
detach(claim_element(nodes, 'NOSCRIPT', {}, false));
}

function find_comment(nodes, text, start) {
for (let i = start; i < nodes.length; i += 1) {
const node = nodes[i];
Expand Down
29 changes: 24 additions & 5 deletions test/runtime/samples/noscript-removal/_config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
export default {
html: `
<div>foo</div>
<div>foo<div>foo</div></div>
`,
ssrHtml: `
<noscript>foo</noscript>
<div>foo<noscript>foo</noscript></div>
<div>foo<div>foo<noscript>foo</noscript></div></div>
`,
test({ assert, target, compileOptions }) {
// if created on client side, should not build noscript
if (!compileOptions.hydratable) {
assert.equal(target.querySelectorAll('noscript').length, 0);
}

// it's okay not to remove the node during hydration
// will not be seen by user anyway
removeNoScript(target);

assert.htmlEqual(
target.innerHTML,
`
<div>foo</div>
<div>foo<div>foo</div></div>
`
);
}
};

function removeNoScript(target) {
target.querySelectorAll("noscript").forEach(elem => {
elem.parentNode.removeChild(elem);
});
}

0 comments on commit 83fb842

Please sign in to comment.