Skip to content

Commit fd42e74

Browse files
committed
fix(theme): prevent flash of different theme
1 parent b43c22a commit fd42e74

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

packages/app-frontend/src/features/App.vue

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import AppConnecting from './connection/AppConnecting.vue'
44
import AppDisconnected from './connection/AppDisconnected.vue'
55
import ErrorOverlay from './error/ErrorOverlay.vue'
66
import { useAppConnection } from './connection'
7-
import { isChrome } from '@vue-devtools/shared-utils'
7+
import { isChrome, setStorage, getStorage } from '@vue-devtools/shared-utils'
88
import SharedData, { watchSharedData, onSharedDataInit } from '@utils/shared-data'
99
import { darkMode } from '@front/util/theme'
10+
import { onMounted } from '@vue/composition-api'
1011
1112
const chromeTheme = isChrome ? chrome.devtools.panels.themeName : undefined
1213
14+
const STORAGE_PREVIOUS_SESSION_THEME = 'previous-session-theme'
15+
1316
export default {
1417
name: 'App',
1518
@@ -23,8 +26,7 @@ export default {
2326
setup () {
2427
const { isConnected, isInitializing } = useAppConnection()
2528
26-
function updateTheme () {
27-
const theme = SharedData.theme
29+
function updateTheme (theme) {
2830
if (theme === 'dark' || theme === 'high-contrast' || (theme === 'auto' && chromeTheme === 'dark')) {
2931
document.body.classList.add('vue-ui-dark-mode')
3032
darkMode.value = true
@@ -37,14 +39,23 @@ export default {
3739
} else {
3840
document.body.classList.remove('vue-ui-high-contrast')
3941
}
42+
setStorage(STORAGE_PREVIOUS_SESSION_THEME, theme)
4043
}
4144
4245
onSharedDataInit(() => {
43-
updateTheme()
46+
updateTheme(SharedData.theme)
47+
})
48+
49+
watchSharedData('theme', (value) => {
50+
updateTheme(value)
4451
})
4552
46-
watchSharedData('theme', () => {
47-
updateTheme()
53+
onMounted(() => {
54+
// Apply last session theme to prevent flashes of different theme
55+
const previousTheme = getStorage(STORAGE_PREVIOUS_SESSION_THEME)
56+
if (previousTheme) {
57+
updateTheme(previousTheme)
58+
}
4859
})
4960
5061
return {

packages/app-frontend/src/features/connection/AppConnecting.vue

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@
1212
</div>
1313
</template>
1414

15-
<script>
16-
import { isChrome } from '@utils/env'
17-
18-
export default {
19-
data () {
20-
return {
21-
theme: isChrome ? chrome.devtools.panels.themeName : 'light'
22-
}
23-
}
24-
}
25-
</script>
26-
2715
<style lang="stylus" scoped>
2816
.app-connecting
2917
width 100%
@@ -33,7 +21,7 @@ export default {
3321
justify-content center
3422
background white
3523
36-
&.theme-dark
24+
.vue-ui-dark-mode &
3725
background $vue-ui-color-almost-black
3826
3927
.animation-inner

packages/app-frontend/src/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ import { initStorage } from '@utils/storage'
55
import { createApp, connectApp } from './app'
66
import { setAppConnected } from './features/connection'
77

8-
const app = createApp()
9-
app.$mount('#app')
10-
118
/**
129
* Create the main devtools app. Expects to be called with a shell interface
1310
* which implements a connect method.
@@ -18,6 +15,8 @@ app.$mount('#app')
1815
*/
1916
export async function initDevTools (shell) {
2017
await initStorage()
18+
const app = createApp()
19+
app.$mount('#app')
2120
connectApp(app, shell)
2221
shell.onReload(() => {
2322
setAppConnected(false)

0 commit comments

Comments
 (0)