-
Notifications
You must be signed in to change notification settings - Fork 72
fix(webview): rescroll target post once content swap settles (#631) #810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -159,6 +159,45 @@ public void runJavascript(@NonNull String javascript) { | |||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Issue #631: the thread page is rendered by swapping innerHTML, so | ||||||||||||
| * neither WebViewClient.onPageFinished nor any other lifecycle | ||||||||||||
| * callback fires when the actual posts arrive. This helper installs | ||||||||||||
| * a MutationObserver that watches the post container and, once it | ||||||||||||
| * has been quiet for a beat, scrolls the target anchor back into | ||||||||||||
| * view. Call this after {@link #setBodyHtml(String)} when the | ||||||||||||
| * caller knows which post the user came in on. | ||||||||||||
| * | ||||||||||||
| * @param anchorId the DOM id of the target post (no leading hash). | ||||||||||||
| * Pass null to fall back to the URL fragment. | ||||||||||||
| */ | ||||||||||||
| public void scrollToTargetAfterContentSettles(@Nullable String anchorId) { | ||||||||||||
| String target = anchorId == null ? "null" : "'" + anchorId.replace("'", "") + "'"; | ||||||||||||
| runJavascript( | ||||||||||||
| "(function(){" + | ||||||||||||
| "var anchorId = " + target + ";" + | ||||||||||||
|
Comment on lines
+175
to
+178
|
||||||||||||
| "var quiet;" + | ||||||||||||
| "function jump() {" + | ||||||||||||
| "var id = anchorId || (location.hash || '').replace('#','');" + | ||||||||||||
| "if (!id) { return; }" + | ||||||||||||
| "var el = document.getElementById(id);" + | ||||||||||||
| "if (el) { el.scrollIntoView({block: 'start'}); }" + | ||||||||||||
|
||||||||||||
| "if (el) { el.scrollIntoView({block: 'start'}); }" + | |
| "if (el) {" + | |
| "try { el.scrollIntoView({block: 'start'}); }" + | |
| "catch (e) { el.scrollIntoView(true); }" + | |
| "}" + |
Copilot
AI
Apr 25, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 2s fallback setTimeout will still fire even if the observer already detected "quiet" and called jump(), causing a second jump later (potentially yanking the user back after they started scrolling). Track the fallback timeout ID and cancel it when jump() runs, or gate jump() with a didJump flag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper is not referenced anywhere in the app yet (no call sites found), so the behavior described in the PR title/"Closes #631" won’t actually take effect. Either wire it up from the intended caller (e.g.,
ThreadDisplayFragmentaftersetBodyHtml) or adjust the PR title/description and avoid closing the issue until it’s integrated.