Skip to content

Fix a scroll fix if container grows#627

Merged
amadeus merged 3 commits into
beta-1.2from
amadeus/scroll-fix-bug
May 1, 2026
Merged

Fix a scroll fix if container grows#627
amadeus merged 3 commits into
beta-1.2from
amadeus/scroll-fix-bug

Conversation

@amadeus
Copy link
Copy Markdown
Member

@amadeus amadeus commented May 1, 2026

When scroll fixing due to option changes (like when changing diffStyle for example), the height of the scroll region could dramatically change. We had an optimization where we do the scroll fix prior to applying the new dom structure to help coalesce mutations together and not trigger unnecessary reflows. However, if the new adjusted scroll position was outside the bounds of the current window, then the scroll fix would ultimately get clamped and we wouldn't be in the right spot for the new dom that would then adjust the height of the scroll view.

Essentially the fix here is to first sync the new container height, then apply the early scroll fix so it doesn't get clamped.

I also realized we don't disable browser scroll anchoring on our root by default, and that's something that's very important and we should apply it and not depend on the user space applying this.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 1, 2026

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

Project Deployment Actions Updated (UTC)
pierre-docs-diffshub Error Error May 1, 2026 9:43pm
pierre-docs-trees Ready Ready Preview May 1, 2026 9:43pm
pierrejs-diff-demo Ready Ready Preview May 1, 2026 9:43pm
pierrejs-docs Ready Ready Preview May 1, 2026 9:43pm

Request Review

Copy link
Copy Markdown

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

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: 8dae2671ce

ℹ️ 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".

Comment thread packages/diffs/src/components/CodeView.ts
amadeus added 3 commits May 1, 2026 14:36
in certain cases when re-computing scroll position for an anchor, we'd
need to move to a scroll position that's not yet valid, and therefore
the pre-mutate position fix would fail because the scroll position would
get inherently clamped.

Now we adjust the height of the scroll region first, then pre-scroll
fix, then mutate/render to ensure it works properly
@amadeus amadeus force-pushed the amadeus/scroll-fix-bug branch from 8dae267 to ceaeff4 Compare May 1, 2026 21:41
@amadeus amadeus merged commit 97b7862 into beta-1.2 May 1, 2026
11 of 12 checks passed
@amadeus amadeus deleted the amadeus/scroll-fix-bug branch May 1, 2026 21:44
amadeus added a commit that referenced this pull request May 2, 2026
* Add scroll anchor regression test

* Fix a scroll fix if container grows

in certain cases when re-computing scroll position for an anchor, we'd
need to move to a scroll position that's not yet valid, and therefore
the pre-mutate position fix would fail because the scroll position would
get inherently clamped.

Now we adjust the height of the scroll region first, then pre-scroll
fix, then mutate/render to ensure it works properly

* pr review fix
amadeus added a commit that referenced this pull request May 7, 2026
* Add scroll anchor regression test

* Fix a scroll fix if container grows

in certain cases when re-computing scroll position for an anchor, we'd
need to move to a scroll position that's not yet valid, and therefore
the pre-mutate position fix would fail because the scroll position would
get inherently clamped.

Now we adjust the height of the scroll region first, then pre-scroll
fix, then mutate/render to ensure it works properly

* pr review fix
amadeus added a commit that referenced this pull request May 8, 2026
* Add scroll anchor regression test

* Fix a scroll fix if container grows

in certain cases when re-computing scroll position for an anchor, we'd
need to move to a scroll position that's not yet valid, and therefore
the pre-mutate position fix would fail because the scroll position would
get inherently clamped.

Now we adjust the height of the scroll region first, then pre-scroll
fix, then mutate/render to ensure it works properly

* pr review fix
amadeus added a commit that referenced this pull request May 8, 2026
* Add scroll anchor regression test

* Fix a scroll fix if container grows

in certain cases when re-computing scroll position for an anchor, we'd
need to move to a scroll position that's not yet valid, and therefore
the pre-mutate position fix would fail because the scroll position would
get inherently clamped.

Now we adjust the height of the scroll region first, then pre-scroll
fix, then mutate/render to ensure it works properly

* pr review fix
amadeus added a commit that referenced this pull request May 9, 2026
* Add scroll anchor regression test

* Fix a scroll fix if container grows

in certain cases when re-computing scroll position for an anchor, we'd
need to move to a scroll position that's not yet valid, and therefore
the pre-mutate position fix would fail because the scroll position would
get inherently clamped.

Now we adjust the height of the scroll region first, then pre-scroll
fix, then mutate/render to ensure it works properly

* pr review fix
amadeus added a commit that referenced this pull request May 9, 2026
* Add scroll anchor regression test

* Fix a scroll fix if container grows

in certain cases when re-computing scroll position for an anchor, we'd
need to move to a scroll position that's not yet valid, and therefore
the pre-mutate position fix would fail because the scroll position would
get inherently clamped.

Now we adjust the height of the scroll region first, then pre-scroll
fix, then mutate/render to ensure it works properly

* pr review fix
amadeus added a commit that referenced this pull request May 9, 2026
* Add scroll anchor regression test

* Fix a scroll fix if container grows

in certain cases when re-computing scroll position for an anchor, we'd
need to move to a scroll position that's not yet valid, and therefore
the pre-mutate position fix would fail because the scroll position would
get inherently clamped.

Now we adjust the height of the scroll region first, then pre-scroll
fix, then mutate/render to ensure it works properly

* pr review fix
amadeus added a commit that referenced this pull request May 12, 2026
* Add scroll anchor regression test

* Fix a scroll fix if container grows

in certain cases when re-computing scroll position for an anchor, we'd
need to move to a scroll position that's not yet valid, and therefore
the pre-mutate position fix would fail because the scroll position would
get inherently clamped.

Now we adjust the height of the scroll region first, then pre-scroll
fix, then mutate/render to ensure it works properly

* pr review fix
amadeus added a commit that referenced this pull request May 16, 2026
* Add scroll anchor regression test

* Fix a scroll fix if container grows

in certain cases when re-computing scroll position for an anchor, we'd
need to move to a scroll position that's not yet valid, and therefore
the pre-mutate position fix would fail because the scroll position would
get inherently clamped.

Now we adjust the height of the scroll region first, then pre-scroll
fix, then mutate/render to ensure it works properly

* pr review fix
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