Skip to content

refactor(diffs): Give diff hunk recompute a single owner per edit#905

Open
necolas wants to merge 1 commit into
beta-1.3from
diffs-single-recompute-owner
Open

refactor(diffs): Give diff hunk recompute a single owner per edit#905
necolas wants to merge 1 commit into
beta-1.3from
diffs-single-recompute-owner

Conversation

@necolas

@necolas necolas commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

updateRenderCache is now a token-content sync that returns the addition lines whose text changed; the incremental hunk recompute moves to recomputeContentHunks, surfaced through a new method applyContentEdit. The host drives exactly one recompute path per edit: applyContentEdit (incremental) for in-place content edits and applyDocumentChange (full) for line-count changes. Removes the skipDiffRecompute and shouldRefreshView parameters and the coordination they required. No behavior change.

@vercel

vercel Bot commented Jun 26, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
pierre-docs-diffs Ready Ready Preview Jun 27, 2026 7:34pm
pierre-docs-diffshub Ready Ready Preview Jun 27, 2026 7:34pm
pierre-docs-trees Ready Ready Preview Jun 27, 2026 7:34pm
pierrejs-diff-demo Ready Ready Preview Jun 27, 2026 7:34pm

Request Review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 39c1326d55

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 407 to +409
result.baseThemeType = themeType;
this.renderCache.isDirty = true;
return changedAdditionLines;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep hunk recompute for deferred edit tokens

When a content-only edit lands outside a virtualized diff's current render range, EditorTokenizer delivers that changed line through Editor.#onDeferTokenize, whose only cache hook is updateRenderCache(lines, themeType). Since this method now just returns the changed addition lines and the deferred caller ignores the return value, the background/offscreen path updates diff.additionLines but never calls recomputeContentHunks; scrolling to that edited line later can render it with stale hunk metadata (for example as unchanged context instead of a new change). The synchronous visible-edit path was updated to consume the return value, but the deferred path still needs an owner for the recompute.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in aea8a2b. The deferred/offscreen tokenize path (Editor.#onDeferTokenize) now recomputes hunks for the changed lines via a new recomputeContentHunks (recompute only, no view refresh), so a content-only edit that lands outside the render window keeps its hunk metadata in sync instead of dropping the recompute after the token/recompute split. The visible rows are still patched separately, and line-count edits remain handled by applyDocumentChange.

@ije ije left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

updateRenderCache is now a token-content sync that returns the addition
lines whose text changed; the hunk recompute moves to a dedicated
recomputeContentHunks method. The host drives the recompute explicitly
per edit: applyContentEdit (recompute + refresh) for visible content
edits, recomputeContentHunks (recompute only) for content edits the
background tokenizer delivers offscreen, and applyDocumentChange (full)
for line-count changes. Removes the skipDiffRecompute and
shouldRefreshView parameters and the coordination they required. No
behavior change.
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.

2 participants