Extension: Included Memories popup fragments comma-containing memories, leaks global click listeners, and drops the last memory on removal
Environment: browser extension on current main (wxt, chrome-mv3). The popup block is duplicated for ChatGPT, Claude and T3, so all three surfaces are affected.
While reading through the related-memories flow in the content scripts, I found a cluster of related problems in the popup pipeline shared by chatgpt.ts, claude.ts and t3.ts — each one traceable directly in the code:
1. Memories containing commas get fragmented into fake rows
getRelatedMemories in background.ts returns data as a string[]. The content scripts assign that array straight onto a dataset attribute (iconElement.dataset.memoriesData = response.data), which coerces it to a single comma-joined string. The popup then re-splits it with .split(/[,\n]/).
Steps to reproduce:
- Save a memory whose content contains a comma, e.g.
Prefers TypeScript, strict mode, and Biome - Type a related prompt on chatgpt.com so auto-search picks it up
- Click "Included Memories"
Expected: one row for the memory.
Actual: three rows ("Prefers TypeScript" / "strict mode" / "and Biome"). Since the remove buttons operate by row index into that mis-split array, removing a row deletes the wrong fragment and rewrites dataset.supermemories into text that no longer matches what the popup shows.
2. Removing one of two memories throws away the last one too
The cleanup guard after a removal is if (currentMemories.length <= 1), which wipes dataset.supermemories, clears the icon, and destroys the popup. So with two memories included, removing one also silently discards the one you wanted to keep. Should be === 0.
3. Every search leaks a popup node and a global click listener
Each successful fetch appends a new popup div to document.body and registers a new document.addEventListener("click", ...) closing over it. The listener is never removed and the popup only goes away after a 5-minute timeout. With auto-search firing on every debounced input change, editing a prompt for a few minutes accumulates dozens of orphaned global click handlers and stacked hidden popups.
4. Prompt injection text degrades after removals
After a removal the remaining memories are re-joined with " ," and the numbering baked into the strings by the background handler goes stale, so the injected "Supermemories of user" block ends up as 1. foo , 3. bar.
I have a fix ready that stores the array as JSON on the dataset (so content survives the round-trip), rebuilds the prompt block from that single source of truth, fixes the <= 1 guard, and disposes the previous popup/listener before mounting a new one — PR incoming.
Follow-up offer (bugs 2–4)
Thanks for the thorough write-up and for #1339 covering bug 1 (JSON serialize / parse for dataset.memoriesData).
I'm happy to take a follow-up PR for the remaining items, scoped to what still reproduces on current main after the memory-suggestion refactor:
| # | Symptom | Still live? |
|---|---|---|
| 1 | Comma / newline fragmentation | Covered by #1339 |
| 2 | <= 1 wipe when removing one of two |
Yes — t3.ts still uses if (currentMemories.length <= 1) |
| 3 | Popup + document click listener leak per search |
Yes — T3 still appends to document.body and registers a click listener without disposing the previous one |
| 4 | Prompt degrades after removals (" ," join / stale numbers) |
Yes — T3 re-inject path |
ChatGPT / Claude / Gemini no longer ship the removable-popup UI (marker popover is display-only), so 2–4 look T3-specific on main.
Plan:
- Base the follow-up on #1339 so we keep the JSON round-trip.
- Fix wipe guard (
=== 0), dispose prior popup/listener before remount, rebuild injected prompt from the remaining string list (no" ,"/ stale indices). - Add regression tests where we can unit-test helpers.
@abhay-codes07 — if you're already planning this as a second PR, say the word and I'll stand down. Otherwise I'll open the follow-up shortly and cross-link it here.
Follow-up PR opened: https://github.com/supermemoryai/supermemory/pull/1421
Includes the #1339 comma-split commit plus T3 wipe/listener/prompt renumber fixes for bugs 2–4.