Sfoglia il codice sorgente

fix(ssr): should not optimize root if conditions

fix #6907
Evan You 8 anni fa
parent
commit
4ad9a56b22
2 ha cambiato i file con 12 aggiunte e 1 eliminazioni
  1. 1 1
      src/server/optimizing-compiler/optimizer.js
  2. 11 0
      test/ssr/ssr-string.spec.js

+ 1 - 1
src/server/optimizing-compiler/optimizer.js

@@ -55,7 +55,7 @@ function walk (node: ASTNode, isRoot?: boolean) {
     if (node.ifConditions) {
       for (let i = 1, l = node.ifConditions.length; i < l; i++) {
         const block = node.ifConditions[i].block
-        walk(block)
+        walk(block, isRoot)
         check(block)
       }
     }

+ 11 - 0
test/ssr/ssr-string.spec.js

@@ -989,6 +989,17 @@ describe('SSR: renderToString', () => {
       done()
     })
   })
+
+  // #6907
+  it('should not optimize root if conditions', done => {
+    renderVmWithOptions({
+      data: { foo: 123 },
+      template: `<input :type="'text'" v-model="foo">`
+    }, res => {
+      expect(res).toBe(`<input type="text" data-server-rendered="true" value="123">`)
+      done()
+    })
+  })
 })
 
 function renderVmWithOptions (options, cb) {