@@ -3,7 +3,7 @@ import type { Unhead } from '@unhead/schema'
33import type { DevToolsRpcClient } from '@vitejs/devtools-kit/client'
44import type { ComputedRef } from 'vue'
55import type { useRoute , useRouter } from '#imports'
6- import { useColorMode } from '@vueuse/core'
6+ import { usePreferredDark } from '@vueuse/core'
77import { computed , ref } from 'vue'
88import { useState } from '#imports'
99import { renderMarkdown } from './client-services/markdown'
@@ -54,10 +54,37 @@ export const showConnectionWarning = computed(() => {
5454return connectionTimeout . value && ! useClient ( ) . value
5555} )
5656
57- export function getColorMode ( ) {
58- return useColorMode ( {
59- storageKey : 'nuxt-devtools-color-mode' ,
60- } )
57+ export type ColorScheme = 'dark' | 'light'
58+
59+ /**
60+ * Color scheme pushed down by whatever embeds this client — the host app's
61+ * resolved scheme (`useClientColorMode`), or a custom-tab iframe carrying its
62+ * own toggle.
63+ *
64+ * Deliberately *not* persisted. This mirrors someone else's state, so storing
65+ * it overwrote our own "follow the OS" default, permanently: nothing ever wrote
66+ * `auto` back. Every surface without an embedder (the standalone hub UI, the
67+ * client opened directly, `nuxi dev client`) was then frozen on whatever the OS
68+ * happened to be the last time an embedder was attached.
69+ */
70+ const embedderColorMode = ref < ColorScheme > ( )
71+
72+ export function setEmbedderColorMode ( mode : ColorScheme | undefined ) {
73+ embedderColorMode . value = mode
74+ }
75+
76+ let colorMode : ComputedRef < ColorScheme > | undefined
77+
78+ /**
79+ * The scheme the DevTools UI renders in: the embedder's when there is one,
80+ * otherwise the live OS `prefers-color-scheme`.
81+ */
82+ export function getColorMode ( ) : ComputedRef < ColorScheme > {
83+ if ( ! colorMode ) {
84+ const preferredDark = usePreferredDark ( )
85+ colorMode = computed ( ( ) => embedderColorMode . value ?? ( preferredDark . value ? 'dark' : 'light' ) )
86+ }
87+ return colorMode
6188}
6289
6390export function useInjectionClient ( ) : ComputedRef < NuxtDevtoolsIframeClient > {
0 commit comments