fix: Preserve URL scheme when typed or pasted into PromptField - #10565
fix: Preserve URL scheme when typed or pasted into PromptField#10565tiffany-sy-lin wants to merge 1 commit into
Conversation
tokenizeURLs was stripping the scheme from token text/serialized output. Paste handling in useTokenField now also recovers a link's href when the pasted plain text is just its scheme-less display label.
|
We want it to look pretty. Why do we need all the url visible? |
We got a report that they were expecting to see the full url after pasting and sending it and that their mcp had some checks/validation related to seeing the full url. I'm currently looking into overriding it in our own application, but it feels a bit hack-y b/c we have to intercept the message with the url and prevent the promptfield from stripping the protocol |
|
Another thing the reporter brought up that I also agree with is that it's odd that something we pasted/typed is changed w/o the user's consent (in this case the protocol is removed). I think it's fine to leave the display text without the |
|
We could change PromptFieldValue's this.segments.map(s => s.type === 'token' && s.value?.type === 'url' ? s.value.url : s.text).join('');that way it includes the full URL when submitted but displays the pretty url. |
|
FYI we merged and released #10575 which applies my comment above. Leaving this open in case we want to discuss the other parts of it (e.g. pasting). |
Summary
tokenizeURLsinPromptField.tsxwas stripping the scheme/www.from a typed or inserted URL's token text, even though it was retained in the token'svalue.url— so both the visible pill and the serialized outgoing message lost the scheme. Now the token's text matches the full match, i.e. exactly what was typed/inserted.hrefhas it) also dropped the scheme, sinceuseTokenField's paste handling fell back to the browser'stext/plainclipboard data. It now inspectstext/htmland substitutes an anchor'shreffor its display text when they represent the same URL, while leaving all other paste content (non-link HTML, links whose label differs from their href) unchanged.Test plan
PromptFieldunit test confirming a typedhttps://www.test.comkeeps its scheme in both the token text and serialized valueTokenFieldbrowser tests (Chromium/Firefox; skipped on WebKit, which doesn't support syntheticdataTransferon constructedInputEvents) covering: scheme recovery from a pasted rendered link, leaving unrelated link labels alone, and pasting non-link HTML unchangedtokenize/replaceRangeWithSegmentspath🤖 Generated with Claude Code