Conversation
A bare URL after other text was cut at the first `_` (or `~`, `#`, `@`, `$`, `!`): those characters end a plain-text chunk in InlineMarkdown, and the chunk's own URL scan only saw the text up to there. End the chunk where a bare URL starts instead, so the bare-URL branch takes the URL whole. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review follow-up. Splitting the plain-text chunk at every bare URL gave each URL its own loop turn, and each turn rescans the rest of the text, so a paragraph of many URLs went quadratic (16,000 URLs: about 3 s, against about 60 ms on main). Split only when the URL, matched whole at its start, ends past the chunk; a URL that ends inside the chunk is linked in the same pass as before. Tests for a trailing ! and a $ inside a URL, and a generous time budget for 32,000 plain URLs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 task
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.
What broke
A bare URL that follows other text was linked only up to its first underscore.
Open http://localhost:3011/w/ws_01M5JCNXKERX0XDNABX0S8K9D0/docs/plan.mdlinkedhttp://localhost:3011/w/wsand left the rest as plain text. Every Workspaces id has an underscore (ws_,doc_,prj_), and so do many real URLs. Seen in the Inbox; the renderer is shared, so plan review and annotate had it too. A URL at the very start of a line, and[text](url)links, were fine.Cause
InlineMarkdownwalks the text in plain-text chunks, and a chunk ends at the next character that can start inline syntax:* _ \[ ! ~ \ < # @,!`).Fix
When a bare
http(s)://URL starts inside the chunk at a word boundary and, matched whole from its start (sticky regex, thentrimUrlTail), ends past the chunk, end the chunk where the URL starts. The next pass hits the existing bare-URL branch, which takes the URL whole and trims trailing sentence punctuation as before (a period, a comma,!, an unbalanced closing paren stay outside). A URL that ends inside its chunk stays on the old one-pass path, so output for every URL the bug did not touch is the same as main (checked against main on 50,000 generated lines: every difference was an input with a cut URL), and a paragraph of many plain URLs stays linear (16,000 URLs: about 60 ms, as on main).Unchanged:
_word_emphasis andsnake_casein prose, a URL inside inline code (stays code), a URL inside_..._emphasis (linked whole inside the<em>), a scheme glued to a word (foohttps://…, not linked).Tests
packages/ui/components/InlineMarkdown.test.ts, "bare URL autolinks keep underscores": the reported URL after text; two underscore runs with~,%, a query and a fragment, comma outside; two URLs on one line; an unbalanced closing paren; a trailing!;$and@and#inside a URL; a URL inside_..._; inline code;snake_caseand_word_; a scheme glued to a word. The cut-URL cases fail on main and pass here. A time budget (2 s for 32,000 plain URLs, about 0.1 s now) guards the one-pass path; it failed at 7.7 s on the first version of this branch.bun test packages/ui packages/editor packages/inbox: 0 failbun run typecheck: cleancheck:manifestin sync)