0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-11 02:59:07 +08:00
discourse/spec/system/page_objects/pages/user_activity_stream.rb
David Battersby b5961484c9
FIX: preserve scroll position when returning to user activity streams (#42435)
Scrolling a user activity stream far enough to trigger infinite scroll,
opening a topic, then pressing back would land the user higher up the
page than where they left off.

The scroll position was being restored correctly, but the stream was
refetched from scratch, so the page only held its first page of items
and was too short to scroll back to the saved offset — the browser
clamped it.

On a back/forward navigation we now reuse the stream we left behind,
including everything infinite scroll appended, so the page is the same
height it was and the restored position lands where the user was
reading. The stream is stored per history entry via the historyStore
service, so ordinary forward navigation still loads a fresh stream.

Meta bug report:
https://meta.discourse.org/t/regression-u-username-activity-loses-scroll-position-after-browser-back/406292
2026-08-07 16:36:28 +04:00

37 lines
812 B
Ruby
Vendored

# frozen_string_literal: true
module PageObjects
module Pages
class UserActivityStream < PageObjects::Pages::Base
def visit_replies(user)
page.visit("/u/#{user.username_lower}/activity/replies")
self
end
def has_items?(count:)
page.has_css?(".user-stream-item", count:)
end
def scroll_to_bottom
page.scroll_to(:bottom)
self
end
def scroll_to_item(index)
page.execute_script(
"document.querySelectorAll('.user-stream-item')[#{index}].scrollIntoView(true)",
)
self
end
def open_item(index)
page.all(".user-stream-item .title a")[index].click
self
end
def scroll_position
page.evaluate_script("window.scrollY")
end
end
end
end