-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
docs: lint code samples within docs #33271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
husayt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes things consistent and neater
danielroe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you for this ❤️
I'll be pushing a few changes shortly as I think the most maintainable way to do this is to have eslint format code examples within markdown.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
WalkthroughThe PR applies widespread documentation edits: consistent formatting (trailing commas, whitespace/indentation, quote normalisation), code fence language adjustments (js → ts), and many example rewrites (multiline tags, parameter parenthesisation, import order). Several docs Type/Signature sections now show explicit exported function declarations and updated interfaces/types (e.g., useFetch, useAsyncData, useHead, useState, definePageMeta, defineNuxtPlugin, defineNuxtRouteMiddleware, abortNavigation, clearNuxtData/State, refreshCookie, refreshNuxtData, reloadNuxtApp, NuxtApp, NuxtError, NavigateToOptions, ObjectPlugin). A few examples contain minor logic tweaks (await vs return, try/catch) but most changes are non-functional formatting. Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@nuxt/kit
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
CodSpeed Performance ReportMerging #33271 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (6)
docs/3.api/3.utils/navigate-to.md (1)
132-135: Keeptargetoptional to match the real type.In
OpenOptions,targetis required here, but the implementation defaults to'_blank'when it isn’t provided. The docs should mirror that by declaringtarget?: string; otherwise the example describing the default is inconsistent with the type.docs/3.api/3.utils/define-lazy-hydration-component.md (1)
210-223: Fix handler name mismatch in hydration example
function onHydrate ()is declared, but the template still wires@hydrated="onHydrated", so the handler referenced in the template no longer exists and the example will throw at runtime. Either rename the function back toonHydratedor update the template binding to callonHydrate.Apply this diff to keep them in sync:
-function onHydrate () { +function onHydrated () { console.log('Component has been hydrated!') }docs/1.getting-started/18.upgrade.md (1)
855-859: Fix incorrect Node.js import (path vs fs).
relativeandresolveare fromnode:path, notnode:fs. The current snippet will error.Apply this diff:
- import { relative, resolve } from 'node:fs' + import { relative, resolve } from 'node:path' // ... nuxt.hook('builder:watch', async (event, path) => { path = relative(nuxt.options.srcDir, resolve(nuxt.options.srcDir, path)) // ... })docs/3.api/3.utils/define-nuxt-plugin.md (1)
44-46: Minor grammar fix in parameter description.“with an potential object” → “with a potential object”.
Apply this diff:
-1. **Function Plugin**: A function that receives the [...] and can return a promise with an potential object with a [`provide`] [...] +1. **Function Plugin**: A function that receives the [...] and can return a promise with a potential object with a [`provide`] [...]docs/3.api/3.utils/define-page-meta.md (1)
137-139: Fix type inconsistency for scrollToTop route types.
Interface uses RouteLocationNormalizedLoaded but the Parameters section here references RouteLocationNormalized. Align to Loaded for consistency.Apply this diff to the Parameters section:
- - **Type**: `boolean | (to: RouteLocationNormalized, from: RouteLocationNormalized) => boolean` + - **Type**: `boolean | (to: RouteLocationNormalizedLoaded, from: RouteLocationNormalizedLoaded) => boolean`docs/3.api/2.composables/use-nuxt-data.md (1)
31-31: Correct the documented empty-state value (null vs undefined).
Signature returns Ref<DataT | undefined>, but the text says “will be null”. Update text to “undefined”.Apply this diff:
-- `data`: A reactive reference to the cached data associated with the provided key. If no cached data exists, the value will be `null`. This `Ref` automatically updates if the cached data changes, allowing seamless reactivity in your components. +- `data`: A reactive reference to the cached data associated with the provided key. If no cached data exists, the value will be `undefined`. This `Ref` automatically updates if the cached data changes, allowing seamless reactivity in your components.
🧹 Nitpick comments (20)
docs/3.api/2.composables/use-runtime-hook.md (1)
16-19: Revert the added space before the parameter list.The new whitespace between the generic and the opening parenthesis (
> () is non-standard for TypeScript snippets and inconsistent with the rest of the docs. Please keep the previous>(formatting.-function useRuntimeHook<THookName extends keyof RuntimeNuxtHooks> ( +function useRuntimeHook<THookName extends keyof RuntimeNuxtHooks>(docs/2.guide/3.going-further/4.kit.md (2)
32-34: Align code fence language with file extension.Block is labelled ts but filename is test.mjs. Prefer matching the fence to the example.
Apply one of:
-```ts [test.mjs] +```js [test.mjs]or
-```ts [test.mjs] +```ts [test.ts]
44-51: CJS example: use js fence and consider destructuring.
- Fence is ts but filename is .cjs; use js for clarity.
- Optional: demonstrate named imports with dynamic import.
Apply:
-```ts [test.cjs] +```js [test.cjs]Optional tweak inside example:
- const kit = await import('@nuxt/kit') + const { useNuxt } = await import('@nuxt/kit')docs/2.guide/1.directory-structure/1.app/1.composables.md (1)
65-70: Consider returning or annotating return type.Example currently returns nothing; returning values (or annotating as () => void) can reduce confusion when copied.
For example:
export const useFoo = () => { const nuxtApp = useNuxtApp() const bar = useBar() + return { nuxtApp, bar } }docs/2.guide/4.recipes/3.custom-usefetch.md (1)
74-81: Unify typing of custom $fetch in useAPI examples.First example casts to typeof $fetch, second does not. Prefer consistency; simplest is to drop the cast for readability (the second example already compiles fine in typical Nuxt TS setups).
Apply this diff to the first example:
- return useFetch(url, { - ...options, - $fetch: useNuxtApp().$api as typeof $fetch, - }) + return useFetch(url, { + ...options, + $fetch: useNuxtApp().$api, + })Also applies to: 104-111
docs/1.getting-started/10.data-fetching.md (1)
33-39: Formatting changes look correct; one minor simplification suggestion.
- All trailing commas/spacing are valid and consistent.
- Optional: in the “Refresh data” example, you can simplify the click handler.
Apply this diff to simplify the handler:
- <button @click="() => refresh()"> + <button @click="refresh">Also applies to: 71-77, 97-99, 200-201, 258-259, 307-307, 320-321, 336-337, 409-410, 429-431, 452-455, 470-470, 481-482, 497-497, 514-515, 529-529, 531-542, 570-570, 575-577, 649-652, 704-704, 747-749, 784-785, 796-796, 809-816
docs/2.guide/1.directory-structure/1.app/3.error.md (1)
15-16: Prefer typed props over runtime validator castingUsing a typed props declaration is clearer and avoids awkward casting to Object. Consider one of:
- Generics
- PropType
Example with generics:
-const props = defineProps({ - error: Object as () => NuxtError, -}) +const props = defineProps<{ error: NuxtError }>()Or with PropType:
+import type { PropType } from 'vue' const props = defineProps({ - error: Object as () => NuxtError, + error: { type: Object as PropType<NuxtError>, required: true }, })docs/1.getting-started/06.styling.md (1)
296-311: Minor consistency nit: quote only when neededIn class-binding examples, you can omit quotes for identifier-safe keys (active) and keep them where required (text-danger) for consistency across snippets.
Example:
-const classObject = reactive({ - 'active': true, - 'text-danger': false, -}) +const classObject = reactive({ + active: true, + 'text-danger': false, +})docs/1.getting-started/14.layers.md (1)
54-55: Optional: Link to giget auth docs for private GitHub sourcesSince this snippet uses an auth token, consider adding a link to giget’s auth docs to guide users on supported env vars/token formats for private repos.
docs/1.getting-started/15.prerendering.md (1)
145-148: Optional: Note on auto-imports forprerenderRoutesConsider adding a brief note that
prerenderRoutesis auto-imported by Nuxt in runtime context so no import is required.docs/2.guide/3.going-further/1.internals.md (1)
39-69: Make the NuxtApp “interface” snippet valid TypeScript (currently invalid).Several properties are missing types (e.g.
vueApp,hooks) and the block mixes literal values with types in an interface, which is not valid TS. Either mark this block as pseudo-code or add minimal types to make it syntactically valid.Apply this diff to keep the snippet valid while remaining high-level:
-interface NuxtApp { - vueApp // the global Vue application: https://vuejs.org/api/application.html#application-api - - versions // an object containing Nuxt and Vue versions - - // These let you call and add runtime NuxtApp hooks - // https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/nuxt.ts#L18 - hooks - hook - callHook - - // Only accessible on server-side - ssrContext: { - url - req - res - runtimeConfig - noSSR - } - - // This will be stringified and passed from server to client - payload: { - serverRendered: true - data: {} - state: {} - } - - provide: (name: string, value: any) => void -} +interface NuxtApp { + // the global Vue application: https://vuejs.org/api/application.html#application-api + vueApp: unknown + + // an object containing Nuxt and Vue versions + versions: { nuxt: string; vue: string } | Record<string, string> + + // These let you call and add runtime NuxtApp hooks + // https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/nuxt.ts#L18 + hooks: unknown + hook: (...args: any[]) => Promise<void> + callHook: (...args: any[]) => Promise<void> + + // Only accessible on server-side + ssrContext?: { + url: string + req?: unknown + res?: unknown + runtimeConfig: unknown + noSSR?: boolean + } + + // This will be stringified and passed from server to client + payload: { + serverRendered: boolean + data: Record<string, unknown> + state: Record<string, unknown> + } + + provide: (name: string, value: unknown) => void +}docs/2.guide/3.going-further/3.modules.md (1)
683-689: Optional: clarifyupdateTemplatesimport in the watch hook snippetIf you expect readers to copy-paste, consider showing
import { updateTemplates } from '@nuxt/kit'above for completeness.docs/3.api/2.composables/use-fetch.md (1)
51-66: Guard browser-only APIs in interceptor examplelocalStorage is browser-only; add a client guard to avoid SSR/runtime issues when the example is used server-side.
onResponse ({ request, response, options }) { // Process the response data - localStorage.setItem('token', response._data.token) + if (import.meta.client && typeof localStorage !== 'undefined') { + localStorage.setItem('token', response._data?.token) + } },docs/1.getting-started/12.error-handling.md (1)
93-96: Prefer typed defineProps or PropType for NuxtErrorObject as () => NuxtError is not idiomatic and may mislead; use a TS generic or PropType.
-const props = defineProps({ - error: Object as () => NuxtError, -}) +const props = defineProps<{ error: NuxtError }>()Alternatively:
import type { PropType } from 'vue' const props = defineProps({ error: Object as PropType<NuxtError>, })docs/3.api/3.utils/define-page-meta.md (2)
176-198: Avoid duplicate keys in the same example object.
The snippet shows middleware defined three times. It’s illustrative, but having the same key repeatedly inside one literal can confuse readers. Consider splitting into separate examples or using an ellipsis between alternatives.
224-232: Same note about duplicate keys.
layout is set twice in one object (string then false). Consider separate examples to avoid implying both can coexist.docs/3.api/2.composables/use-nuxt-data.md (1)
53-57: Guard against undefined cached data in default().
posts.value may be undefined; calling .find will throw. Use optional chaining and a sensible fallback.Apply this diff:
- default () { - // Find the individual post from the cache and set it as the default value. - return posts.value.find(post => post.id === route.params.id) - }, + default () { + // Find the individual post from the cache and set it as the default value. + return posts.value?.find(post => post.id === route.params.id) ?? null + },docs/3.api/2.composables/use-nuxt-app.md (1)
37-40: Unify arrow-parameter style within the page.
Elsewhere in this page single-arg arrows are parenthesised (e.g. (event) => ...). Consider using (name) => here for consistency.Apply this diff:
-const nuxtApp = useNuxtApp() -nuxtApp.provide('hello', name => `Hello ${name}!`) +const nuxtApp = useNuxtApp() +nuxtApp.provide('hello', (name) => `Hello ${name}!`)docs/2.guide/1.directory-structure/1.app/1.components.md (1)
309-324: Importing from #components is valid, but optional for NuxtLink.
NuxtLink is globally available; keeping the import is fine if emphasising explicit imports.docs/2.guide/1.directory-structure/1.app/1.middleware.md (1)
175-178: Small doc caveat suggestion.
Defaulting route = useRoute() is handy outside middleware, but add a one-liner comment warning not to rely on the default within middleware and to pass to explicitly to avoid warnings.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
package.jsonis excluded by!package.json,!**/package.jsonpnpm-lock.yamlis excluded by!**/pnpm-lock.yaml,!pnpm-lock.yaml
📒 Files selected for processing (107)
README.md(1 hunks)docs/1.getting-started/03.configuration.md(6 hunks)docs/1.getting-started/04.views.md(1 hunks)docs/1.getting-started/05.assets.md(2 hunks)docs/1.getting-started/06.styling.md(17 hunks)docs/1.getting-started/07.routing.md(3 hunks)docs/1.getting-started/08.seo-meta.md(15 hunks)docs/1.getting-started/09.transitions.md(16 hunks)docs/1.getting-started/10.data-fetching.md(24 hunks)docs/1.getting-started/11.state-management.md(3 hunks)docs/1.getting-started/12.error-handling.md(4 hunks)docs/1.getting-started/13.server.md(1 hunks)docs/1.getting-started/14.layers.md(4 hunks)docs/1.getting-started/15.prerendering.md(8 hunks)docs/1.getting-started/16.deployment.md(3 hunks)docs/1.getting-started/17.testing.md(19 hunks)docs/1.getting-started/18.upgrade.md(20 hunks)docs/2.guide/1.directory-structure/1.app/1.components.md(13 hunks)docs/2.guide/1.directory-structure/1.app/1.composables.md(4 hunks)docs/2.guide/1.directory-structure/1.app/1.layouts.md(4 hunks)docs/2.guide/1.directory-structure/1.app/1.middleware.md(6 hunks)docs/2.guide/1.directory-structure/1.app/1.pages.md(8 hunks)docs/2.guide/1.directory-structure/1.app/1.plugins.md(9 hunks)docs/2.guide/1.directory-structure/1.app/1.utils.md(1 hunks)docs/2.guide/1.directory-structure/1.app/3.app-config.md(3 hunks)docs/2.guide/1.directory-structure/1.app/3.error.md(3 hunks)docs/2.guide/1.directory-structure/1.content.md(1 hunks)docs/2.guide/1.directory-structure/1.modules.md(1 hunks)docs/2.guide/1.directory-structure/1.public.md(1 hunks)docs/2.guide/1.directory-structure/1.server.md(11 hunks)docs/2.guide/1.directory-structure/1.shared.md(1 hunks)docs/2.guide/2.concepts/1.auto-imports.md(5 hunks)docs/2.guide/2.concepts/2.vuejs-development.md(1 hunks)docs/2.guide/2.concepts/3.rendering.md(5 hunks)docs/2.guide/2.concepts/5.modules.md(1 hunks)docs/2.guide/2.concepts/7.esm.md(6 hunks)docs/2.guide/2.concepts/8.typescript.md(2 hunks)docs/2.guide/3.going-further/1.events.md(2 hunks)docs/2.guide/3.going-further/1.experimental-features.md(32 hunks)docs/2.guide/3.going-further/1.features.md(3 hunks)docs/2.guide/3.going-further/1.internals.md(1 hunks)docs/2.guide/3.going-further/10.runtime-config.md(4 hunks)docs/2.guide/3.going-further/2.hooks.md(6 hunks)docs/2.guide/3.going-further/3.modules.md(21 hunks)docs/2.guide/3.going-further/4.kit.md(2 hunks)docs/2.guide/3.going-further/6.nuxt-app.md(1 hunks)docs/2.guide/3.going-further/7.layers.md(7 hunks)docs/2.guide/3.going-further/9.debugging.md(1 hunks)docs/2.guide/4.recipes/1.custom-routing.md(8 hunks)docs/2.guide/4.recipes/2.vite-plugin.md(1 hunks)docs/2.guide/4.recipes/3.custom-usefetch.md(3 hunks)docs/2.guide/4.recipes/4.sessions-and-authentication.md(6 hunks)docs/2.guide/5.best-practices/performance.md(3 hunks)docs/3.api/1.components/1.client-only.md(3 hunks)docs/3.api/1.components/1.nuxt-client-fallback.md(1 hunks)docs/3.api/1.components/11.teleports.md(1 hunks)docs/3.api/1.components/12.nuxt-route-announcer.md(1 hunks)docs/3.api/1.components/13.nuxt-time.md(7 hunks)docs/3.api/1.components/2.nuxt-page.md(2 hunks)docs/3.api/1.components/3.nuxt-layout.md(3 hunks)docs/3.api/1.components/4.nuxt-link.md(8 hunks)docs/3.api/1.components/6.nuxt-error-boundary.md(1 hunks)docs/3.api/2.composables/on-prehydrate.md(1 hunks)docs/3.api/2.composables/use-async-data.md(6 hunks)docs/3.api/2.composables/use-cookie.md(5 hunks)docs/3.api/2.composables/use-error.md(1 hunks)docs/3.api/2.composables/use-fetch.md(7 hunks)docs/3.api/2.composables/use-head-safe.md(2 hunks)docs/3.api/2.composables/use-head.md(1 hunks)docs/3.api/2.composables/use-hydration.md(1 hunks)docs/3.api/2.composables/use-loading-indicator.md(1 hunks)docs/3.api/2.composables/use-nuxt-app.md(7 hunks)docs/3.api/2.composables/use-nuxt-data.md(3 hunks)docs/3.api/2.composables/use-preview-mode.md(5 hunks)docs/3.api/2.composables/use-request-fetch.md(1 hunks)docs/3.api/2.composables/use-request-headers.md(2 hunks)docs/3.api/2.composables/use-response-header.md(3 hunks)docs/3.api/2.composables/use-route-announcer.md(1 hunks)docs/3.api/2.composables/use-router.md(2 hunks)docs/3.api/2.composables/use-runtime-config.md(2 hunks)docs/3.api/2.composables/use-runtime-hook.md(1 hunks)docs/3.api/2.composables/use-seo-meta.md(1 hunks)docs/3.api/2.composables/use-server-seo-meta.md(1 hunks)docs/3.api/2.composables/use-state.md(1 hunks)docs/3.api/3.utils/$fetch.md(1 hunks)docs/3.api/3.utils/abort-navigation.md(1 hunks)docs/3.api/3.utils/add-route-middleware.md(1 hunks)docs/3.api/3.utils/call-once.md(1 hunks)docs/3.api/3.utils/clear-error.md(1 hunks)docs/3.api/3.utils/clear-nuxt-data.md(1 hunks)docs/3.api/3.utils/clear-nuxt-state.md(1 hunks)docs/3.api/3.utils/create-error.md(1 hunks)docs/3.api/3.utils/define-lazy-hydration-component.md(8 hunks)docs/3.api/3.utils/define-nuxt-component.md(2 hunks)docs/3.api/3.utils/define-nuxt-plugin.md(4 hunks)docs/3.api/3.utils/define-nuxt-route-middleware.md(1 hunks)docs/3.api/3.utils/define-page-meta.md(6 hunks)docs/3.api/3.utils/define-route-rules.md(2 hunks)docs/3.api/3.utils/navigate-to.md(3 hunks)docs/3.api/3.utils/preload-components.md(1 hunks)docs/3.api/3.utils/prerender-routes.md(2 hunks)docs/3.api/3.utils/refresh-cookie.md(2 hunks)docs/3.api/3.utils/refresh-nuxt-data.md(3 hunks)docs/3.api/3.utils/reload-nuxt-app.md(1 hunks)docs/3.api/3.utils/set-response-status.md(1 hunks)docs/3.api/3.utils/show-error.md(1 hunks)docs/3.api/3.utils/update-app-config.md(1 hunks)
⛔ Files not processed due to max files limit (34)
- docs/3.api/5.kit/1.modules.md
- docs/3.api/5.kit/10.templates.md
- docs/3.api/5.kit/11.nitro.md
- docs/3.api/5.kit/12.resolving.md
- docs/3.api/5.kit/14.builder.md
- docs/3.api/5.kit/15.examples.md
- docs/3.api/5.kit/16.layers.md
- docs/3.api/5.kit/3.compatibility.md
- docs/3.api/5.kit/4.autoimports.md
- docs/3.api/5.kit/5.components.md
- docs/3.api/5.kit/6.context.md
- docs/3.api/5.kit/7.pages.md
- docs/3.api/5.kit/8.layout.md
- docs/3.api/5.kit/9.plugins.md
- docs/3.api/6.advanced/2.import-meta.md
- docs/3.api/6.nuxt-config.md
- docs/6.bridge/1.overview.md
- docs/6.bridge/10.configuration.md
- docs/6.bridge/2.typescript.md
- docs/6.bridge/3.bridge-composition-api.md
- docs/6.bridge/4.plugins-and-middleware.md
- docs/6.bridge/5.nuxt3-compatible-api.md
- docs/6.bridge/6.meta.md
- docs/6.bridge/8.nitro.md
- docs/6.bridge/9.vite.md
- docs/7.migration/2.configuration.md
- docs/7.migration/4.meta.md
- docs/7.migration/5.plugins-and-middleware.md
- docs/7.migration/6.pages-and-layouts.md
- docs/7.migration/7.component-options.md
- docs/7.migration/8.runtime-config.md
- eslint.config.mjs
- packages/kit/src/resolve.ts
- packages/nuxt/src/components/module.ts
🧰 Additional context used
🧠 Learnings (9)
📚 Learning: 2025-07-18T16:46:07.446Z
Learnt from: CR
PR: nuxt/nuxt#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T16:46:07.446Z
Learning: Applies to **/*.vue : Use `<script setup lang="ts">` and the composition API when creating Vue components
Applied to files:
docs/3.api/3.utils/define-route-rules.mddocs/3.api/2.composables/use-request-headers.mddocs/2.guide/3.going-further/1.features.mddocs/3.api/2.composables/use-route-announcer.mddocs/2.guide/3.going-further/7.layers.mddocs/2.guide/1.directory-structure/1.app/1.pages.mddocs/2.guide/1.directory-structure/1.app/1.composables.mddocs/2.guide/2.concepts/8.typescript.mddocs/2.guide/1.directory-structure/1.app/1.middleware.mddocs/3.api/2.composables/use-nuxt-app.mddocs/2.guide/2.concepts/3.rendering.mddocs/1.getting-started/09.transitions.mddocs/2.guide/2.concepts/1.auto-imports.mddocs/3.api/2.composables/use-server-seo-meta.mddocs/2.guide/1.directory-structure/1.server.mddocs/1.getting-started/08.seo-meta.mddocs/2.guide/3.going-further/1.experimental-features.mddocs/2.guide/1.directory-structure/1.public.mddocs/1.getting-started/06.styling.mddocs/3.api/1.components/2.nuxt-page.mddocs/3.api/2.composables/use-response-header.mddocs/3.api/3.utils/define-nuxt-component.mddocs/3.api/3.utils/define-page-meta.mddocs/1.getting-started/10.data-fetching.mddocs/3.api/2.composables/use-error.mddocs/3.api/3.utils/define-lazy-hydration-component.mddocs/1.getting-started/17.testing.mddocs/1.getting-started/03.configuration.mddocs/1.getting-started/07.routing.mddocs/2.guide/1.directory-structure/1.app/1.layouts.mddocs/3.api/3.utils/$fetch.mddocs/2.guide/1.directory-structure/1.app/1.components.md
📚 Learning: 2024-11-11T12:34:22.648Z
Learnt from: Tofandel
PR: nuxt/nuxt#0
File: :0-0
Timestamp: 2024-11-11T12:34:22.648Z
Learning: Ensure that AI-generated summaries accurately reflect the key changes in the PR, focusing on notable changes such as the removal of unused imports and variables starting with underscores.
Applied to files:
docs/2.guide/3.going-further/9.debugging.mddocs/2.guide/3.going-further/1.features.mddocs/2.guide/3.going-further/7.layers.mddocs/2.guide/5.best-practices/performance.mddocs/2.guide/2.concepts/3.rendering.mddocs/2.guide/2.concepts/1.auto-imports.mddocs/2.guide/3.going-further/1.experimental-features.mddocs/1.getting-started/06.styling.mddocs/2.guide/2.concepts/5.modules.mddocs/2.guide/3.going-further/10.runtime-config.mddocs/1.getting-started/16.deployment.mddocs/1.getting-started/10.data-fetching.mddocs/1.getting-started/17.testing.mddocs/2.guide/3.going-further/4.kit.mddocs/2.guide/2.concepts/7.esm.mddocs/1.getting-started/15.prerendering.md
📚 Learning: 2024-11-05T15:22:54.759Z
Learnt from: GalacticHypernova
PR: nuxt/nuxt#26468
File: packages/nuxt/src/components/plugins/loader.ts:24-24
Timestamp: 2024-11-05T15:22:54.759Z
Learning: In `packages/nuxt/src/components/plugins/loader.ts`, the references to `resolve` and `distDir` are legacy code from before Nuxt used the new unplugin VFS and will be removed.
Applied to files:
docs/2.guide/3.going-further/7.layers.mddocs/2.guide/2.concepts/1.auto-imports.mddocs/2.guide/1.directory-structure/1.app/1.components.mddocs/1.getting-started/18.upgrade.md
📚 Learning: 2024-11-05T20:04:39.622Z
Learnt from: Tofandel
PR: nuxt/nuxt#26468
File: packages/nuxt/src/components/runtime/client-delayed-component.ts:62-62
Timestamp: 2024-11-05T20:04:39.622Z
Learning: In Vue components, when typing the `hydrate` prop for hydration strategies like `hydrateOnInteraction`, use `type: null as PropType<Arguments<typeof hydrateOnInteraction>[0]>` to get the type directly from Vue's hydration methods. Also, remember that `HTMLElementEventMap` is not a type but an object; use `keyof HTMLElementEventMap` when defining prop types for events.
Applied to files:
docs/3.api/2.composables/on-prehydrate.mddocs/3.api/2.composables/use-hydration.md
📚 Learning: 2024-12-12T12:36:34.871Z
Learnt from: huang-julien
PR: nuxt/nuxt#29366
File: packages/nuxt/src/app/components/nuxt-root.vue:16-19
Timestamp: 2024-12-12T12:36:34.871Z
Learning: In `packages/nuxt/src/app/components/nuxt-root.vue`, when optimizing bundle size by conditionally importing components based on route metadata, prefer using inline conditional imports like:
```js
const IsolatedPage = route?.meta?.isolate ? defineAsyncComponent(() => import('#build/isolated-page.mjs')) : null
```
instead of wrapping the import in a computed property or importing the component unconditionally.
Applied to files:
docs/2.guide/1.directory-structure/1.app/1.pages.mddocs/2.guide/1.directory-structure/1.app/1.middleware.mddocs/2.guide/2.concepts/1.auto-imports.mddocs/3.api/1.components/2.nuxt-page.mddocs/3.api/3.utils/define-page-meta.mddocs/1.getting-started/17.testing.mddocs/2.guide/1.directory-structure/1.app/1.components.md
📚 Learning: 2025-07-18T16:46:07.446Z
Learnt from: CR
PR: nuxt/nuxt#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T16:46:07.446Z
Learning: Applies to **/*.{ts,tsx} : Follow standard TypeScript conventions and best practices
Applied to files:
docs/2.guide/1.directory-structure/1.app/1.composables.mddocs/2.guide/2.concepts/8.typescript.mddocs/2.guide/2.concepts/7.esm.mddocs/1.getting-started/18.upgrade.md
📚 Learning: 2025-09-10T14:42:56.647Z
Learnt from: Tofandel
PR: nuxt/nuxt#33192
File: test/nuxt/use-async-data.test.ts:366-373
Timestamp: 2025-09-10T14:42:56.647Z
Learning: In the Nuxt useAsyncData test "should watch params deeply in a non synchronous way", the foo watcher intentionally updates both params.foo and params.locale using locale.value, simulating a scenario where one watcher consolidates multiple reactive values into a shared params object for testing debounced/non-synchronous behavior.
Applied to files:
docs/1.getting-started/10.data-fetching.mddocs/1.getting-started/18.upgrade.md
📚 Learning: 2025-07-18T16:46:07.446Z
Learnt from: CR
PR: nuxt/nuxt#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T16:46:07.446Z
Learning: Applies to **/*.{test,spec}.{ts,tsx,js,jsx} : Write unit tests for core functionality using `vitest`
Applied to files:
docs/1.getting-started/17.testing.mddocs/2.guide/3.going-further/4.kit.mddocs/2.guide/3.going-further/3.modules.md
📚 Learning: 2025-07-18T16:46:07.446Z
Learnt from: CR
PR: nuxt/nuxt#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-07-18T16:46:07.446Z
Learning: Applies to **/e2e/**/*.{ts,js} : Write end-to-end tests using Playwright and `nuxt/test-utils`
Applied to files:
docs/1.getting-started/17.testing.mddocs/2.guide/3.going-further/4.kit.mddocs/2.guide/3.going-further/3.modules.md
| import { AliasSortingPlugin, TemplateParamsPlugin } from '@unhead/vue/plugins' | ||
|
|
||
| export default defineNuxtPlugin({ | ||
| setup() { | ||
| setup () { | ||
| const unhead = injectHead() | ||
| unhead.use(TemplateParamsPlugin) | ||
| unhead.use(AliasSortingPlugin) | ||
| } | ||
| }, | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
Add/import injectHead in Unhead v2 example.
The snippet uses injectHead() without importing it. Add an import to avoid confusion.
Apply this diff:
-import { AliasSortingPlugin, TemplateParamsPlugin } from '@unhead/vue/plugins'
+import { AliasSortingPlugin, TemplateParamsPlugin } from '@unhead/vue/plugins'
+import { injectHead } from '@unhead/vue'🌐 Web query:
In Nuxt 3/4 with Unhead v2, is `injectHead` auto-imported? What is the recommended import path for `injectHead` (from `@unhead/vue`, `#imports`, or `nuxt/app`)?
💡 Result:
Short answer: No — don't import from @unhead/vue. Use Nuxt's re-exports (auto-imports) instead: import/use injectHead from #imports (or from nuxt/app). Avoid directly importing injectHead from @unhead/vue. [1][2]
Sources:
- Nuxt upgrade docs recommending switching @unhead/vue imports to #imports or nuxt/app. [1]
- Nuxt release/notes stating Nuxt re-exports head APIs and to import from Nuxt auto-imports / nuxt/app instead of @unhead/vue. [2]
Import injectHead from Nuxt auto-imports
Nuxt re-exports head APIs; import injectHead from #imports (or nuxt/app) instead of @unhead/vue.
import { AliasSortingPlugin, TemplateParamsPlugin } from '@unhead/vue/plugins'
+import { injectHead } from '#imports'📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import { AliasSortingPlugin, TemplateParamsPlugin } from '@unhead/vue/plugins' | |
| export default defineNuxtPlugin({ | |
| setup() { | |
| setup () { | |
| const unhead = injectHead() | |
| unhead.use(TemplateParamsPlugin) | |
| unhead.use(AliasSortingPlugin) | |
| } | |
| }, | |
| }) | |
| import { AliasSortingPlugin, TemplateParamsPlugin } from '@unhead/vue/plugins' | |
| import { injectHead } from '#imports' | |
| export default defineNuxtPlugin({ | |
| setup () { | |
| const unhead = injectHead() | |
| unhead.use(TemplateParamsPlugin) | |
| unhead.use(AliasSortingPlugin) | |
| }, | |
| }) |
🤖 Prompt for AI Agents
In docs/1.getting-started/18.upgrade.md around lines 423 to 431, the code
imports injectHead from @unhead/vue but Nuxt re-exports head APIs; replace that
import by importing injectHead from Nuxt auto-imports (#imports or 'nuxt/app')
and keep AliasSortingPlugin and TemplateParamsPlugin from '@unhead/vue'. Update
the import lines to remove injectHead from the @unhead/vue import and add a
separate import: import { injectHead } from '#imports' (or from 'nuxt/app'),
then use injectHead as before in the plugin setup.
| import { useRuntimeConfig } from '@nuxt/kit' | ||
|
|
||
| const options = useRuntimeConfig().public.myModule | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect import source for useRuntimeConfig in runtime code.
useRuntimeConfig is a runtime composable, not provided by @nuxt/kit. Import from #imports (or rely on auto-imports) to avoid confusing readers.
Apply one of these diffs (preferred: explicit import from #imports):
-import { useRuntimeConfig } from '@nuxt/kit'
-
-const options = useRuntimeConfig().public.myModule
+import { useRuntimeConfig } from '#imports'
+const options = useRuntimeConfig().public.myModuleOr rely on auto-imports:
-import { useRuntimeConfig } from '@nuxt/kit'
-
const options = useRuntimeConfig().public.myModule📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import { useRuntimeConfig } from '@nuxt/kit' | |
| const options = useRuntimeConfig().public.myModule | |
| ``` | |
| import { useRuntimeConfig } from '#imports' | |
| const options = useRuntimeConfig().public.myModule |
🤖 Prompt for AI Agents
In docs/2.guide/3.going-further/3.modules.md around lines 320 to 323, the
example imports useRuntimeConfig from '@nuxt/kit' which is incorrect for runtime
code; change the import to come from '#imports' (preferred) or remove the import
and rely on auto-imports so the runtime composable is referenced correctly
(i.e., replace "import { useRuntimeConfig } from '@nuxt/kit'" with an import
from '#imports' or omit the import).
| import { addComponent, createResolver, defineNuxtModule, useRuntimeConfig } from '@nuxt/kit' | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused/incorrect useRuntimeConfig from build-time imports.
This import list is for module authoring utilities. useRuntimeConfig does not belong here and is unused in the snippet.
-import { addComponent, createResolver, defineNuxtModule, useRuntimeConfig } from '@nuxt/kit'
+import { addComponent, createResolver, defineNuxtModule } from '@nuxt/kit'📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import { addComponent, createResolver, defineNuxtModule, useRuntimeConfig } from '@nuxt/kit' | |
| import { addComponent, createResolver, defineNuxtModule } from '@nuxt/kit' |
🤖 Prompt for AI Agents
In docs/2.guide/3.going-further/3.modules.md around lines 359 to 360, the import
line incorrectly includes useRuntimeConfig which is a runtime-only utility and
is unused in this build-time module authoring snippet; remove useRuntimeConfig
from the import list so only module-authoring utilities (addComponent,
createResolver, defineNuxtModule) are imported.
|
thank you ❤️ |
|
Thanks @danielroe . |
Co-authored-by: Daniel Roe <[email protected]>
@danielroe , In the nuxt doc and the code we do not use semicolons except the css/style part I guess. In the doc, there are some places where we have put semicolons, even in the same interface we have given semicolons for some properties where other properties do not have semicolons. I think for consistency we can improve it.