diff --git a/src/core/index.js b/src/core/index.js index 7045332e083..b2a0cb8c5a2 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -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 } }) diff --git a/test/ssr/ssr-basic-renderer.spec.js b/test/ssr/ssr-basic-renderer.spec.js index 053bde1a00e..7cbacbee726 100644 --- a/test/ssr/ssr-basic-renderer.spec.js +++ b/test/ssr/ssr-basic-renderer.spec.js @@ -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: ` +
+ `, + created () { + ssrContext = this.$ssrContext + } + }), (err, result) => { + expect(err).toBeNull() + expect(ssrContext).toBeUndefined() + done() + }) + }) })