-
-
Notifications
You must be signed in to change notification settings - Fork 125
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
Resize / scroll triggered multiple times after a page transition #46
Comments
@MoOx i think the bigger question here is whether switches should trigger window resize/scroll at all. Why not:
As far as I can tell, resize/scroll events is not even necessary for basic usage. However, I haven't yet used this library thoroughly. Maybe you will remember something. |
@darylteo if you click at a link in the bottom of the page and do not make an automatic scroll, the user experience is pretty weird: the page content change, but you are in the middle of the new content... |
Hmm... I think based on my experience, most of the time you'd expect to scroll to the top of the container while the content is loading. Devs can also choose to clear the target container and replace it with a loading indicator. There's also no guarantee that they want smooth scroll - and might prefer to jump to scroll position instead. I feel letting the developer decide what is best UX for their application is better rather than enforcing UX. I know you don't use this library anymore, but I don't know how you'd feel regarding changes to the library and the concepts and principles it subscribes to. Thoughts? |
Fair enough :) |
@MoOx What's the effect of triggering the |
Can't remember :/ |
I agree with @darylteo that we should deprecate triggering I also think that we don't need to trigger a new event like Instead, I think it should trigger Regarding scrolling, I think we should do as follows:
|
@MoOx what do you think? |
What about always triggering pjax:switch event but send a flag to say if it's user created or built-in? (for consistency) Scrolling proposal LGTM. |
If it's triggered by every switch, that would mean doing it in |
I think there are 3 options when to trigger
|
I think either triggering an event during each I already do something similar in my current project that's using Pjax whereby I have a custom async switch to handle switching the main page content which dispatches |
Why do you need events? Why can't you do whatever you need right inside the custom switch? |
@BehindTheMath I use events because my JS is modularised to ensure separation of concerns -- I have a component that is responsible for setting up Pjax and related functionality (topbar loading indicator etc.) and defining my custom switch, but other components that add specific functionality to my main content (e.g. a masonry grid) need to know when a switch is happening so that they can destroy and/or init themselves at the right time. |
Got it.
This would only work if the user passed the element to
This will be even easier if we switch to an event emitter (see #53). |
Good point -- we could do that, or we could pass a pre-bound callback to each switch function to call at the end of the switch process. i.e in
Sounds like a good idea -- but maybe something to do after pushing out a new release? Such a change would probably be a fairly extensive change and necessitate a major version bump (because it would be breaking compatibility with previous versions). Adding more user-facing events is already a minor version bump, according to SemVer. |
That's also a breaking change. I think it will be simpler to just have the user pass the element to
We have a breaking change already, I moved the trigger for the But I think you're right. I'll move the trigger back. We can finish up with any other PRs that won't have breaking changes, release 0.2.5, then milestone this and everything else for 0.3.0. |
Sounds like a good plan to me! |
Done, see 6000ad5. |
@MoOx Do you mind if we use milestones to keep track of what we want to implement when? |
Go ahead. You have full control here, I am just a visitor :) |
I have a page with multiple elements whose content pjax controls and each of those might use a different "switch" to swap the old content out for the new. After every page transition I have a bunch of scripts that handle how the new content is supposed to behave. Some of these need to also update on 'resize'.
The problem is that pjax triggers 'resize' and 'scroll' on every element "switch", so in my case would trigger resize & scroll 6 times for every page transition. The method responsible for that is: https://github.com/MoOx/pjax/blob/master/index.js#L72
My solution was to override the aforementioned
onSwitch
method with the following:This seems to work so far, but I am wondering whether there is a better way and/or whether pjax should handle triggering resize & scroll only once after a page transition internally.
The text was updated successfully, but these errors were encountered: