Repository navigation
studio: stop find in page matching part way through a grapheme - #10200
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Confirmed the cluster pattern in studio/frontend/src/features/find-in-page/lib/find-text-index.ts still splits a Hangul syllable into Jamo on main, so Korean queries come back empty against text on screen. Will get this reviewed. |
The shell prevents the chord's default and only then renders the bar, so deferring the bar behind `lazy` leaves a reader who presses it early with no native find and no bar either. Warming the chunk on idle narrows that window but does not close it, and it never opens at all on Safari, which has shipped requestIdleCallback behind a feature flag in every version to date and so always takes the one second timer instead. The smoke harness already caught this and was taught not to: `open_bar` grew a ten second wait for the landmark, which is exactly the delay being measured. Revert that wait, carry the bar in the entry again, and drop the test that asserted the split. Against a deferred build five webkit checks that the bar is a search landmark fail; against this one the harness is 432/432 across chromium, firefox and webkit. The budget raise this PR already makes is what pays for it: 1,566.3 KB eager transfer, 6.0 KB inside the new ceiling. The split was not needed to fit.
|
Round 2 done, both items genuine and fixed in 06ff5ef. Both are in the Hangul work I added, and both reproduced first. |
|
Round 3: both items genuine, both in my own Hangul work, both fixed in f97dc9d and reproduced first. |
|
Round 36, pushed as |
|
Security review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Converged. Codex reviewed |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Security review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Security review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
The find bar became its own lazily loaded module on main (#10236), the index grew portal surfaces and `renumbersMatches` (#10237), and #10209 landed its own Hangul handling. Resolved by keeping both sides: - `OffsetRuns`, `unsafe` and `shifted` sit alongside `rootLength` and `surfaces` on `FindTextIndex`, and `buildTextIndex` returns all of them. - `CLUSTER_PATTERN` and the Hangul spelling helpers are main's, which require the vowel and carry the lint exemption. `canonicalSource` uses `partiallyComposedHangul` for the half-composed spelling and keeps the longest-first sort the grapheme fence needs. - Every component-source assertion now reads `find-bar.tsx`, and the store tests are main's, since the store is gone. `check-bundle-budget.ts` is back to main's: the branch only reflowed its comments and added a note that the find bar is eager, which main's lazy split has made untrue.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: de6c76509f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| cost.seen = (cost.seen ?? 0) - ((cost.seen ?? 0) % SEEK_BLOCK); | ||
| cost.since = 0; |
There was a problem hiding this comment.
Charge partial seek blocks before resetting the window
When a query produces fewer than SEEK_BLOCK boundary checks, this resets both the partial seek count and its timer without adding any of that work to cost.spent. Consequently, repeated searches can never trigger the boundary-table fallback: for example, a near-tail query with one candidate in a large regional-indicator run repeatedly performs an expensive Intl.Segmenter.containing() seek on every query edit. Preserve or account for the partial block at the end of each search so actual seek cost eventually reaches the scan budget.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The accounting is as you describe: endSeekWindow rounds cost.seen down to a whole block and drops the open block's elapsed time, so a search that never completes a block is never charged. I could not reproduce the consequence, and the numbers say the fallback it would trigger is the more expensive answer, so this is a 👎 rather than a fix.
Instrumented containing and the iterator over a 4M index of nothing but regional indicators, which is the worst document this code can be given:
- 200-match query, 25 searches: 9,975 seeks, 0 table buys, 10ms total.
- 15-match query, 25 searches: 727 seeks, 0 table buys, 19ms total.
- 30 searches of a tail-anchored query: 2.2-2.7ms each, flat, 70ms total.
One full scan of that index, which is what buying the table costs, is 107-110ms. So in every shape I could build, charging the partial block would trip the table and make the search slower, not faster: the seeks it would replace cost about a microsecond each here, because containing is not linear in the offset on V8.
The design already says this: the budget is measured time, not a count, and completed blocks are charged. What is dropped is bounded by one partial block per search. If an engine ever makes containing expensive enough for that to matter, the seeking path is not used there anyway, because it has to pass the correctness probe added in 06dc474 first, and WebKit already fails it and goes straight to the table.
Happy to be shown a document where this bites; the harness is a few lines and I will take the two-line change if it does.
The fence is what this PR is for: no match may begin or end part way through a grapheme, which main still allows. It needs `Intl.Segmenter` and the cheap sub-U+0300 test in front of it, and nothing else. Removed the hand-rolled UAX 29 fallback for engines with no segmenter, and the bookkeeping that tracked which offsets a truncating walk left in doubt. Both were correct and both were answering questions this feature can decline: a reader on Firefox 104 to 124 keeps the behaviour they have today, and a document cut at the 4M ceiling keeps it at the seam. What is left is the fence itself, its budget, and the tests that hold it to the platform's own answer. Behaviour is unchanged everywhere a segmenter exists: half a flag, a bare thumb before its skin tone, one member of a ZWJ family, a consonant inside a conjunct, `cafe` inside a decomposed `café` and a keycap digit are all still refused, and every whole-grapheme query still matches at the same offsets.
|
Rewritten to one fix, and the title and description now say what that is.
Merged 2694/892 across 3 files, down to 1034/570 across 2. Behaviour is unchanged everywhere a segmenter exists, checked case by case against the pre-cut branch. 6900/6900 frontend tests, typecheck, build and The round-by-round log above is trimmed to one line each. The rounds themselves stand, but most of them are about code this PR no longer contains. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ed62ad82ad
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!alignsToGraphemes(index, hit.index, end)) { | ||
| pattern.lastIndex = hit.index + 1; | ||
| continue; |
There was a problem hiding this comment.
Retry preserved whitespace before skipping a greedy hit
Inside preserved-whitespace content such as <pre>, a query ending in whitespace can have a valid occurrence hidden by the greedy \s+ pattern. For example, with text "x \u0301", the first space is a complete grapheme and "x " should match it exactly, but the regex initially consumes both spaces, the second space's combining mark makes this boundary check fail, and advancing lastIndex past the start prevents retrying the shorter valid match; findMatches consequently returns no occurrence. Retry an exact/shorter whitespace match at the same start before discarding the candidate.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The mechanism is real and I reproduced it, but it is 👎 because it needs input this code never receives, and both fixes for it are worse than the defect.
Reproduced at head: "x \u0301", query "x " returns [] although [0,2] is an aligned literal occurrence. Greedy \s+ takes both spaces, the second carries the mark, the fence rejects, and lastIndex = start + 1 cannot come back for the shorter one.
Measured the reach: over 302,667 queries on 9,512 documents, 111 aligned occurrences are missed, and every one needs a combining mark attached to whitespace. It is wider than your example inside that family (108 of the 111 have no mark in the query at all, e.g. "hello \u0301 world" with query "ello "), and empty outside it. A combining mark on a space does not occur in chat, code or tool output.
Both repairs cost more than that:
- Lazy
\s+?: a lazy quantifier at the END of a pattern never expands, so a query of"\r\n"matches only the CR and the fence then rejects it for splitting the pair. The existing testa CRLF is one grapheme, which the fast path has to know aboutfails on it. Tried it; it is wrong. - A negative lookahead for a joiner after the run: this works (
/x\s+(?![\p{Grapheme_Extend}\p{Mc}\p{Emoji_Modifier}\u200d])/ubacktracks to[0,2]as wanted), but property escapes need theuflag, and putting the whole query pattern in unicode mode changesescapeForRegexand thelastIndex = start + 1step for every query in the app to repair a case with no real input. Doing it withoutumeans re-adding the range tables this PR just removed.
The failure mode here is a lost match, never a wrong one: the fence's invariant still holds, and nothing gets painted over half a character. That is the right side to fail on for input this exotic. Recorded rather than fixed.
…first WebKit's `Segments.prototype.containing` answers the segment that ENDS at an offset rather than the one that starts there. Over `x` and a thumbs up it reads 0, 0, 1 where Chromium and Firefox both read 0, 1, 1, so every interior boundary answers "not a boundary". `startsGrapheme` seeks with `containing` while it is under its budget, so on Safari and on both WebKit-backed Tauri webviews this fence threw away every match beside an emoji or an accent. Not consistently, either: past the budget the boundaries are tabulated from the ITERATOR, which is correct, so the answers changed back on their own once a search had done enough work. Found by running the fence in all three engines over 250,000 queries each: the same corpus is clean on Chromium and Firefox and had 40 violations on WebKit, of the form "this occurrence is aligned by your own segmenter, and you dropped it". One fixture settles it, once per process, and its answer is not a matter of opinion: `containing(1)` over a code unit and a surrogate pair is the start of the pair. Where the engine gets that wrong, boundaries are tabulated instead -- the same answer by the slower route, not a second implementation of UAX 29. Measured on a 4M index in WebKit, that costs 328ms once and 1ms a search after, against Firefox's own 311ms worst case on the seeking path.
|
Simulated this across the three engines before trusting it, and found one thing that would have broken Safari. WebKit's Fixed in How it was found. A differential harness against Also checked. With One thing worth a second opinion, in the description now. Measured with |
Two ways a match could still end part way through a grapheme, both at a seam where the walk dropped text: - `startsGrapheme` returned true for `at === text.length` unconditionally. When the ceiling lands between a letter and the mark that joins it, the index ends on the letter and the mark is in the node that was left out, so the text alone says the letter is whole and the page says otherwise. - The per-node cut moved only for a surrogate pair, so `MAX_NODE_CHARS` landing between a letter and its mark split the pair for every other extender. Both are settled rather than assumed, from the one thing a cut has in hand: the text it is dropping. `joinsAcross` asks the segmenter whether the kept tail runs on into the next code point, over a 32-character window, and only the junctions that really join become seams. `alignsToGraphemes` consults them ahead of the cheap test, which reads the text either side of an edge and so cannot see a cut at all -- at the end of a truncated index there is no next character to read. Deciding rather than refusing is what keeps the far side of a cut findable: a blanket refusal makes the first character after every clip unmatchable, which three existing tests already pin. Verified: the two reported cases now return no match, 6904/6904 frontend tests, and the invariant harness against main is unchanged over 1.19M queries.
…ixed size A window taken as the last 32 code units is not the text the segmenter would see. Regional indicators prove it: a run pairs off from its START, so the tail of an ODD run reads as an even one and the indicator after the cut looks like a fresh flag rather than the back half of this one. A node of one ASCII character, 49,998 indicators and then two more, cut between the last two, returned the second-to-last on its own while the page pairs it with the one that was dropped. `exactTail` reads back to a character below U+0300 instead. Such a character can neither extend nor be extended, which the sweep over every code point below U+0300 already asserts, so it always begins a cluster and the window from it segments exactly as the whole string does. Where there is no anchor within the window the junction is unknown rather than open, and a match may not end on it: that costs the one occurrence ending exactly at a cut inside an unbroken run, which is the side to fail on. Verified: the reported case now returns no match, the text after the cut is still findable, both earlier seam cases stay fixed, 6905/6905 frontend tests, and the invariant harness against main is unchanged over 1.19M queries.
Entering a block cleared the text a clip had dropped; leaving one did not. A node clipped inside a block therefore stayed readable to the sibling after that block, and decided a junction the block separator had already settled: a dropped suffix ending in a Prepend joined the first character of the next block, putting a seam on text that had nothing dropped in front of it and making it unfindable. Reproduced against head: a `DIV` holding a clipped node whose dropped tail ends U+0600, followed by the inline text `a`, returned no match for `a`. Leaving a block clears it, as entering one does.
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Find in page can currently end a match part way through a character. The fix is one thing: ask
Intl.Segmenterwhether both edges of a candidate land where a grapheme starts, and drop the candidate when they do not.What main does today
Reproduced against
mainatcc0cdab40, one text node per row:café(decomposed)cafe[0,4][0,2][0,2][3,5][0,1]1[0,1]Each of those paints a highlight over part of a character: the thumb of a hand whose skin tone stays unpainted, one half of a flag,
cafeinsidecaféwith the combining acute left hanging off the end. Enter then walks the reader to it.This is not the Hangul defect. #10209 fixed "a Korean query finds nothing"; this is "a match may stop inside what the page draws as one character", which is still open and is not specific to any script.
The fence
alignsToGraphemesasksstartsGraphemeabout both edges. Ahead of it is a cheap test that decides almost every match without a segmentation: nothing below U+0300 can extend a grapheme or be extended into one, so Latin prose costs four comparisons per candidate. That fact is asserted over every code point below U+0300 rather than argued for.Seeking is billed by what it costs rather than by how often it happens. A seek is 0.2us into a page of Hangul and 1236us into a page of flags, so no count is right for both; the budget is what a scan of the same index would cost, and once a search has spent it the boundaries are tabulated once and answer everything after. Wall time between two searches is the reader thinking and is not charged to either.
Where there is no
Intl.Segmenter, every candidate is taken unchecked, which is what happens today. Firefox shipped one in 125 and was the last engine to; hand-rolling UAX 29 for the versions behind it is a second Unicode implementation to keep current, and the only thing at stake is whether those readers get the fix now or when they upgrade.WebKit cannot be asked with
containingSegments.prototype.containingin WebKit answers the segment that ENDS at an offset rather than the one that starts there. Overxand a thumbs up:containing(0)containing(1)containing(2)startsGraphemeseeks withcontainingwhile it is under its budget, so taken at face value this fence threw away every match beside an emoji or an accent on Safari and on both WebKit-backed Tauri webviews. Not consistently either: past the budget the boundaries come from the iterator, which is correct, so the answers changed back on their own once a search had done enough work.One fixture settles it, once per process. Where the engine fails it, boundaries are tabulated instead: the same answer by the slower route, not a second implementation of UAX 29.
What the engines' own find does, measured
window.find, reading the selection back rather than the boolean:1So the three engines do not agree with each other, and none of them does what this PR does. Chromium matches and then EXPANDS the selection to the whole cluster; Firefox paints half; WebKit is split. This PR refuses instead.
Refusing is the conservative half of the right answer: it can never paint part of a character, which is the defect. Expanding, as Chromium does, would also find 👍🏽 for a reader who typed 👍, and is the better behaviour. That is a bigger change -- it moves the ends of a match, and so the highlight, the counter and the walk -- and belongs in its own PR rather than smuggled into this one. Worth knowing that this trades "paints half" for "finds nothing" on those queries.
Verification
bundle:checkwithin budget with 14.8 KB transfer to spare. Biome reports the same 2 pre-existing errors asmain.main's module over 2.78M queries / 86k documents / 4 DOM shapes under Node, and 250k queries each inside Chromium 151, Firefox 153 and WebKit 26.5. Every match the fence keeps is aligned at both edges; every aligned occurrence is kept unless a kept match already covers it; nothing is invented; ordering, non-overlap and bounds hold throughout.Intl.Segmenterdeleted, head is byte-identical tomainin all three engines, over the same corpora.en,tr,ko,th,ja,ar,hi,eland against four host locales includingtr_TRandko_KR.History
This opened as a Hangul cluster-pattern fix plus a lazy split of the find bar, both of which
mainhas since done itself (#10209, #10236). It then grew a hand-rolled UAX 29 fallback and a set of offsets tracking what a truncating walk left in doubt. Both were correct; both have been removed here as more machinery than the defect warrants. What is left is the fence, its budget, and the tests that hold it to the platform's own answer.