Returning to a search via back

(Andrew Waugh) #1

A user asked about this today.

If you’ve used search to get a list of posts, scroll down then click on one of them, if you then use the back function in the browser it always returns you to the top of the search results.

If you view a category, scroll down, then open a topic, the back button returns you to your previous scrolling position.

(Sam Saffron) #2

I believe this was reported before but can not find the topic or discussion fragment, its a bug we should fix.

(Jeff Atwood) #3

Sure if this is not too hard or risky maybe @eviltrout could take it.

(Bianca) #5


I have been trying to fix this issue. I implemented it like this so far: Comparing discourse:master...nbianca:scroll_tracking · discourse/discourse · GitHub

The issue is that even though scrollTo has the right value in didInsertElement, the scrollTop method does not seem to work (probably rendering has not finished?).

Can anyone take a look, please?

(Joffrey Jaffeux) #6

Hi Bianca,

I would implement it this way:

import Scrolling from "discourse/mixins/scrolling";

export default Ember.Component.extend(Scrolling, {
  didInsertElement() {

    this.bindScrolling({ name: this.get("name") });

  didRender() {

    const scrollToY = this.session.get(this.get("trackerName"));
    if (scrollToY && scrollToY >= 0) { => $(window).scrollTop(scrollToY + 1));

  didReceiveAttrs() {

    this.set("trackerName", `scroll-tracker-${this.get("name")}`);

  willDestroyElement() {


  scrolled() {

    this.session.set(this.get("trackerName"), $(window).scrollTop());

It should work, feel free to modify the coding style. Thanks for your contribution.

(Bianca) #7

Thank you a lot! :confetti_ball: That fixed my issue and made my code look a lot better.

I submitted this pull request: Scroll is tracked on search page. by nbianca · Pull Request #5040 · discourse/discourse · GitHub

(Joffrey Jaffeux) #8

Merged, thanks Bianca.