From 83fb842efa715ca7f1c3b74b467b56bf08127716 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Sat, 22 Feb 2020 20:16:06 +0800 Subject: [PATCH] ignore noscript when claiming --- .../render_dom/wrappers/Element/index.ts | 7 +---- src/runtime/internal/dom.ts | 4 --- .../samples/noscript-removal/_config.js | 29 +++++++++++++++---- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/compiler/compile/render_dom/wrappers/Element/index.ts b/src/compiler/compile/render_dom/wrappers/Element/index.ts index ba66d83ffb..71e5260a9e 100644 --- a/src/compiler/compile/render_dom/wrappers/Element/index.ts +++ b/src/compiler/compile/render_dom/wrappers/Element/index.ts @@ -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; diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index a16570377c..fb715ff205 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -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]; diff --git a/test/runtime/samples/noscript-removal/_config.js b/test/runtime/samples/noscript-removal/_config.js index 657cff8870..3e911ac604 100644 --- a/test/runtime/samples/noscript-removal/_config.js +++ b/test/runtime/samples/noscript-removal/_config.js @@ -1,9 +1,4 @@ export default { - html: ` -
foo
- -
foo
foo
-`, ssrHtml: ` @@ -11,4 +6,28 @@ export default {
foo
foo
`, + 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, + ` +
foo
+
foo
foo
+ ` + ); + } }; + +function removeNoScript(target) { + target.querySelectorAll("noscript").forEach(elem => { + elem.parentNode.removeChild(elem); + }); +}