fix(extension): repair Included Memories popup data handling and lifecycle#1261
Open
abhay-codes07 wants to merge 1 commit into
Open
fix(extension): repair Included Memories popup data handling and lifecycle#1261abhay-codes07 wants to merge 1 commit into
abhay-codes07 wants to merge 1 commit into
Conversation
…lifecycle The related-memories flow on ChatGPT/Claude/T3 round-tripped the background's string[] response through a dataset attribute, which coerces the array into one comma-joined string. The popup then re-split that string on /[,\n]/, so any memory whose content contains a comma was fragmented into multiple fake rows, and the index-based remove buttons spliced the wrong entries and rewrote a desynced prompt injection. Three more defects lived in the same duplicated block: - every fetch appended a fresh popup to <body> and registered a new document-level click listener that was never removed, so auto-search leaked one popup + one global listener per keystroke burst - the removal cleanup used length <= 1, so removing one of two memories silently threw away the last remaining memory too - removal re-joined memories with " ," and left the numbering baked into the strings, corrupting the injected prompt block The block was byte-identical across chatgpt.ts, claude.ts, and t3.ts, so the popup now lives in a shared utils/included-memories.ts helper: memories are stored as JSON on the dataset (commas survive), the prompt block is always rebuilt from that single source of truth, rows re-render from the array instead of juggling indices, removing entries keeps the last one until none remain (=== 0), and each popup disposes its predecessor (listener, node, auto-dismiss timer) before mounting. The background handler now returns raw memory strings and skips empty ones; numbering is applied at injection time so it stays correct after removals. Verified with tsc --noEmit and a full wxt build.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1257
What
The "Included Memories" popup pipeline on ChatGPT/Claude/T3 had four related defects, all rooted in the same ~180-line block duplicated across the three content scripts:
string[]; assigning that todataset.memoriesDatacoerces it into one comma-joined string, and the popup re-split it with.split(/[,\n]/). Any memory containing a comma showed up as several fake rows, and the index-based remove buttons spliced the wrong entries while rewriting a desynced prompt injection.length <= 1, so removing one of two memories also silently discarded the remaining one.<body>and registered a newdocument-level click listener that was never removed. With auto-search firing per debounced input change, a few minutes of prompt editing accumulates dozens of orphaned global click handlers and stacked popups." ,"and the numbering baked in by the background handler went stale, leaving the injected block as1. foo , 3. bar.Fix
Since the block was byte-identical in
chatgpt.ts,claude.ts, andt3.ts(apart from the prompt-element lookup), the popup now lives in a sharedutils/included-memories.ts:dataset.supermemoriesblock is always rebuilt from that single source of truth, with numbering applied at build time so it stays correct after removalsdata-memory-indexattributes=== 0), and only then clears the injection and restores the iconThe background handler now returns raw memory strings and skips empty results; each content script passes its own site-specific prompt-element lookup. Net −206 lines.
Testing
bun run compile(tsc --noEmit) — cleanbun run build(wxt, chrome-mv3) — cleanbiome checkon all touched files — cleanThe extension package has no test harness, so the helper was written as pure functions (
serializeMemories/parseMemories/buildPromptInjection) plus a self-contained popup factory to keep the behaviour easy to reason about and to unit-test later if a harness lands. Happy to add screenshots/screen recording of the popup flow if that helps review.cc @MaheshtheDev