Skip to content

[diffs] Misc Polish Feedback Items - #1294

Merged
amadeus merged 13 commits into
beta-1.7from
amadeus/t3-feedback
Nov 14, 2026
Merged

amadeus merged 13 commits into
beta-1.7from
amadeus/t3-feedback

Conversation

@amadeus

@amadeus amadeus commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Fixes and small features from feedback on 1.7.0-beta.3, mostly around CodeView find.

Find

  • Find now searches collapsed files and the collapsed context between hunks. Landing on a hidden match expands what hides it.
  • A hidden match counts as on screen when its file header or separator row is, so find still starts from the first match in view.
  • Matches no longer land under the find panel or a sticky file header. The panel is anchored to the top of the scroll view.
  • Scrolling to a match is instant by default. searchOptions.scrollBehavior still accepts 'smooth' and 'smooth-auto'.
  • A fresh panel opens on the text selected in a code line.
  • Closing the panel returns focus to the viewer, not body.
  • Two quick find steps in split view no longer leave the match scrolled out of view.

CodeView

  • New onItemCollapsedChange(item, nextItem) option, called after CodeView changes an item's collapsed itself (find opening a collapsed file). An owner that keeps its own items stores the change.
  • Expanding context works again after a host re-creates an equal diff while a partial diff is being loaded.

Rendering

  • Collapsed items are no longer highlighted. They render a header and theme styles only, and are highlighted when opened.
  • A collapsed item shows a replaced diff or file at once. Its header used to keep the old name and counts until a highlight came back.
  • FileDiff and File listen for theme and message changes from their first render until cleanUp, not from construction. A full-list setItems used to leave every new CodeView item listening.

Editor

  • setSelections([]) with markers or find matches showing clears the selection. It used to scroll back to the old caret and take focus.

i18n

  • Counts are written with the locale's digit grouping: +12,345 in headers, "12,345 unmodified lines", "1,000 of 1,234". i18n.formatNumber is new.
  • A header picks up a locale change the next time it renders.

Build

  • Vite dev no longer evaluates the worker entry twice. worker/worker.ts only registers the handlers, which moved to worker/workerHandlers.ts.

API changes

  • FileDiff.isLineRenderable is now isLineInCollapsedContext, with the opposite sense. It and revealLine take a side.
  • EMPTY_RENDER_RANGE is removed from the constants entry.
  • ExpandedHunksMap is a new exported type.
  • The worker pool's themeSubscribers stat counts rendered instances.

Measured

Headless Chromium, the commit before the collapsed-item change against it. A CodeView of 300 collapsed diffs, 300 lines each, scrolled top to bottom:

Case Before After
Worker pool, fast scroll 61 highlight jobs 0
Worker pool, 200 ms per step 171 highlight jobs 0
No pool, main thread blocked 22.6 s 0 s

Give CodeView a partial diff with a cacheKey, then pass a new object
for the same diff with the same cacheKey and a bumped version. Expand
a collapsed region in that file: the full files load, but the context
never appears, and every later expand fails the same way.

The loaded files wait for the next layout pass, which applied them
only when CodeView passed the exact object the load started with. The
instance keeps its first object when cacheKeys match, so a re-created
diff never matched again. Compare with areDiffTargetsEqual, as the
instance does for its own input, and write the loaded contents into
the object the host passes now.
Create the worker pool in a Vite dev server with the documented
`worker.js?worker&url` recipe, then render a file. The console logs a
worker error on every render, such as a language or theme that was
never loaded. When that reply arrives first, the file renders without
highlighting.

The highlighter backends load lazily, and their chunks imported shared
code back out of worker.js. Vite dev loads a worker entry under its own
URL, so that import ran the entry a second time in the same worker,
with a second message listener and none of the state the pool had sent.

Move the worker code to workerHandlers.ts and leave worker.ts as one
call to registerWorkerHandlers. Build both as entries, which keeps the
shared code out of worker.js so no chunk imports it.
Open find in a CodeView, then close it with Escape or its close
button. Focus drops to the page body, so the next Cmd+F or arrow key
goes nowhere until you click back into the diff.

Closing removed the panel while its input still had focus, and nothing
took the focus over. closeSearch now checks whether the panel holds
focus before removing it. If it does, focus moves to the CodeView
root, and then to the editor the panel was searching when there is
one. A panel that did not have focus leaves focus where it was.

The panel now tells its host it is closing before it removes itself.
Its close button used to remove it first, which left the host no way
to see that it had held focus.
Select some text in a line of a file or diff, then press Cmd/Ctrl+F.
The find box now opens with that text as the query and its matches
found, instead of opening empty.

Until now only a focused edit-mode item filled the box, from the
editor's own selection. When find opens across every item, CodeView
now reads the browser's selection through each rendered item's shadow
root and uses it when all of it sits in one code line. A selection
that spans lines, or sits outside the code, still opens the box empty,
and an open panel keeps its query.
Open find in a narrow CodeView and search for text that sits on the
top line. The find panel floats over that corner, so the current match
stays hidden under it. Stepping to a match further away centers it in
the whole viewport, as if the panel and the sticky header were not
there.

Navigation now works from where the match is drawn. A match counts as
visible when it is inside the viewport, below the sticky header, and
not under the panel. Anything else is centered in the space below the
taller of the two. A match that is not rendered yet has no position to
read, so the scroll starts from its line and switches to the measured
position once the row exists. Wrapped lines no longer matter, since
the target is the match and not its line.

The panel was also mounted after a renderCodeViewHeader host, which
left it below the header until the header scrolled away. It now mounts
ahead of it and stays at the top of the scroll view.

Search highlights are painted earlier in the render pass, once the
rows are in place, so a find scroll can measure its match before the
scroll is resolved for that frame.
Step through find results in a CodeView. The view now jumps straight
to each match. Before, it glided there whenever the match was within a
few screens, which is not how find behaves in most editors and
browsers.

The default for searchOptions.scrollBehavior changes from
'smooth-auto' to 'instant'. Hosts that want the animation set 'smooth'
or 'smooth-auto' themselves.
In a split diff with long lines, step through find results twice in
quick succession, such as with a held Enter key. The current match can
end up scrolled out of view sideways, and nothing brings it back.

Stepping to a match scrolled its code column sideways straight from
the key handler. The two split columns copy each other's scroll
position on the next frame, so a second step inside the same frame was
overwritten by the first step's late copy.

The sideways scroll now runs only in the frame paint, once per frame,
as it did before the find panel work. Navigation still paints the
highlight ranges right away to read where the match is, without
scrolling.
CodeView find skipped collapsed items and, in unscoped search, the
unchanged lines hidden between hunks. Both are now searched. Landing on
a hidden match expands what hides it: the region through revealLine, the
file through updateItem with collapsed: false and a bumped version.

A hidden match counts as on screen when its file header or separator row
is, so find still starts from the first match in view.

isLineRenderable is renamed isLineInCollapsedContext, with the sense
flipped, and it and revealLine take a side. In CodeView an expansion is
applied at the next layout pass; until then VirtualizedFileDiff keeps
the expansion state as it will be, so a just-revealed line has a
position to scroll to.
Find opens a collapsed item when it lands on a match inside it. An owner
that keeps its own item list was never told, so its next list still said
collapsed at the old version and the item closed again.

onItemCollapsedChange(item, nextItem) is called after CodeView itself
changes an item's collapsed state, with the item before the change and
the one CodeView has already applied. It is not called for changes the
owner makes, and it cannot veto. Find is the only caller.
@vercel

vercel Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
pierre-diffshub Ready Ready Preview Nov 14, 2026 8:33pm UTC
pierre-docs-diffs Ready Ready Preview Nov 14, 2026 8:33pm UTC
pierre-docs-trees Ready Ready Preview Nov 14, 2026 8:33pm UTC
pierrejs-diff-demo Ready Ready Preview Nov 14, 2026 8:33pm UTC

Request Review

Editor.setSelections([]) with markers or find matches present scrolled
back to the old caret and focused the editor. The selection update only
dropped the stored selection when nothing else was drawn in the overlay;
otherwise it redrew the markers and matches and left the old selection
in state, and the scroll that follows found it.

An empty list now always clears the selection. Selecting a deleted line
had the same stale selection and is fixed by the same change.
Header counts were written raw and the i18n store turned every number
into text with String(), so the UI showed "+12345", "12345 unmodified
lines" and "1 of 10000".

The store now builds an Intl.NumberFormat for its locale. `#` in a
plural block and numeric arguments go through it, and i18n.formatNumber
covers counts that are not part of a message, which the diff header
uses. The header's cached HTML records the i18n version it was written
under, so a header picks up a locale change the next time it renders,
including one that happened while it was scrolled out of a CodeView.

FileDiff and File no longer subscribe to theme and message changes in
their constructors. They start listening when they first get a container
and stop in cleanUp. CodeView creates an instance per item, and a
full-list setItems left every new one listening whether or not it was
rendered: 300 new items meant 300 callbacks per change.
A collapsed item shows only its header, but it got that header by
running the full row pipeline with an empty render range. That asked
for a highlight of the whole diff or file: a worker pool task per
collapsed item, or a main-thread highlight without a pool.

Both renderers now have renderCollapsed, which returns the header and
the theme's styles, builds no rows and requests no highlight. When no
highlighter has the theme yet it loads one with the text language only
and asks for another render.

A collapsed item takes a new diff or file at once. The renderer keeps
the previous input's rows on screen until the new one is highlighted,
which for a collapsed item left the old name and counts in the header
until a highlight answer arrived. renderCollapsed also drops rows
cached for another input, and hydration state that only describes
prerendered DOM, since collapsing removes that DOM.

EMPTY_RENDER_RANGE has no remaining use and is removed.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T08:14:15.183313Z 3730d93 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

A find-only panel had an extra 6px before the find input. The hidden
replace toggle still had its own grid column, and that column's gap
remained. With the toggle shown, the chevron sat off center: the
widget's padding on one side and the wider column gap on the other.

The grid now carries data-can-replace when the panel can replace, and
only then has a toggle column. The toggle's margin is the difference
between the widget's padding and the column gap, so it has the same
space on both sides in the wide and narrow layouts.

One helper sets the grid's mode, data-can-replace, and the toggle's
hidden and aria-expanded, in place of three copies of that code.
amadeus added a commit that referenced this pull request Nov 14, 2026
* fix(diffs): keep expand working after a diff is re-created

Give CodeView a partial diff with a cacheKey, then pass a new object
for the same diff with the same cacheKey and a bumped version. Expand
a collapsed region in that file: the full files load, but the context
never appears, and every later expand fails the same way.

The loaded files wait for the next layout pass, which applied them
only when CodeView passed the exact object the load started with. The
instance keeps its first object when cacheKeys match, so a re-created
diff never matched again. Compare with areDiffTargetsEqual, as the
instance does for its own input, and write the loaded contents into
the object the host passes now.

* fix(diffs): stop Vite dev from running the worker entry twice

Create the worker pool in a Vite dev server with the documented
`worker.js?worker&url` recipe, then render a file. The console logs a
worker error on every render, such as a language or theme that was
never loaded. When that reply arrives first, the file renders without
highlighting.

The highlighter backends load lazily, and their chunks imported shared
code back out of worker.js. Vite dev loads a worker entry under its own
URL, so that import ran the entry a second time in the same worker,
with a second message listener and none of the state the pool had sent.

Move the worker code to workerHandlers.ts and leave worker.ts as one
call to registerWorkerHandlers. Build both as entries, which keeps the
shared code out of worker.js so no chunk imports it.

* fix(diffs): keep focus in CodeView when the find panel closes

Open find in a CodeView, then close it with Escape or its close
button. Focus drops to the page body, so the next Cmd+F or arrow key
goes nowhere until you click back into the diff.

Closing removed the panel while its input still had focus, and nothing
took the focus over. closeSearch now checks whether the panel holds
focus before removing it. If it does, focus moves to the CodeView
root, and then to the editor the panel was searching when there is
one. A panel that did not have focus leaves focus where it was.

The panel now tells its host it is closing before it removes itself.
Its close button used to remove it first, which left the host no way
to see that it had held focus.

* feat(diffs): open CodeView find on the selected text

Select some text in a line of a file or diff, then press Cmd/Ctrl+F.
The find box now opens with that text as the query and its matches
found, instead of opening empty.

Until now only a focused edit-mode item filled the box, from the
editor's own selection. When find opens across every item, CodeView
now reads the browser's selection through each rendered item's shadow
root and uses it when all of it sits in one code line. A selection
that spans lines, or sits outside the code, still opens the box empty,
and an open panel keeps its query.

* fix(diffs): keep find matches clear of the find panel

Open find in a narrow CodeView and search for text that sits on the
top line. The find panel floats over that corner, so the current match
stays hidden under it. Stepping to a match further away centers it in
the whole viewport, as if the panel and the sticky header were not
there.

Navigation now works from where the match is drawn. A match counts as
visible when it is inside the viewport, below the sticky header, and
not under the panel. Anything else is centered in the space below the
taller of the two. A match that is not rendered yet has no position to
read, so the scroll starts from its line and switches to the measured
position once the row exists. Wrapped lines no longer matter, since
the target is the match and not its line.

The panel was also mounted after a renderCodeViewHeader host, which
left it below the header until the header scrolled away. It now mounts
ahead of it and stays at the top of the scroll view.

Search highlights are painted earlier in the render pass, once the
rows are in place, so a find scroll can measure its match before the
scroll is resolved for that frame.

* feat(diffs): scroll to CodeView find matches instantly by default

Step through find results in a CodeView. The view now jumps straight
to each match. Before, it glided there whenever the match was within a
few screens, which is not how find behaves in most editors and
browsers.

The default for searchOptions.scrollBehavior changes from
'smooth-auto' to 'instant'. Hosts that want the animation set 'smooth'
or 'smooth-auto' themselves.

* fix(diffs): keep the find match in view after two quick steps

In a split diff with long lines, step through find results twice in
quick succession, such as with a held Enter key. The current match can
end up scrolled out of view sideways, and nothing brings it back.

Stepping to a match scrolled its code column sideways straight from
the key handler. The two split columns copy each other's scroll
position on the next frame, so a second step inside the same frame was
overwritten by the first step's late copy.

The sideways scroll now runs only in the frame paint, once per frame,
as it did before the find panel work. Navigation still paints the
highlight ranges right away to read where the match is, without
scrolling.

* feat(diffs): find matches in collapsed files and collapsed context

CodeView find skipped collapsed items and, in unscoped search, the
unchanged lines hidden between hunks. Both are now searched. Landing on
a hidden match expands what hides it: the region through revealLine, the
file through updateItem with collapsed: false and a bumped version.

A hidden match counts as on screen when its file header or separator row
is, so find still starts from the first match in view.

isLineRenderable is renamed isLineInCollapsedContext, with the sense
flipped, and it and revealLine take a side. In CodeView an expansion is
applied at the next layout pass; until then VirtualizedFileDiff keeps
the expansion state as it will be, so a just-revealed line has a
position to scroll to.

* feat(diffs): add onItemCollapsedChange to CodeView

Find opens a collapsed item when it lands on a match inside it. An owner
that keeps its own item list was never told, so its next list still said
collapsed at the old version and the item closed again.

onItemCollapsedChange(item, nextItem) is called after CodeView itself
changes an item's collapsed state, with the item before the change and
the one CodeView has already applied. It is not called for changes the
owner makes, and it cannot veto. Find is the only caller.

* fix(diffs): clear the editor selection while markers or matches show

Editor.setSelections([]) with markers or find matches present scrolled
back to the old caret and focused the editor. The selection update only
dropped the stored selection when nothing else was drawn in the overlay;
otherwise it redrew the markers and matches and left the old selection
in state, and the scroll that follows found it.

An empty list now always clears the selection. Selecting a deleted line
had the same stale selection and is fixed by the same change.

* feat(diffs): group digits in counts for the i18n locale

Header counts were written raw and the i18n store turned every number
into text with String(), so the UI showed "+12345", "12345 unmodified
lines" and "1 of 10000".

The store now builds an Intl.NumberFormat for its locale. `#` in a
plural block and numeric arguments go through it, and i18n.formatNumber
covers counts that are not part of a message, which the diff header
uses. The header's cached HTML records the i18n version it was written
under, so a header picks up a locale change the next time it renders,
including one that happened while it was scrolled out of a CodeView.

FileDiff and File no longer subscribe to theme and message changes in
their constructors. They start listening when they first get a container
and stop in cleanUp. CodeView creates an instance per item, and a
full-list setItems left every new one listening whether or not it was
rendered: 300 new items meant 300 callbacks per change.

* fix(diffs): stop highlighting collapsed items

A collapsed item shows only its header, but it got that header by
running the full row pipeline with an empty render range. That asked
for a highlight of the whole diff or file: a worker pool task per
collapsed item, or a main-thread highlight without a pool.

Both renderers now have renderCollapsed, which returns the header and
the theme's styles, builds no rows and requests no highlight. When no
highlighter has the theme yet it loads one with the text language only
and asks for another render.

A collapsed item takes a new diff or file at once. The renderer keeps
the previous input's rows on screen until the new one is highlighted,
which for a collapsed item left the old name and counts in the header
until a highlight answer arrived. renderCollapsed also drops rows
cached for another input, and hydration state that only describes
prerendered DOM, since collapsing removes that DOM.

EMPTY_RENDER_RANGE has no remaining use and is removed.

* fix(diffs): tidy the find panel's leading spacing

A find-only panel had an extra 6px before the find input. The hidden
replace toggle still had its own grid column, and that column's gap
remained. With the toggle shown, the chevron sat off center: the
widget's padding on one side and the wider column gap on the other.

The grid now carries data-can-replace when the panel can replace, and
only then has a toggle column. The toggle's margin is the difference
between the widget's padding and the column gap, so it has the same
space on both sides in the wide and narrow layouts.

One helper sets the grid's mode, data-can-replace, and the toggle's
hidden and aria-expanded, in place of three copies of that code.
amadeus added a commit that referenced this pull request Nov 21, 2026
* fix(diffs): keep expand working after a diff is re-created

Give CodeView a partial diff with a cacheKey, then pass a new object
for the same diff with the same cacheKey and a bumped version. Expand
a collapsed region in that file: the full files load, but the context
never appears, and every later expand fails the same way.

The loaded files wait for the next layout pass, which applied them
only when CodeView passed the exact object the load started with. The
instance keeps its first object when cacheKeys match, so a re-created
diff never matched again. Compare with areDiffTargetsEqual, as the
instance does for its own input, and write the loaded contents into
the object the host passes now.

* fix(diffs): stop Vite dev from running the worker entry twice

Create the worker pool in a Vite dev server with the documented
`worker.js?worker&url` recipe, then render a file. The console logs a
worker error on every render, such as a language or theme that was
never loaded. When that reply arrives first, the file renders without
highlighting.

The highlighter backends load lazily, and their chunks imported shared
code back out of worker.js. Vite dev loads a worker entry under its own
URL, so that import ran the entry a second time in the same worker,
with a second message listener and none of the state the pool had sent.

Move the worker code to workerHandlers.ts and leave worker.ts as one
call to registerWorkerHandlers. Build both as entries, which keeps the
shared code out of worker.js so no chunk imports it.

* fix(diffs): keep focus in CodeView when the find panel closes

Open find in a CodeView, then close it with Escape or its close
button. Focus drops to the page body, so the next Cmd+F or arrow key
goes nowhere until you click back into the diff.

Closing removed the panel while its input still had focus, and nothing
took the focus over. closeSearch now checks whether the panel holds
focus before removing it. If it does, focus moves to the CodeView
root, and then to the editor the panel was searching when there is
one. A panel that did not have focus leaves focus where it was.

The panel now tells its host it is closing before it removes itself.
Its close button used to remove it first, which left the host no way
to see that it had held focus.

* feat(diffs): open CodeView find on the selected text

Select some text in a line of a file or diff, then press Cmd/Ctrl+F.
The find box now opens with that text as the query and its matches
found, instead of opening empty.

Until now only a focused edit-mode item filled the box, from the
editor's own selection. When find opens across every item, CodeView
now reads the browser's selection through each rendered item's shadow
root and uses it when all of it sits in one code line. A selection
that spans lines, or sits outside the code, still opens the box empty,
and an open panel keeps its query.

* fix(diffs): keep find matches clear of the find panel

Open find in a narrow CodeView and search for text that sits on the
top line. The find panel floats over that corner, so the current match
stays hidden under it. Stepping to a match further away centers it in
the whole viewport, as if the panel and the sticky header were not
there.

Navigation now works from where the match is drawn. A match counts as
visible when it is inside the viewport, below the sticky header, and
not under the panel. Anything else is centered in the space below the
taller of the two. A match that is not rendered yet has no position to
read, so the scroll starts from its line and switches to the measured
position once the row exists. Wrapped lines no longer matter, since
the target is the match and not its line.

The panel was also mounted after a renderCodeViewHeader host, which
left it below the header until the header scrolled away. It now mounts
ahead of it and stays at the top of the scroll view.

Search highlights are painted earlier in the render pass, once the
rows are in place, so a find scroll can measure its match before the
scroll is resolved for that frame.

* feat(diffs): scroll to CodeView find matches instantly by default

Step through find results in a CodeView. The view now jumps straight
to each match. Before, it glided there whenever the match was within a
few screens, which is not how find behaves in most editors and
browsers.

The default for searchOptions.scrollBehavior changes from
'smooth-auto' to 'instant'. Hosts that want the animation set 'smooth'
or 'smooth-auto' themselves.

* fix(diffs): keep the find match in view after two quick steps

In a split diff with long lines, step through find results twice in
quick succession, such as with a held Enter key. The current match can
end up scrolled out of view sideways, and nothing brings it back.

Stepping to a match scrolled its code column sideways straight from
the key handler. The two split columns copy each other's scroll
position on the next frame, so a second step inside the same frame was
overwritten by the first step's late copy.

The sideways scroll now runs only in the frame paint, once per frame,
as it did before the find panel work. Navigation still paints the
highlight ranges right away to read where the match is, without
scrolling.

* feat(diffs): find matches in collapsed files and collapsed context

CodeView find skipped collapsed items and, in unscoped search, the
unchanged lines hidden between hunks. Both are now searched. Landing on
a hidden match expands what hides it: the region through revealLine, the
file through updateItem with collapsed: false and a bumped version.

A hidden match counts as on screen when its file header or separator row
is, so find still starts from the first match in view.

isLineRenderable is renamed isLineInCollapsedContext, with the sense
flipped, and it and revealLine take a side. In CodeView an expansion is
applied at the next layout pass; until then VirtualizedFileDiff keeps
the expansion state as it will be, so a just-revealed line has a
position to scroll to.

* feat(diffs): add onItemCollapsedChange to CodeView

Find opens a collapsed item when it lands on a match inside it. An owner
that keeps its own item list was never told, so its next list still said
collapsed at the old version and the item closed again.

onItemCollapsedChange(item, nextItem) is called after CodeView itself
changes an item's collapsed state, with the item before the change and
the one CodeView has already applied. It is not called for changes the
owner makes, and it cannot veto. Find is the only caller.

* fix(diffs): clear the editor selection while markers or matches show

Editor.setSelections([]) with markers or find matches present scrolled
back to the old caret and focused the editor. The selection update only
dropped the stored selection when nothing else was drawn in the overlay;
otherwise it redrew the markers and matches and left the old selection
in state, and the scroll that follows found it.

An empty list now always clears the selection. Selecting a deleted line
had the same stale selection and is fixed by the same change.

* feat(diffs): group digits in counts for the i18n locale

Header counts were written raw and the i18n store turned every number
into text with String(), so the UI showed "+12345", "12345 unmodified
lines" and "1 of 10000".

The store now builds an Intl.NumberFormat for its locale. `#` in a
plural block and numeric arguments go through it, and i18n.formatNumber
covers counts that are not part of a message, which the diff header
uses. The header's cached HTML records the i18n version it was written
under, so a header picks up a locale change the next time it renders,
including one that happened while it was scrolled out of a CodeView.

FileDiff and File no longer subscribe to theme and message changes in
their constructors. They start listening when they first get a container
and stop in cleanUp. CodeView creates an instance per item, and a
full-list setItems left every new one listening whether or not it was
rendered: 300 new items meant 300 callbacks per change.

* fix(diffs): stop highlighting collapsed items

A collapsed item shows only its header, but it got that header by
running the full row pipeline with an empty render range. That asked
for a highlight of the whole diff or file: a worker pool task per
collapsed item, or a main-thread highlight without a pool.

Both renderers now have renderCollapsed, which returns the header and
the theme's styles, builds no rows and requests no highlight. When no
highlighter has the theme yet it loads one with the text language only
and asks for another render.

A collapsed item takes a new diff or file at once. The renderer keeps
the previous input's rows on screen until the new one is highlighted,
which for a collapsed item left the old name and counts in the header
until a highlight answer arrived. renderCollapsed also drops rows
cached for another input, and hydration state that only describes
prerendered DOM, since collapsing removes that DOM.

EMPTY_RENDER_RANGE has no remaining use and is removed.

* fix(diffs): tidy the find panel's leading spacing

A find-only panel had an extra 6px before the find input. The hidden
replace toggle still had its own grid column, and that column's gap
remained. With the toggle shown, the chevron sat off center: the
widget's padding on one side and the wider column gap on the other.

The grid now carries data-can-replace when the panel can replace, and
only then has a toggle column. The toggle's margin is the difference
between the widget's padding and the column gap, so it has the same
space on both sides in the wide and narrow layouts.

One helper sets the grid's mode, data-can-replace, and the toggle's
hidden and aria-expanded, in place of three copies of that code.
amadeus added a commit that referenced this pull request Nov 22, 2026
* fix(diffs): keep expand working after a diff is re-created

Give CodeView a partial diff with a cacheKey, then pass a new object
for the same diff with the same cacheKey and a bumped version. Expand
a collapsed region in that file: the full files load, but the context
never appears, and every later expand fails the same way.

The loaded files wait for the next layout pass, which applied them
only when CodeView passed the exact object the load started with. The
instance keeps its first object when cacheKeys match, so a re-created
diff never matched again. Compare with areDiffTargetsEqual, as the
instance does for its own input, and write the loaded contents into
the object the host passes now.

* fix(diffs): stop Vite dev from running the worker entry twice

Create the worker pool in a Vite dev server with the documented
`worker.js?worker&url` recipe, then render a file. The console logs a
worker error on every render, such as a language or theme that was
never loaded. When that reply arrives first, the file renders without
highlighting.

The highlighter backends load lazily, and their chunks imported shared
code back out of worker.js. Vite dev loads a worker entry under its own
URL, so that import ran the entry a second time in the same worker,
with a second message listener and none of the state the pool had sent.

Move the worker code to workerHandlers.ts and leave worker.ts as one
call to registerWorkerHandlers. Build both as entries, which keeps the
shared code out of worker.js so no chunk imports it.

* fix(diffs): keep focus in CodeView when the find panel closes

Open find in a CodeView, then close it with Escape or its close
button. Focus drops to the page body, so the next Cmd+F or arrow key
goes nowhere until you click back into the diff.

Closing removed the panel while its input still had focus, and nothing
took the focus over. closeSearch now checks whether the panel holds
focus before removing it. If it does, focus moves to the CodeView
root, and then to the editor the panel was searching when there is
one. A panel that did not have focus leaves focus where it was.

The panel now tells its host it is closing before it removes itself.
Its close button used to remove it first, which left the host no way
to see that it had held focus.

* feat(diffs): open CodeView find on the selected text

Select some text in a line of a file or diff, then press Cmd/Ctrl+F.
The find box now opens with that text as the query and its matches
found, instead of opening empty.

Until now only a focused edit-mode item filled the box, from the
editor's own selection. When find opens across every item, CodeView
now reads the browser's selection through each rendered item's shadow
root and uses it when all of it sits in one code line. A selection
that spans lines, or sits outside the code, still opens the box empty,
and an open panel keeps its query.

* fix(diffs): keep find matches clear of the find panel

Open find in a narrow CodeView and search for text that sits on the
top line. The find panel floats over that corner, so the current match
stays hidden under it. Stepping to a match further away centers it in
the whole viewport, as if the panel and the sticky header were not
there.

Navigation now works from where the match is drawn. A match counts as
visible when it is inside the viewport, below the sticky header, and
not under the panel. Anything else is centered in the space below the
taller of the two. A match that is not rendered yet has no position to
read, so the scroll starts from its line and switches to the measured
position once the row exists. Wrapped lines no longer matter, since
the target is the match and not its line.

The panel was also mounted after a renderCodeViewHeader host, which
left it below the header until the header scrolled away. It now mounts
ahead of it and stays at the top of the scroll view.

Search highlights are painted earlier in the render pass, once the
rows are in place, so a find scroll can measure its match before the
scroll is resolved for that frame.

* feat(diffs): scroll to CodeView find matches instantly by default

Step through find results in a CodeView. The view now jumps straight
to each match. Before, it glided there whenever the match was within a
few screens, which is not how find behaves in most editors and
browsers.

The default for searchOptions.scrollBehavior changes from
'smooth-auto' to 'instant'. Hosts that want the animation set 'smooth'
or 'smooth-auto' themselves.

* fix(diffs): keep the find match in view after two quick steps

In a split diff with long lines, step through find results twice in
quick succession, such as with a held Enter key. The current match can
end up scrolled out of view sideways, and nothing brings it back.

Stepping to a match scrolled its code column sideways straight from
the key handler. The two split columns copy each other's scroll
position on the next frame, so a second step inside the same frame was
overwritten by the first step's late copy.

The sideways scroll now runs only in the frame paint, once per frame,
as it did before the find panel work. Navigation still paints the
highlight ranges right away to read where the match is, without
scrolling.

* feat(diffs): find matches in collapsed files and collapsed context

CodeView find skipped collapsed items and, in unscoped search, the
unchanged lines hidden between hunks. Both are now searched. Landing on
a hidden match expands what hides it: the region through revealLine, the
file through updateItem with collapsed: false and a bumped version.

A hidden match counts as on screen when its file header or separator row
is, so find still starts from the first match in view.

isLineRenderable is renamed isLineInCollapsedContext, with the sense
flipped, and it and revealLine take a side. In CodeView an expansion is
applied at the next layout pass; until then VirtualizedFileDiff keeps
the expansion state as it will be, so a just-revealed line has a
position to scroll to.

* feat(diffs): add onItemCollapsedChange to CodeView

Find opens a collapsed item when it lands on a match inside it. An owner
that keeps its own item list was never told, so its next list still said
collapsed at the old version and the item closed again.

onItemCollapsedChange(item, nextItem) is called after CodeView itself
changes an item's collapsed state, with the item before the change and
the one CodeView has already applied. It is not called for changes the
owner makes, and it cannot veto. Find is the only caller.

* fix(diffs): clear the editor selection while markers or matches show

Editor.setSelections([]) with markers or find matches present scrolled
back to the old caret and focused the editor. The selection update only
dropped the stored selection when nothing else was drawn in the overlay;
otherwise it redrew the markers and matches and left the old selection
in state, and the scroll that follows found it.

An empty list now always clears the selection. Selecting a deleted line
had the same stale selection and is fixed by the same change.

* feat(diffs): group digits in counts for the i18n locale

Header counts were written raw and the i18n store turned every number
into text with String(), so the UI showed "+12345", "12345 unmodified
lines" and "1 of 10000".

The store now builds an Intl.NumberFormat for its locale. `#` in a
plural block and numeric arguments go through it, and i18n.formatNumber
covers counts that are not part of a message, which the diff header
uses. The header's cached HTML records the i18n version it was written
under, so a header picks up a locale change the next time it renders,
including one that happened while it was scrolled out of a CodeView.

FileDiff and File no longer subscribe to theme and message changes in
their constructors. They start listening when they first get a container
and stop in cleanUp. CodeView creates an instance per item, and a
full-list setItems left every new one listening whether or not it was
rendered: 300 new items meant 300 callbacks per change.

* fix(diffs): stop highlighting collapsed items

A collapsed item shows only its header, but it got that header by
running the full row pipeline with an empty render range. That asked
for a highlight of the whole diff or file: a worker pool task per
collapsed item, or a main-thread highlight without a pool.

Both renderers now have renderCollapsed, which returns the header and
the theme's styles, builds no rows and requests no highlight. When no
highlighter has the theme yet it loads one with the text language only
and asks for another render.

A collapsed item takes a new diff or file at once. The renderer keeps
the previous input's rows on screen until the new one is highlighted,
which for a collapsed item left the old name and counts in the header
until a highlight answer arrived. renderCollapsed also drops rows
cached for another input, and hydration state that only describes
prerendered DOM, since collapsing removes that DOM.

EMPTY_RENDER_RANGE has no remaining use and is removed.

* fix(diffs): tidy the find panel's leading spacing

A find-only panel had an extra 6px before the find input. The hidden
replace toggle still had its own grid column, and that column's gap
remained. With the toggle shown, the chevron sat off center: the
widget's padding on one side and the wider column gap on the other.

The grid now carries data-can-replace when the panel can replace, and
only then has a toggle column. The toggle's margin is the difference
between the widget's padding and the column gap, so it has the same
space on both sides in the wide and narrow layouts.

One helper sets the grid's mode, data-can-replace, and the toggle's
hidden and aria-expanded, in place of three copies of that code.

This branch was successfully deployed

4 active deployments
Preview – pierre-docs-diffs — 715b2de8 Deployed Nov 14, 2026 by vercel[bot]
Preview – pierre-diffshub — 715b2de8 Deployed Nov 14, 2026 by vercel[bot]
Preview – pierre-docs-trees — 715b2de8 Deployed Nov 14, 2026 by vercel[bot]
Preview – pierrejs-diff-demo — 715b2de8 Deployed Nov 14, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant