Skip to content

Bug/STC-469: Highlight and scroll to activity comment on anchor change#23894

Draft
akabiru wants to merge 4 commits into
devfrom
bug/stc-469-highlight-anchor-on-hashchange
Draft

Bug/STC-469: Highlight and scroll to activity comment on anchor change#23894
akabiru wants to merge 4 commits into
devfrom
bug/stc-469-highlight-anchor-on-hashchange

Conversation

@akabiru

@akabiru akabiru commented Jun 23, 2026

Copy link
Copy Markdown
Member

STC-469

Updating the activity-tab anchor without a full page load didn't scroll to or highlight the referenced comment - whether clicking a comment-reference link inside another comment, or editing #comment-<id> in the address bar.

Two separate causes. The auto-scrolling controller only acted on initial render, so later hash changes were ignored; a hashchange listener now reacts to all of them. And a comment-reference link is a plain link inside the activities Turbo frame, so Turbo claimed the click as a navigation and dropped the fragment before anything could react; same-page comment links are now routed through the hash, while links to other pages and external links are left untouched.

A previous attempt (#20609) was closed because its scroll-detection rework left a large empty gap at the bottom of the activity list. This keeps the existing initial-load scrolling untouched and never resizes or pads the container, so it can't reintroduce that. The old offsetTop-based math measured against the wrong ancestor; the scroll target now comes from the comment's position within the actual scroll container, which is correct in the full view, split screen, notification center, and on mobile.

Legacy #activity-<n> anchors aren't handled on a hash change, since resolving a sequence version to a comment needs the server, which a same-page hash change never reaches.

highlight-on-click.mp4

@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./spec/features/projects/lists/filters_spec.rb[1:6:1]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #23894, linked for reference only):

- `rspec ./spec/features/projects/lists/filters_spec.rb[1:6:1]`

Treat this as a standalone task, unrelated to PR #23894. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #23894 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @akabiru to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @akabiru, and request a review from @akabiru.
On every commit, set @akabiru as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./modules/backlogs/spec/features/backlogs/create_spec.rb[1:3:2]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #23894, linked for reference only):

- `rspec ./modules/backlogs/spec/features/backlogs/create_spec.rb[1:3:2]`

Treat this as a standalone task, unrelated to PR #23894. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #23894 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @akabiru to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @akabiru, and request a review from @akabiru.
On every commit, set @akabiru as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

akabiru added 3 commits June 24, 2026 14:35
Changing the activity URL hash without a page load (an in-page comment link or a manual URL edit) left the referenced comment un-highlighted and un-scrolled, since scrolling only ran on initial render. Add a hashchange handler that highlights and scrolls to the comment, positioned relative to the scroll container so it lands correctly in every activity-tab context. Legacy activity-N anchors are left to the server, which a hash change cannot reach.

Ref: STC-469
A comment-reference link in a comment body is a plain link inside the activities turbo-frame, so Turbo claimed the click as a frame/page visit and dropped the #comment fragment, leaving the referenced comment un-scrolled and un-highlighted. Intercept clicks on links that point to a comment on the current activity page and route them through the hash, letting the hashchange handler scroll and highlight. Links to other pages and external links are left untouched.

Ref: STC-469
@akabiru akabiru force-pushed the bug/stc-469-highlight-anchor-on-hashchange branch from b12d717 to f3579b0 Compare June 24, 2026 11:40
Address review findings on the activities hashchange handling. The window
hashchange listener fires on every live controller, so resolve the anchor
element within this.element rather than the document, and construct the
AbortController in connect so a reconnect rebinds its listeners. Only claim
an in-content comment click when the target is rendered here, otherwise let
it navigate instead of swallowing it into a hash change that resolves to
nothing. Drop the fixed sleeps in the specs; the highlight assertion already
waits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant