From 55816543c46e75aa53481ac95a89ff6f87a2d704 Mon Sep 17 00:00:00 2001 From: JK Date: Thu, 29 Jun 2017 12:37:03 +0800 Subject: [PATCH] fix(ssr): reference error when create $ssrContext for root component (#5981) fix #5941 --- src/core/index.js | 2 +- test/ssr/ssr-basic-renderer.spec.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core/index.js b/src/core/index.js index 7045332e08..b2a0cb8c5a 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 053bde1a00..7cbacbee72 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() + }) + }) })