Skip to content

Commit

Permalink
Use mounted hook to avoid hydration errors
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberAP committed Jul 26, 2020
1 parent 04ca98a commit bec1857
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-component-media-queries",
"version": "1.0.0-alpha.4",
"version": "1.0.0-alpha.5",
"description": "Component-based media query matcher for Vue",
"main": "dist/index.js",
"module": "dist/index.es.js",
Expand Down
2 changes: 1 addition & 1 deletion src/MatchMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const MatchMedia = Vue.extend({
matches: this.fallback,
};
},
beforeMount() {
mounted() {
if (this.query) {
const matcher = this.matcher = window.matchMedia(this.query);
matcher.addListener(this.onMedia);
Expand Down
7 changes: 5 additions & 2 deletions src/MediaQueryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export const MediaQueryProvider = Vue.extend({
},
data(): Data {
const mediaQueries = {} as MediaQueriesProvision;
const { fallback } = this;
const { fallback, queries } = this;

Object.keys(queries).forEach(key => { mediaQueries[key] = false; });

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

return { mediaQueries, matchers: [] };
},
beforeMount() {
// Matching on mounted to avoid hydration errors
mounted() {
const { queries, mediaQueries } = this;

for (const key in queries) {
Expand Down

0 comments on commit bec1857

Please sign in to comment.