Skip to content
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

Consider all query params in parent routes #97

Closed

Conversation

hbrysiewicz
Copy link

@hbrysiewicz hbrysiewicz commented Feb 28, 2018

Currently only the most recent transition is examined to determine whether to preserve the scroll position. This means that any parent route query parameters are not being respected. This works fine for isolated pages, like the tab example, but does not work when query params exist on the application route, for example.

In my case I dynamically set query parameters on the application route to show/hide modals. I would expect that when I set preserveScrollPosition=true on the application controller that even though I'm on a deeply nested sub-route it would be respected. Currently this is not the case.

This PR updates the line that examines only the last transition so that it checks all transitions involved to see if any of them have the parameter set.

@hbrysiewicz hbrysiewicz force-pushed the respect-query-params branch 3 times, most recently from 785f18b to bff1c81 Compare February 28, 2018 20:43
Copy link
Collaborator

@snewcomer snewcomer left a comment

Choose a reason for hiding this comment

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

@hbrysiewicz Looks like a conflict that could be resolved, but otherwise I like the concept!

@@ -44,7 +44,7 @@ export default Mixin.create({
}
const scrollElement = get(this, 'service.scrollElement');

const preserveScrollPosition = get(lastTransition, 'handler.controller.preserveScrollPosition');
const preserveScrollPosition = transitions.some((transition) => get(transition, 'handler.controller.preserveScrollPosition'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to walk backwards on the transitions. Would it make a difference here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@hbrysiewicz So if there are 5 transitions do we want to start at the last one and walk backwards until we find one with handler.controller.preserveScrollPosition? This way will start at the earliest one. What are your thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah you are right. It's just a boolean value. Ignore my comment!

@yowainwright yowainwright reopened this Apr 7, 2018
@yowainwright
Copy link
Contributor

yowainwright commented Apr 7, 2018

@hbrysiewicz I apologize. I switched to CircleCi and changed linting.

If you could get the latest from master and run:

yarn 
yarn eslint

After you push this PR should be GTG. ~🙏

@yowainwright
Copy link
Contributor

@hbrysiewicz @snewcomer I'm happy to get this branch setup with passing checks. ...I don't want to mess with @hbrysiewicz's awesome work, though.

Let me know. 🙏

@snewcomer
Copy link
Collaborator

@hbrysiewicz I think is is a good addition. Might be best to open another PR at this point, esp with this commit that landed in master.

What do you think?

@hbrysiewicz hbrysiewicz force-pushed the respect-query-params branch from 9038f44 to 9d02eff Compare April 24, 2018 16:55
@hbrysiewicz
Copy link
Author

@snewcomer was able to get this updated

@@ -44,7 +44,7 @@ export default Mixin.create({
}
const scrollElement = get(this, 'service.scrollElement');

const preserveScrollPosition = get(lastTransition, 'handler.controller.preserveScrollPosition');
const preserveScrollPosition = transitions.some((transition) => get(transition, 'handler.controller.preserveScrollPosition'));
Copy link
Collaborator

Choose a reason for hiding this comment

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

@hbrysiewicz So if there are 5 transitions do we want to start at the last one and walk backwards until we find one with handler.controller.preserveScrollPosition? This way will start at the earliest one. What are your thoughts?

@@ -61,7 +61,7 @@
"test:all": "ember try:each"
},
"dependencies": {
"ember-app-scheduler": "^0.2.0",
"ember-app-scheduler": "kyleshay/ember-app-scheduler#64a0c91d8866b356439bb2d3068029ac59490090",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we try 0.2.2 here? Fyi - ember-app-scheduler is not the default anymore.

Copy link
Author

Choose a reason for hiding this comment

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

Not sure what you mean "not the default anymore"
Was this dep removed?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Still there. Just you need to opt into ember-app-scheduler (see README). There was a noticeable jump in the dummy app b/c ember-app-scheduler moves work until after first meaningful paint. To get rid of that jump, we schedule scrollTop work in the render queue.

Lmk if you notice or have any thoughts on that. I could have missed something...

#101

@hbrysiewicz
Copy link
Author

@snewcomer - it doesn't matter which controller it is set on, its a query param. So if its in the URL, any controller that has it set should have the same value.

@Duder-onomy
Copy link
Contributor

Duder-onomy commented Aug 3, 2018

@snewcomer @hbrysiewicz
This PR makes this lib able to use in our app.

We previously had our own reset-scroll solution, but I was constantly fixing it. So, I just ripped ours out and threw ember-router-scroll in and it works great.
The only issue is we have TONS of deeply nested modal type routes. The controller that is handling in-page actions is almost never the top most transition. So setting preserveScrollPosition where the action was handled was never taken into account.

This PR fixes our issue very nicely!

What is stopping this from being dusted off and merged? (is there anything I can do?)

If I understand correctly, from looking at the commits, it seems like only a 1 line diff.
Changing this line
From :
const preserveScrollPosition = get(lastTransition, 'handler.controller.preserveScrollPosition');
To :
const preserveScrollPosition = transitions.some((transition) => get(transition, 'handler.controller.preserveScrollPosition'));

@snewcomer
Copy link
Collaborator

@Duder-onomy Just a rebase + revert change to pkg.json!

@Duder-onomy
Copy link
Contributor

Just opened #149 to speed the process.

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.

4 participants