-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot read property 'ssrContext' of undefined #5941
Comments
https://github.com/vuejs/vue/blob/dev/src/core/index.js#L11-L16 |
@JounQin 👍 Thank you for giving the information, which has dispelled my doubt. This changed code got be ok: if (this.$vnode && this.$vnode.ssrContext) {
this.$ssrContext.title = title
} But then again, this kind of code is very confusing for debugging and maintaining. How would I know $ssrContext is ready to use, even when this below code is not safe. if (this.$ssrContext) {
this.$ssrContext.title = title
} The source code https://github.com/vuejs/vue/blob/dev/src/core/index.js#L11-L16 should be optimized like: Object.defineProperty(Vue.prototype, '$ssrContext', {
get () {
/* istanbul ignore next */
if(this.$vnode){
return this.$vnode.ssrContext
}
}
}) |
This only happens for the root component because it doesn't have |
should not create $ssrContext for root component, because it doesn't has $vnode vuejs#5941
@liamwang for me the |
Version
2.3.4
Reproduction link
https://github.com/vuejs/vue-hackernews-2.0/blob/master/src/util/title.js#L13
Steps to reproduce
git clone https://github.com/vuejs/vue-hackernews-2.0.git
Change /src/util/title.js file like this:
According to functional and robustness, the changed code should be ok as normal thinking.
按照正常的编程思路,修改后的代码应该更加严谨才是
npm install & npm run dev
open browser, enter http://localhost:8080
What is expected?
The
if
condition statement ensuredthis.$ssrContext
to be not undefined when trying to settitle
a value on it. It shoud be ok as normal expected.What is actually happening?
Error trace in console:
Error in browser:
500 | Internal Server Error
I suppose it is a bug of vue-server-renderer. If not, what happened?
The text was updated successfully, but these errors were encountered: