-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
fix(vue-app): fallback to global nuxt instance of $root
is not available
#9008
Conversation
return window.$nuxt if $root is not set
fixes #8995 |
$root
is not available
packages/vue-app/template/index.js
Outdated
@@ -46,7 +46,7 @@ Vue.component(Nuxt.name, Nuxt) | |||
|
|||
Object.defineProperty(Vue.prototype, '<%= globals.nuxt %>', { | |||
get() { | |||
return this.$root.$options.<%= globals.nuxt %> | |||
return this.$root.$options.<%= globals.nuxt %> || (process.client && typeof window !== 'undefined' && window.<%= globals.nuxt %>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried this will lead to inconsistent behaviour between client/server rendering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed we have to double-check this. Check-related issue #8995 is due to usage of the second app by vuetify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any inconsistant behaviour between client/server.
In the server it will be this.$root.$options.<%= globals.nuxt %>
if it's defined. If it's not defined, it will still be undefined, because window is not defined server side. I see there can be an error when accessing a property on undefined - the changed code would fix this.
On the client it won't change anything if $root
exists - only if it does not. Could you please explain, what the problem is?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks OK, but as @pi0 mentioned, let double check, a test for this would be test.
BTW, I think we can split this complex expression into if/else, sth like:
const globalNuxt = this.$root.$options.<%= globals.nuxt %>
if(process.client && !globalNuxt && window) {
return window.<%= globals.nuxt %>
}
return globalNuxt
I recently tried upgrading to 2.15.4, but I am still facing $root not available issue. What would rather work is - |
Types of changes
return window.$nuxt if $root is not set
Description
$nuxt was not always accessible (if $root was not set), so return the property from window object
fixes #8995
Checklist: