diff --git a/packages/suggestion/src/suggestion.ts b/packages/suggestion/src/suggestion.ts index b174b5d8..37a300a9 100644 --- a/packages/suggestion/src/suggestion.ts +++ b/packages/suggestion/src/suggestion.ts @@ -67,6 +67,7 @@ export function Suggestion({ allow = () => true, }: SuggestionOptions) { + let props: SuggestionProps | undefined const renderer = render?.() return new Plugin({ @@ -96,7 +97,8 @@ export function Suggestion({ ? prev : next const decorationNode = document.querySelector(`[data-decoration-id="${state.decorationId}"]`) - const props: SuggestionProps = { + + props = { editor, range: state.range, query: state.query, @@ -141,6 +143,14 @@ export function Suggestion({ renderer?.onStart?.(props) } }, + + destroy: () => { + if (!props) { + return + } + + renderer?.onExit?.(props) + }, } },