Skip to content

Commit

Permalink
fix(ssr): reference error when create $ssrContext for root component
Browse files Browse the repository at this point in the history
should not create $ssrContext for root component, because it doesn't has $vnode

#5941
  • Loading branch information
jkzing committed Jun 27, 2017
1 parent b5f08f3 commit 96d337a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Object.defineProperty(Vue.prototype, '$isServer', {
Object.defineProperty(Vue.prototype, '$ssrContext', {
get () {
/* istanbul ignore next */
return this.$vnode.ssrContext
return this.$vnode && this.$vnode.ssrContext
}
})

Expand Down
17 changes: 17 additions & 0 deletions test/ssr/ssr-basic-renderer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,21 @@ describe('SSR: basicRenderer', () => {
done()
})
})

// #5941
it('should work peoperly when accessing $ssrContext in root component', done => {
let ssrContext
renderToString(new Vue({
template: `
<div></div>
`,
created () {
ssrContext = this.$ssrContext
}
}), (err, result) => {
expect(err).toBeNull()
expect(ssrContext).toBeUndefined()
done()
})
})
})

0 comments on commit 96d337a

Please sign in to comment.