Skip to content

Commit

Permalink
fix: wait hydration to update $colorMode
Browse files Browse the repository at this point in the history
  • Loading branch information
Atinux committed Jul 28, 2020
1 parent 8d2c5db commit 7a873ab
Show file tree
Hide file tree
Showing 4 changed files with 2,971 additions and 2,604 deletions.
8 changes: 3 additions & 5 deletions lib/templates/plugin.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ const colorMode = window['<%= options.globalName %>']

export default function (ctx, inject) {
const $colorMode = new Vue({
data: {
preference: colorMode.preference,
value: colorMode.value,
unknown: colorMode.preference === 'system'
},
data: ctx.nuxtState.colorMode,
watch: {
preference (preference) {
if (preference === 'system') {
Expand Down Expand Up @@ -73,6 +69,8 @@ export default function (ctx, inject) {

if ($colorMode.unknown) {
window.onNuxtReady(() => {
$colorMode.preference = colorMode.preference
$colorMode.value = colorMode.value
$colorMode.unknown = false
})
}
Expand Down
4 changes: 4 additions & 0 deletions lib/templates/plugin.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@ export default function (ctx, inject) {
unknown: process.static || !ctx.req || preference === 'system'
}

ctx.beforeNuxtRender(({ nuxtState }) => {
nuxtState.colorMode = colorMode
})

inject('colorMode', colorMode)
}
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@
"lodash.template": "^4.5.0"
},
"devDependencies": {
"@babel/core": "latest",
"@babel/preset-env": "latest",
"@commitlint/cli": "latest",
"@commitlint/config-conventional": "latest",
"@nuxtjs/eslint-config": "latest",
"@nuxtjs/module-test-utils": "latest",
"@babel/core": "^7.10.5",
"@babel/preset-env": "^7.10.4",
"@commitlint/cli": "^9.1.1",
"@commitlint/config-conventional": "^9.1.1",
"@nuxtjs/eslint-config": "^3.1.0",
"@nuxtjs/module-test-utils": "^1.6.3",
"@nuxtjs/svg": "^0.1.11",
"babel-eslint": "latest",
"babel-jest": "latest",
"eslint": "latest",
"babel-jest": "^26.1.0",
"eslint": "^7.5.0",
"husky": "latest",
"jest": "latest",
"nuxt-edge": "latest",
"rollup": "latest",
"jest": "^26.1.0",
"nuxt-edge": "^2.14.1-26598267.60f68638",
"rollup": "^2.23.0",
"rollup-plugin-babel": "latest",
"rollup-plugin-terser": "latest",
"standard-version": "latest"
"rollup-plugin-terser": "^6.1.0",
"standard-version": "^8.0.2"
},
"publishConfig": {
"access": "public"
Expand Down

0 comments on commit 7a873ab

Please sign in to comment.