Skip to content

Conversation

gaearon
Copy link
Contributor

@gaearon gaearon commented Sep 30, 2025

Fixes #9095

This logic is luckily web-only.

To repro, you have to navigate to a reply and then navigate to another one (e.g. upwards).

I don't understand the logic quite enough to tell what's happening, but for some reason we were setting shouldHandleScroll.current = false a bit too early. This function runs an extra time in this scenario and we end up missing the last event when we actually should scroll.

I changed the condition to what seems to make it work: only stop attempting after one positive scroll. I don't know if this is a perfect heuristic but seems to work at least on Chrome. You'll probably want to test FF, Safari, and Mobile Safari.

Test Plan

I was doing stuff like this. Previously it would lose scroll position.

fix.mov

@gaearon
Copy link
Contributor Author

gaearon commented Sep 30, 2025

Curiously the bug repro's on main but not in prod. Idk what's up with that.

@estrattonbailey estrattonbailey self-requested a review September 30, 2025 01:55
@estrattonbailey
Copy link
Member

Curiously the bug repro's on main but not in prod. Idk what's up with that.

Yeah wth, that's odd

@gaearon
Copy link
Contributor Author

gaearon commented Sep 30, 2025

It's gotta be either dev/prod difference or a regression since last deploy. Would be good to confirm which is that, and why. I'm not entirely comfortable with the > 0 condition because if it never happens (for one or the other reason), the scroll will keep readjusting on each resize.

@estrattonbailey
Copy link
Member

Must be something in #8931. RN-for-web doesn't seem to be the culprit. Lot of changes in RN itself of course.

It seems that after setDeferParents(true) runs, onContentSizeChange fires 2x now, whereas before it ran 1x. Basically, I think it's running both before and after the DOM has updated to give us a positive offset for the anchor, and we're disabling scroll handling after the first pass.

The intent here is that if shouldHandleScroll.current === true, then we want to ensure that the anchor offset is reset back to 0. So you nailed that.

I think your concern about the > 0 condition is a good instinct. If there are any parents of a post — including deleted tombstones and such — that offset value will be > 0. It will be < 0 for the root post, but that's handled by the isRoot check.

I could also theoretically happen if we're expecting parents to be prepended and after setDeferParents(true) runs, and the API returns nothing or nothing is prepended for some reason. Then yeah onContentSizeChange will not run and we won't reset shouldHandleScroll. I don't think this case would blow us up though — actually it mostly works if we never reset it, except for the resize case. Subsequent navigations or a content resize should recover the broken state.

I don't want to claim there aren't other edge cases, but I think this this one is unlikely to happen and recoverable in the case it does. I think your fix is good and we can roll with it for now 👍

Copy link
Member

@estrattonbailey estrattonbailey left a comment

Choose a reason for hiding this comment

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

Thanks for this! I think it's a solid solve, and it was good to revisit this logic. It's been a few months, nice refresher. We'll keep an eye on this in the near future.

@estrattonbailey estrattonbailey merged commit 5df6036 into bluesky-social:main Sep 30, 2025
7 checks passed
NekoDrone pushed a commit to NekoDrone/catsky-social that referenced this pull request Oct 1, 2025
* Send inferrable interactions to third-party feeds (bluesky-social#9094)

* Fix link crash (bluesky-social#9102)

* fix link crash

* fix link crash

* Log OTA errors properly (bluesky-social#9101)

* Log OTA errors properly

* filter out network errors

* don't send some "activity no longer available" errors (bluesky-social#9100)

* remove root sibling library (bluesky-social#9097)

* Catch errors on geolocation request, reduce Sentry logs (bluesky-social#9098)

* Nightly source-language update

* fix gap on profile (bluesky-social#9081)

* Update admonition component (bluesky-social#9068)

* update admonition component

* fix linting, adominition alighment

* design tweak

* edge cases for admonition, update storybook

* Update src/components/Admonition.tsx

Co-authored-by: Samuel Newman <[email protected]>

* fix mobile version

* change button style

---------

Co-authored-by: Samuel Newman <[email protected]>

* Button tweaks (bluesky-social#9106)

* Tweak button colors

* Semi bold only for tiny buttons

* [Web] Fix thread jumps (bluesky-social#9111)

* [Web] Fix thread jumps

* Comment formatting

---------

Co-authored-by: Eric Bailey <[email protected]>

* Add StackedButton component (bluesky-social#9086)

---------

Co-authored-by: dan <[email protected]>
Co-authored-by: Samuel Newman <[email protected]>
Co-authored-by: pfrazee <[email protected]>
Co-authored-by: Chenyu <[email protected]>
Co-authored-by: Eric Bailey <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
estrattonbailey added a commit that referenced this pull request Oct 1, 2025
…ge-selection

* origin/main: (29 commits)
  add patent pledge link to readme (#9118)
  Fix feedfeedback metrics not distinguishing which feed it's from (#9099)
  Nightly source-language update
  Add StackedButton component (#9086)
  [Web] Fix thread jumps (#9111)
  Button tweaks (#9106)
  Update admonition component (#9068)
  fix gap on profile (#9081)
  Nightly source-language update
  Catch errors on geolocation request, reduce Sentry logs (#9098)
  remove root sibling library (#9097)
  don't send some "activity no longer available" errors (#9100)
  Log OTA errors properly (#9101)
  Fix link crash (#9102)
  Send inferrable interactions to third-party feeds (#9094)
  patch react native screens (#9087)
  fix: remove escapejs and fix profile issues
  feat: profile.html escapejs
  feat: post.html structured content, wip
  feat: profile.html structured content
  ...
NekoDrone added a commit to NekoDrone/catsky-social that referenced this pull request Oct 3, 2025
* Send inferrable interactions to third-party feeds (bluesky-social#9094)

* Fix link crash (bluesky-social#9102)

* fix link crash

* fix link crash

* Log OTA errors properly (bluesky-social#9101)

* Log OTA errors properly

* filter out network errors

* don't send some "activity no longer available" errors (bluesky-social#9100)

* remove root sibling library (bluesky-social#9097)

* Catch errors on geolocation request, reduce Sentry logs (bluesky-social#9098)

* Nightly source-language update

* fix gap on profile (bluesky-social#9081)

* Update admonition component (bluesky-social#9068)

* update admonition component

* fix linting, adominition alighment

* design tweak

* edge cases for admonition, update storybook

* Update src/components/Admonition.tsx

Co-authored-by: Samuel Newman <[email protected]>

* fix mobile version

* change button style

---------

Co-authored-by: Samuel Newman <[email protected]>

* Button tweaks (bluesky-social#9106)

* Tweak button colors

* Semi bold only for tiny buttons

* [Web] Fix thread jumps (bluesky-social#9111)

* [Web] Fix thread jumps

* Comment formatting

---------

Co-authored-by: Eric Bailey <[email protected]>

* Add StackedButton component (bluesky-social#9086)

* Nightly source-language update

* Fix feedfeedback metrics not distinguishing which feed it's from (bluesky-social#9099)

* fix feedfeedback metrics being sent for all feeds

* remove `discover:` metrics

* add patent pledge link to readme (bluesky-social#9118)

* Language selection and suggestion UX improvements (bluesky-social#9067)

* feat: don't retain accepted language suggestion after finishing or exiting post (bluesky-social#8886)

* feat: don't retain accepted language suggestion after finishing or exiting post

* fix: rebase fixes

* fix: rebase fixes

* chore: lint

* Rename onChange for clarity

* Improve logic in composer

* Handle user override more explicitly

* Drill in onSelectLanguage callback into dialog too

* Fix typo

Co-authored-by: surfdude29 <[email protected]>

* Make text crystal clear

* Handle multiple languages

---------

Co-authored-by: Elijah Seed-Arita <[email protected]>
Co-authored-by: surfdude29 <[email protected]>

* Tighten up eslint rule to catch unused `const {_} = useLingui()` (bluesky-social#9122)

* tighten eslint config to catch unused `useLingui`s

* fix now-invalid uses of _

* remove unused function that produces a ton of eslint warnings

* upgrade react compiler plugin

* [Fix Logouts] Remove buggy hackfix (bluesky-social#9108)

* Rip out the network hack in favor of bluesky-social/atproto#4238

* Bump api pkg

* Debug code

* Revert "Debug code"

This reverts commit 38445f3.

---------

Co-authored-by: Eric Bailey <[email protected]>

* Nightly source-language update

* fix: missed alf reversion

---------

Co-authored-by: dan <[email protected]>
Co-authored-by: Samuel Newman <[email protected]>
Co-authored-by: pfrazee <[email protected]>
Co-authored-by: Chenyu <[email protected]>
Co-authored-by: Eric Bailey <[email protected]>
Co-authored-by: Daniel Holmgren <[email protected]>
Co-authored-by: Elijah Seed-Arita <[email protected]>
Co-authored-by: surfdude29 <[email protected]>
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.

Navigating between posts in the thread often loses scroll position
2 participants