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
  • Loading branch information
jkzing authored and yyx990803 committed Jun 29, 2017
1 parent 0cd6ef3 commit 5581654
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 5581654

Please sign in to comment.