NUXT0097Initialize each useState key in one place
Why it happens
useState(key, init) runs init only while the key has no value. Once one initializer sets the value, the others are ignored, so route and render order can change the starting value. Doctor compares initializers for string-literal keys within each Nuxt app and its layers, ignoring formatting that does not change the parsed syntax. Read-only calls and dynamic keys are not reported.
Fix
Put the state in one composable, such as export const useCount = () => useState('count', () => 0), and call it everywhere instead of repeating useState(key, init). If the call sites mean different state, give each its own key rather than aligning the initializers.
Example
Initialize the state in one composable
Before
// app/pages/index.vue
const count = useState('count', () => 0)
// app/components/Counter.vue
const count = useState('count', () => 10)
After
// app/composables/useCount.ts
export const useCount = () => useState('count', () => 0)
// app/pages/index.vue, app/components/Counter.vue
const count = useCount()
Verify the fix
Run only this rule after editing so the report stays focused on the diagnostic you are closing:
pnpm nuxt doctor --rules nuxt/state/no-diverging-usestate-init