jquery-pjax icon indicating copy to clipboard operation
jquery-pjax copied to clipboard

problem scrollTo on popstate with maxCacheLength = 0

Open Nelrann opened this issue 9 years ago • 6 comments

Hi,

When using maxCacheLength = 0 on popstate event, the page scrollTo before replace content. Is it possible to scroll after replace content ?

Thx

Nelrann avatar Mar 20 '15 10:03 Nelrann

Hi! Good catch. This is a tricky problem.

When maxCacheLength is 0, basically that means pjax cache is disabled. That means that on popstate, we won't be able to restore the old page content from cache, but rather that we'll have to re-fetch previous page contents from the server.

Also, on popstate we don't do any manual scrolling (scrollTo is ignored). We expect the browser to restore previous scroll position. This works well if previous content is restored from cache. But, because we're re-fetching it as outlined above, the content will be injected into the page async, so the scroll position would sometimes be off, because of variable heights of different web documents.

I'm not sure what the solution would be. We could try keeping scroll positions of every page in state objects, then on popstate manually scroll to that stored position after asynchronously fetching the content.

mislav avatar Mar 21 '15 00:03 mislav

it can be a solution.

I cant use cache because I have trouble with some javascript plugin as select2 on popstate event .

Nelrann avatar Mar 21 '15 14:03 Nelrann

I cant use cache because I have trouble with some javascript plugin as select2 on popstate event .

What is the trouble? What is the plugin that misbehaves?

mislav avatar Mar 23 '15 21:03 mislav

I found two plugins on my site that have a problem

select2 => https://select2.github.io/ wysibb => http://www.wysibb.com/

these plugins are changing dom structure

Nelrann avatar Mar 26 '15 16:03 Nelrann

So because they're changing DOM structure (like most JS plugins), how did you find that they break with pjax?

mislav avatar Mar 27 '15 10:03 mislav

So I have a javascript function (function ApplyPlugins) that applies my JS plugins on my new content from ajax request (on "end" event )

When I do popstate the content of the page is ok from cache but plugins (select2, wysibb ..) does not work, the only way I've found is to reapply plugins on cache content with my function ApplyPlugins .

But with this logiqueI i apply 2 times plugins (or more if i do back next back next ...).

Nelrann avatar Apr 02 '15 13:04 Nelrann