Skip to content

PINIA_COLADA_R0007: defineMutation() called outside of a component or effect scope

  • Level: warning (dev only)

What happened

A composable returned by defineMutation() was called outside of a component and outside of an effect scope. The mutation's reactive effects are attached to the current scope so they can be paused when no consumer is left; without a scope, they will never be cleaned up, which may cause memory leaks.

How to fix it

Call the composable inside a component setup(), an effect scope, or a store:

ts
const useCreateTodo = defineMutation({
  key: ['todos', 'create'],
  mutation: (text: string) => createTodo(text),
})

// ✅ inside a component setup
const { mutate } = useCreateTodo()

// ✅ inside an effect scope
const scope = effectScope()
scope.run(() => useCreateTodo())

// ❌ at the top level of a module or inside an event handler

Common causes

  • Calling the defined mutation at the top level of a module
  • Calling it inside a plain event handler or async callback that runs after setup() finished

Released under the MIT License.