fix(shared): leave thread URLs inside HTML attributes unchanged on paste #48091
main fromrefs/pull/48091/head·merged by juliusmarminge View on GitHubProblem#
Pasting Markdown with a thread URL in an inline HTML attribute turns the attribute value into a thread chip, even though it is not a Markdown link. A real thread URL beside the tag should still become a chip.
Deterministic repro on origin/main (23c6d11d9eb5c6ecfad231411a16508e5ac6845a)
From the repository root with dependencies installed:
node --input-type=module <<'JS'
import { threadLinkContextReferences } from './packages/shared/src/composerContextReferences.ts';
const text = 'Example: <span title="https://app.t3.codes/threads/env/id">Reference</span>; real: https://app.t3.codes/threads/env/id';
console.log(threadLinkContextReferences(text, [], () => 'Target').text);
JS
- Observed:
Example: <span title="[Target](t3-context://v1/thread/thread_id)">Reference</span>; real: [Target](t3-context://v1/thread/thread_id) - Expected:
Example: <span title="https://app.t3.codes/threads/env/id">Reference</span>; real: [Target](t3-context://v1/thread/thread_id)
For the app repro, substitute the hosted URL of a thread on the composer's own machine in both positions and paste the fixture from a plain-text clipboard into an empty composer. Web and Electron route the paste through readPastedComposerClipboard and importPastedComposerText into Tiptap; iOS and Android route the clipboard through importComposerContextClipboard into the draft. The shared scanner creates two chip occurrences on base. The importers may deduplicate the backing record and remap its ID, but they retain both occurrences in the composer text.
Change#
Extend the existing offset-preserving HTML tag mask to cover tags with hosted or custom thread-link text even when there is no backtick. The same scanner serves Markdown relabeling and web, Electron, iOS, and Android paste; its existing escape, code, and autolink handling continues to distinguish literal tags from authored links.
Scope#
Small fix for an obvious bug; no issue needed under CONTRIBUTING.md.
Verification#
- Both focused cases fail on the pinned base: the attribute is rewritten for a hosted bare URL and for a custom-scheme autolink. On the fix, the attribute stays byte-for-byte intact and the adjacent link becomes a chip; both shared suites pass (140 tests).
- The checked commit runs
vp run check:changedand exits 0. - Before/after runtime transcript and assertion diffs: two title lookups and two rewrites on base, one on the fix.
Not shown: Live browser or Electron paste, native iOS or Android paste, and rendered screenshots. The transcript executes the shared parser directly.
Authored by GPT-6.2 Sol (Codex); reviewed by Gemini 4 Neon (Antigravity).
- 1
tanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
- @@ -405,5 +405,5 @@405405 lineIndex++;406406 const spanEnd = findCodeSpanEnd(markdown, match.index, ticks.length, lines, lineIndex);407407 if (spanEnd !== -1) pattern.lastIndex = spanEnd;408- } else if (match[0].startsWith("<") && match[0].includes("`")) {408+ } else if (match[0].startsWith("<") && (match[0].includes("`") || hasThreadLinks(match[0]))) {409409 masked += markdown.slice(cursor, match.index) + match[0].replace(/[^\r\n]/g, "x");
🟡 Medium
src/threadLinks.ts:409Bare thread URLs immediately before or after a matched HTML tag are skipped, so
replaceThreadLinksandthreadLinkRefsmiss valid links. Replacing the tag withxmakes it part of the URL-boundary lookarounds; use spaces to mask the tag without changing adjacent URL boundaries.Suggested change409- masked += markdown.slice(cursor, match.index) + match[0].replace(/[^\r\n]/g, "x");409+match[0].replace(/[^\r\n]/g, " ")🤖 Copy this AI Prompt to have your agent fix this:
In file @packages/shared/src/threadLinks.ts around line 409: Bare thread URLs immediately before or after a matched HTML tag are skipped, so `replaceThreadLinks` and `threadLinkRefs` miss valid links. Replacing the tag with `x` makes it part of the URL-boundary lookarounds; use spaces to mask the tag without changing adjacent URL boundaries.Good catch! Fixed in cdbde85fafd by masking tags with
";"instead of"x"(keeping the placeholder non-whitespace so a masked tag cannot turn a line into a blank line or leading indentation for fences/quotes, while staying outside the bare-URL boundary lookarounds) and added a regression test for bare thread URLs immediately before and after a masked HTML tag.Sorry, I'm unable to act on this request because you do not have permissions within this repository.
Approvability#
Verdict: Approved at
1495d43Macroscope's review found this PR approvable — Thread URLs inside HTML attributes now remain unchanged during thread-link processing. The change is confined to text recognition and preserves the original attribute content, with no evident material operational or data-access risk.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review.
Walkthrough
-
The parser now masks HTML tags that contain backticks or thread links. Tests check that thread URLs in attributes remain literal, while bare thread URLs become references, including when they appear on either side of a tag.
Changes: Thread-link parsing in HTML tags
Layer / File(s) Summary HTML tag masking and reference parsing
packages/shared/src/threadLinks.ts,packages/shared/src/composerContextReferences.test.tsThe parser masks HTML tags that contain backticks or thread links. Tests check that URLs in attributes remain literal and that bare thread URLs around a tag become references. The tests also check that a thread record is created for the bare URL. Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
stienswout,only21mil
Merge Risk:
Minimal · up to1495d-
Thread URLs inside HTML attributes now stay literal during pasted Markdown handling, while real thread URLs next to a tag still become chips. The change is small, covered by tests, and easy to revert. No merge-blocking risk was identified.
Pre-merge checks:
4-
Check name Status Explanation Title check The title names the fix: thread URLs inside HTML attributes stay unchanged on paste. The raw summary confirms the change masks HTML tags containing thread links in the shared threadLinks scanner, and … Description check The description follows the template well. It has Problem, Change, Scope, and Verification sections with substantive content. The Problem section gives a clear reproduction and expected behavior. The … Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Full details: Title check
-
Explanation
The title names the fix: thread URLs inside HTML attributes stay unchanged on paste. The raw summary confirms the change masks HTML tags containing thread links in the shared threadLinks scanner, and the added tests cover this paste behavior. The title is specific, short, and in conventional commit form, so it passes.
Full details: Description check
-
Explanation
The description follows the template well. It has Problem, Change, Scope, and Verification sections with substantive content. The Problem section gives a clear reproduction and expected behavior. The Change section explains the masking extension and why the scanner is shared. The Scope section explains why no issue is linked. Verification lists focused tests, observed results, and what was not checked. The template's optional agent-model line is present. The description is complete, so it passes.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: pingdotgg/t3code
- Branch: main
- File: .coderabbit.config.ts
- Commit: e0661db
- Layers: Repository TS config
- Review profile: CHILL
- Plan: Advanced
- Run ID:
7cc6d0cc-a4f3-413e-b964-42a5396e95e7
Commits-
Reviewing files that changed from the base of the PR and between cdbde85fafdfd842f188effa3324441cc7d634de and 1495d43d2eb1cbf13e2a79c9127ae68c986887bc.
Files selected for processing: 1-
packages/shared/src/threadLinks.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
-
- 2
- 3
Pushed1495d43
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Evidence#
Scenario: A pasted thread URL inside an HTML attribute stays literal#
Steps: Seeded a demo project and source thread, opened a target thread, focused the composer, and pasted the hosted thread URL inside an HTML title attribute and after
real:.Base e0661db2c8Head 1495d43d2eResult ❌ failed: 2 context chips observed (attribute and real URL) ✅ passed: 1 context chip observed (real URL only) Composer capture 

Scenario file: scripts/scenarios/thread-link-attribute-paste.e2e.ts
Not shown:
- The scenario proves the web client path only; mobile was not run.
juliusmarminge added labelstakeover:ready
juliusmarminge removed labelstakeover:in-progress
juliusmarminge merged this7eba80e
juliusmarminge closed this
juliusmarminge removed labelstakeover:ready
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed