Skip to content

fix: pasted-text chip revert breaks after draft restore#2013

Merged
adboio merged 1 commit intomainfrom
posthog-code/fix-pasted-text-chip-revert
May 4, 2026
Merged

fix: pasted-text chip revert breaks after draft restore#2013
adboio merged 1 commit intomainfrom
posthog-code/fix-pasted-text-chip-revert

Conversation

@posthog
Copy link
Copy Markdown
Contributor

@posthog posthog Bot commented May 4, 2026

Problem

Clicking a pasted-text chip in the prompt input no longer reverts the chip back to inline text after the editor restores from a saved draft (for example, after the editor instance is rebuilt because disabled toggled, after a remount, or after returning to a session whose draft contained a pasted chip).

Root cause

MentionChipNode carries a boolean pastedText attribute that distinguishes pasted-text chips (rendered by PastedTextChip with a click-to-revert handler) from normal mention chips (rendered by DefaultChip, which has no click action for file types).

In useDraftSync.ts, both tiptapJsonToEditorContent and editorContentToTiptapJson were dropping the pastedText attribute when round-tripping through EditorContent. After a draft restore, every chip came back with pastedText defaulted to false, so the view rendered DefaultChip and clicks did nothing.

Fix

  • Add optional pastedText to the MentionChip interface in utils/content.ts.
  • Read node.attrs.pastedText in tiptapJsonToEditorContent and write it back in editorContentToTiptapJson (defaulting to false so existing chips are unaffected).

This preserves the flag through the draft save/restore cycle, so pasted-text chips remain clickable and continue to revert inline.

Test plan

  • Paste a long block of text into the prompt input → chip appears
  • Click the chip immediately → text is restored inline (still works)
  • Paste, then trigger a re-render that rebuilds the editor (e.g. send a different message, switch sessions, or toggle a state that flips disabled), then click the chip → text is restored inline (this was broken before)
  • Existing unit tests pass: pnpm --filter code test src/renderer/features/message-editor

Created with PostHog Code

The `pastedText` chip attribute was being stripped during the
EditorContent <-> Tiptap JSON conversion in useDraftSync, so any time the
editor was rehydrated from the persisted draft (e.g. on remount or when
the editor instance was rebuilt), pasted-text chips lost their flag and
rendered as the non-clickable DefaultChip variant. Clicking them no
longer reverted the text inline.

Pass pastedText through both conversion functions so the chip identity
survives a round trip.

Generated-By: PostHog Code
Task-Id: 95b90a23-b18c-496a-9bf0-eed999ec40aa
@adboio adboio marked this pull request as ready for review May 4, 2026 21:06
@adboio adboio merged commit c4aec8d into main May 4, 2026
15 checks passed
@adboio adboio deleted the posthog-code/fix-pasted-text-chip-revert branch May 4, 2026 21:07
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 4, 2026

Reviews (1): Last reviewed commit: "fix: preserve pastedText flag through dr..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant