Back to Plate

`rejectSuggestion` must clear inline element metadata

docs/solutions/logic-errors/2026-04-05-reject-suggestion-must-clear-inline-element-metadata.md

53.0.51.7 KB
Original Source

rejectSuggestion must clear inline element metadata

Problem

Rejecting a suggestion on a link could leave the link styled as a deletion even after the suggestion was rejected.

The visible symptom was a red link that no longer had an active suggestion card.

Root cause

rejectSuggestion only cleared inline suggestion metadata from text nodes and block suggestion elements.

That missed inline elements like links, even though inline suggestion metadata can live directly on the element node. acceptSuggestion already handled that shape, so the reject path was inconsistent with the accept path.

Fix

Treat inline elements the same way as text nodes in the reject cleanup paths:

  • when unsetting rejected remove suggestion metadata
  • when removing rejected insert suggestion nodes

The key branch is:

ts
if (
  TextApi.isText(n) ||
  (ElementApi.isElement(n) && editor.api.isInline(n))
) {
  const suggestionData = getInlineSuggestionData(n as TSuggestionText);
  // clear or remove matching inline suggestion metadata
}

Add regression coverage with a real inline link element, not only leaf text nodes.

Verification

These checks passed:

bash
bun test packages/suggestion/src/lib/transforms/rejectSuggestion.spec.tsx
pnpm install
pnpm turbo build --filter=./packages/link --filter=./packages/suggestion
pnpm turbo typecheck --filter=./packages/link --filter=./packages/suggestion
pnpm lint:fix

Prevention

When suggestion metadata can live on both leaf text nodes and inline elements, keep acceptSuggestion and rejectSuggestion structurally symmetric.

If a regression only shows up on rendered inline UI like links or mentions, add one test with a real inline element. Text-only coverage is not enough.