Skip to content

Commit bec1857

Browse files
committed
Use mounted hook to avoid hydration errors
1 parent 04ca98a commit bec1857

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-component-media-queries",
3-
"version": "1.0.0-alpha.4",
3+
"version": "1.0.0-alpha.5",
44
"description": "Component-based media query matcher for Vue",
55
"main": "dist/index.js",
66
"module": "dist/index.es.js",

src/MatchMedia.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const MatchMedia = Vue.extend({
3434
matches: this.fallback,
3535
};
3636
},
37-
beforeMount() {
37+
mounted() {
3838
if (this.query) {
3939
const matcher = this.matcher = window.matchMedia(this.query);
4040
matcher.addListener(this.onMedia);

src/MediaQueryProvider.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ export const MediaQueryProvider = Vue.extend({
2929
},
3030
data(): Data {
3131
const mediaQueries = {} as MediaQueriesProvision;
32-
const { fallback } = this;
32+
const { fallback, queries } = this;
33+
34+
Object.keys(queries).forEach(key => { mediaQueries[key] = false; });
3335

3436
if (fallback) {
3537
if (Array.isArray(fallback)) {
@@ -41,7 +43,8 @@ export const MediaQueryProvider = Vue.extend({
4143

4244
return { mediaQueries, matchers: [] };
4345
},
44-
beforeMount() {
46+
// Matching on mounted to avoid hydration errors
47+
mounted() {
4548
const { queries, mediaQueries } = this;
4649

4750
for (const key in queries) {

0 commit comments

Comments
 (0)