Skip to content

Commit fbab245

Browse files
authored
fix: add missing imports in client hints (#141)
* fix: add missing imports in client hints * chore: prepare module before building docs * chore: remove nuxt auto imports
1 parent 842e4e9 commit fbab245

File tree

6 files changed

+30
-11
lines changed

6 files changed

+30
-11
lines changed

.nuxtrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
imports.autoImport=true
21
typescript.includeWorkspace=true

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@
4343
"*.mjs"
4444
],
4545
"scripts": {
46-
"build": "pnpm dev:prepare && nuxt-module-build",
46+
"prepack": "nuxt-module-build",
4747
"dev": "nuxi dev playground",
4848
"dev:multiple-json": "MULTIPLE_LANG_FILES=true nuxi dev playground",
49-
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
50-
"dev:prepare:multiple-json": "nuxt-module-build --stub && MULTIPLE_LANG_FILES=true nuxi prepare playground",
49+
"dev:prepare": "nuxt-module-build --stub && nuxt-module-build prepare && nuxi prepare playground",
50+
"dev:prepare:multiple-json": "nuxt-module-build --stub && nuxt-module-build prepare && MULTIPLE_LANG_FILES=true nuxi prepare playground",
5151
"dev:build": "nuxi build playground",
5252
"dev:generate": "nuxi generate playground",
5353
"dev:build:multiple-json": "MULTIPLE_LANG_FILES=true nuxi build playground",
5454
"dev:generate:multiple-json": "MULTIPLE_LANG_FILES=true nuxi generate playground",
5555
"dev:preview": "nuxi preview playground",
5656
"docs:dev": "pnpm -C docs run dev",
57-
"docs:build": "pnpm dev:prepare && pnpm -C docs run build",
57+
"docs:build": "nuxt-module-build prepare && pnpm -C docs run build",
5858
"docs:serve": "pnpm -C docs run serve",
5959
"lint": "eslint .",
6060
"lint:fix": "nr lint --fix",

src/runtime/plugins/config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ export async function configureVuetify() {
1212

1313
const vuetify = createVuetify(vuetifyOptions)
1414

15+
// @ts-expect-error Vuetify using App<any> instead of App<Element>
1516
nuxtApp.vueApp.use(vuetify)
1617

1718
nuxtApp.provide('vuetify', vuetify)
1819

1920
await nuxtApp.hooks.callHook('vuetify:ready', vuetify)
2021

22+
// eslint-disable-next-line n/prefer-global/process
2123
if (process.client) {
2224
// eslint-disable-next-line no-console
2325
isDev && console.log('Vuetify 3 initialized', vuetify)

src/runtime/plugins/vuetify-client-hints.client.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,15 @@ export default defineNuxtPlugin((nuxtApp) => {
6969
}
7070

7171
// update the theme
72-
if (prefersColorScheme && prefersColorSchemeOptions)
73-
vuetifyOptions.theme.defaultTheme = state.value.colorSchemeFromCookie ?? prefersColorSchemeOptions.defaultTheme
72+
if (prefersColorScheme && prefersColorSchemeOptions) {
73+
if (vuetifyOptions.theme === false) {
74+
vuetifyOptions.theme = { defaultTheme: state.value.colorSchemeFromCookie ?? prefersColorSchemeOptions.defaultTheme }
75+
}
76+
else {
77+
vuetifyOptions.theme = vuetifyOptions.theme ?? {}
78+
vuetifyOptions.theme.defaultTheme = state.value.colorSchemeFromCookie ?? prefersColorSchemeOptions.defaultTheme
79+
}
80+
}
7481
})
7582

7683
// update theme logic

src/runtime/plugins/vuetify-client-hints.server.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
defineNuxtPlugin,
1212
useCookie,
1313
useNuxtApp,
14+
useRequestEvent,
1415
useRequestHeaders,
1516
useState,
1617
} from '#imports'
@@ -64,12 +65,22 @@ export default defineNuxtPlugin((nuxtApp) => {
6465
: true
6566

6667
// update theme from cookie
67-
if (clientHintsRequest.colorSchemeFromCookie)
68-
vuetifyOptions.theme.defaultTheme = clientHintsRequest.colorSchemeFromCookie
68+
if (clientHintsRequest.colorSchemeFromCookie) {
69+
if (vuetifyOptions.theme === false) {
70+
vuetifyOptions.theme = { defaultTheme: clientHintsRequest.colorSchemeFromCookie }
71+
}
72+
else {
73+
vuetifyOptions.theme ??= {}
74+
vuetifyOptions.theme.defaultTheme = clientHintsRequest.colorSchemeFromCookie
75+
}
76+
}
6977

7078
await nuxtApp.hooks.callHook('vuetify:ssr-client-hints', {
7179
vuetifyOptions,
72-
ssrClientHintsConfiguration,
80+
ssrClientHintsConfiguration: {
81+
...ssrClientHintsConfiguration,
82+
enabled: true,
83+
},
7384
ssrClientHints: state.value,
7485
})
7586
})

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"extends": "./playground/.nuxt/tsconfig.json"
2+
"extends": "./.nuxt/tsconfig.json"
33
}

0 commit comments

Comments
 (0)