Skip to content

Commit b4f6b3c

Browse files
author
Guillaume Chau
committed
fix(ui): darkMode lost on cache reset
1 parent fd92852 commit b4f6b3c

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

packages/@vue/cli-ui/src/components/StatusBar.vue

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,6 @@ export default {
166166
167167
async applyDarkMode (enabled) {
168168
localStorage.setItem('vue-ui-dark-mode', enabled.toString())
169-
const el = document.getElementsByTagName('html')[0]
170-
if (enabled) {
171-
el.classList.add('vue-ui-dark-mode')
172-
} else {
173-
el.classList.remove('vue-ui-dark-mode')
174-
}
175169
await this.$apollo.mutate({
176170
mutation: DARK_MODE_SET,
177171
variables: {

packages/@vue/cli-ui/src/state/resolvers.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ export default {
2222
darkMode: enabled
2323
}
2424
cache.writeData({ data })
25+
const el = document.getElementsByTagName('html')[0]
26+
if (enabled) {
27+
el.classList.add('vue-ui-dark-mode')
28+
} else {
29+
el.classList.remove('vue-ui-dark-mode')
30+
}
2531
return null
2632
}
2733
}

packages/@vue/cli-ui/src/vue-apollo.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import clientStateResolvers from './state/resolvers'
77
// import CONNECTED from './graphql/connected.gql'
88
import CONNECTED_SET from './graphql/connectedSet.gql'
99
import LOADING_CHANGE from './graphql/loadingChange.gql'
10+
import DARK_MODE_SET from './graphql/darkModeSet.gql'
1011

1112
// Install the vue plugin
1213
Vue.use(VueApollo)
@@ -67,6 +68,13 @@ export async function resetApollo () {
6768
} catch (e) {
6869
// Potential errors
6970
}
71+
const raw = localStorage.getItem('vue-ui-dark-mode')
72+
apolloClient.mutate({
73+
mutation: DARK_MODE_SET,
74+
variables: {
75+
enabled: raw === 'true'
76+
}
77+
})
7078
}
7179

7280
/* Connected state */

0 commit comments

Comments
 (0)