vojtech-dobes / nette.ajax.js

Flexible AJAX for Nette Framework. Supports snippets, redirects etc.
https://componette.org/vojtech-dobes/nette.ajax.js/
MIT License
149 stars 85 forks source link

Wrong browser history title when used with history.nette.ajax.js #151

Open zipper opened 7 years ago

zipper commented 7 years ago

Not sure which repository should I use for this issue, since it's dependent on using both. When used in combination with https://github.com/vojtech-dobes/history.nette.ajax.js, there is a bug in browser history titles in Google Chrome (oddly, FireFox handles it right).

When you use <title> tag as a snippet, document.title is changed prior to pushState call. That results in wrong title in Google Chrome history (long press on back button). Lets assume these steps:

  1. Being on page with "Title 1".
  2. Trigger AJAX call which invalidates title snippet, returning "Title 2" as its new content.
  3. Extension snippets updates the title, so it's now "Title 2".
  4. pushState from history.nette.ajax.js is called. First state in history is now titled "Title 2" (as it was last document.title of the page), the new one has the same title (as it is the current document.title).

I'm not sure how to approach this issue, since snippets has to updated before pushState call (because of UI cache) but title has to be unchanged until the pushState call. Moreover, when traversing back in history, the title stays unchanged if UI cache is turned off (I guess this might be treated as separate issue, but it may also be solved with this issue).