Skip to main content
Advice lets a plugin wrap or replace a function or React component owned by another plugin, without modifying the original source. This API is inspired by Emacs, where defadvice is used to modify existing functions without editing their source.
Advice is a kind of injection. this.advise(...) is sugar over this.inject(...) with meta.kind: "advice".

Registering advice

Call this.advise(...) from inside a service:
Returns an unregister function. Wrap in this.setup() for hot-reload cleanup.

Around advice

Around-advice receives the next function in the chain (which is the original target, or the next around-advice if several are stacked) as the first positional argument. For React components, since React calls components as Component(props), the signature is (Original, props).
src/content/wrap-counter.tsx
For a plain function save({ path }: { path: string }), around-advice would be:
Use around-advice when you want to render the original but add structure around it, change its props, or short-circuit it conditionally (skip the next(...) call).

Replace advice

Substitutes the export entirely. The wrapper is used in place of the original.

Before / After

before and after advice wrap a function without taking over the call.
  • before runs first with the original args (...originalArgs); its return value is ignored.
  • after runs last with the result followed by the original args (result, ...originalArgs). If it returns a value other than undefined, that value overrides the result.

Hot reloading

Adding, removing, or editing a this.advise(...) call reloads the renderer so the new advice takes effect. Edits inside the advice module itself hot-replace through Vite’s normal HMR.