-
-
Notifications
You must be signed in to change notification settings - Fork 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
[Bug Report] Wrong first $vuetify.breakpoint value when using webpack-ssr #3436
Comments
It works when using a v-toolbar. |
I have been unable to reproduce this error. |
Versions and EnvironmentVuetify: 1.0.5 Reproduction repositoryhttps://github.com/peluprvi/vuetify-issue-3436 After F5 (window width = 960px)After window resize (and expected behavior) (window width = 960px) |
WorkaroundUse a computed prop that conditionally changes after nextTick on created hook: <script>
export default {
props: {
xsOnly: {
type: Boolean,
default: false
}
},
data: () => ({
reloaded: false
}),
computed: {
isXsOnly () {
return this.reloaded ? this.xsOnly || this.$vuetify.breakpoint.xsOnly : this.xsOnly
}
},
created () {
this.$nextTick(function () {
this.reloaded = true
})
}
}
</script> |
As I said in discord, this appears to be vuejs/vue#7063 but with classes this time. Try adding a ref to one of those v-layouts and see what happens. @peluprvi I would consider that bad advice, as it relies on timing. A better solution would be to use the data: () => ({
isHydrated: false
})
computed: {
breakpoint () { // just an example, could be one specific value if that's all you need
return this.isHydrated
? this.$vuetify.breakpoint
: // "empty" $breakpoint object with initial values
}
}
mounted () {
this.isHydrated = true
} |
I've opened a new issue vuejs/vue#7787, follow that for updates. |
Based on the response above I've made a simple nuxt plugin so that we don't have to use mounted hooks on every component that needs to use vuetify breakpoints
|
This did not make the cut for v1.3 and is being refactored for v2.0 |
None of the suggested solutions worked for me (tried them all) |
This is a bit of a hack and not for everyone, but I worked around the issue by triggering a breakpoint recalc in mounted: mounted() {
this.$vuetify.clientHeight--
this.$vuetify.clientHeight++
} If you dont mind there being a minor difference in the actual value, this works also: mounted() {
this.$vuetify.clientHeight -= 0.1
} |
Added a computed function to @kovsky0 's nuxt-plugin so the call-syntax is a bit prettier:
Then you can call it like |
This comment has been minimized.
This comment has been minimized.
This is what I have come up with loosely based on the comment by pantunchy: https://gist.github.com/douira/6d3f99fa4546adee470637467931ed19 |
This is getting pushed back from v1.2.0 (mid 2018!) to v3.0.0. I think this is important, as everyone developing nuxt with vuetify will face this issue, breaking hydration completely. @pantuchy 's solution works really well. I think it should be included by default in the create-nuxt-app when choosing vuetify. Also, it should be included in the docs. Do you think it would be a good idea to submit this as a PR to create-nuxt-app? Or is another solution under development? |
The breakpoints I had some difficulties with the other version of the plugin so I made this one. I don't know which one is preferable for performance and architecture quality. How to usePlace this file in export default {
plugins: ["~/plugins/breakpoint"]
} and then you can use WorkaroundSee more info: https://gist.github.com/douira/6d3f99fa4546adee470637467931ed19 import Vue from "vue"
//the properties of breakpoint that we want to mirror
const defaults = {
xs: true,
xsOnly: true,
sm: false,
smOnly: true,
smAndDown: true,
smAndUp: false,
md: false,
mdOnly: false,
mdAndDown: true,
mdAndUp: false,
lg: false,
lgOnly: false,
lgAndDown: true,
lgAndUp: false,
xl: false,
xlOnly: false
}
//create a property on the prototype of all instances that holds the breakpoint state
Vue.prototype.$breakpoint = new Vue({
data: () => ({ ...defaults })
})
export default async function({ app }) {
//init mixins and the watchers if they don't exist yet
app.mixins = app.mixins || []
app.watch = app.watch || {}
//create a watcher for each breakpoint
for (const prop in defaults) {
//the watcher sets the breakpoint prop to cause an update
app.watch[`$vuetify.breakpoint.${prop}`] = function(value) {
//update our mirrored value properly
this.$breakpoint[prop] = value
}
}
//add a mixin that does the client prop setting
app.mixins.push({
//here is the magic, if we set the state with the correct value on client init it works
mounted() {
//for all props that we are processing
for (const prop in defaults) {
//set the initial value from vuetify
this.$breakpoint[prop] = this.$vuetify.breakpoint[prop]
}
}
})
} |
Sorry @douira, your solution don't work 😢 If I change the viewport the app crashes with the following error:
Tried the solution provided by @pantuchy and this works. But it's just a workaround. |
Both are workarounds and work differently. Neither is a solution since they both do a similar thing; creating a reactive breakpoint object that also works in SSR even though Vuetify currently has none. I can't figure out what went wrong in your project since this stacktrace doesn't really say anything. Are you sure you're not using |
If someone is interested in a workaround for a vue-ts class style component.
|
Is this bug fixed? Because I keep getting the breakpoint value as xs even though my screen is lg. Thank you |
We kindly ask users to not comment on closed/resolved issues. If you believe that this issue has not been correctly resolved, please create a new issue showing the regression. If you have any additional questions, please reach out to us in our Discord community. |
Yes, the first render will always be XS. |
Versions and Environment
Vuetify: 1.0.4
Vue: 2.5.13
Browsers: Chrome 63.0.3239.132
OS: Windows 7
Steps to reproduce
Expected Behavior
Cards should be rendered side by side (row layout).
Actual Behavior
When hitting F5, cards are rendering one below the other (column layout) - that is the bug.
When resize the window, cards are rendering as expected (row layout).
When webpack compiles with the page previously opened, cards are rendering as expected (row layout).
Reproduction Link
https://codepen.io/anon/pen/rJRNrL
The text was updated successfully, but these errors were encountered: