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
Callthis.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 asComponent(props), the signature is (Original, props).
src/content/wrap-counter.tsx
save({ path }: { path: string }), around-advice would be:
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.
beforeruns first with the original args (...originalArgs); its return value is ignored.afterruns last with the result followed by the original args (result, ...originalArgs). If it returns a value other thanundefined, that value overrides the result.
Hot reloading
Adding, removing, or editing athis.advise(...) call reloads the renderer so the new advice takes effect. Edits inside the advice module itself hot-replace through Vite’s normal HMR.
