Nuxt · NUXT0097
Initialize each useState key in one place
Finds a useState() key that two or more call sites initialize with different functions.
nuxt/state/no-diverging-usestate-initsrc/rule-packs/nuxt/rules/nuxt/no-diverging-usestate-init.ts Upstream docs Run this rule
pnpm nuxt doctor --rules nuxt/state/no-diverging-usestate-init
Why it matters
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.
Recommended 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.
Useful links
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()