lundi 1 juin 2015

Odd behavior with "history.back" in Ember app using "replaceWith" running in iframe in FF

I have an Ember app running in an iframe. Page A has a link to page B, and page B has a link to page C implemented using 'Route#replaceWith', so that B does not remain in the history stack. Page C has a link which invokes history.back(), which should return to Page A. It does return to Page A, but in Firefox only after reloading the page. There is no reason to be reloading the page, and this behavior is not observed in Chrome. This behavior also does not occur unless the app is running in an iframe.

Here's the app:

// router.js
var Router = Ember.Router.extend({location:'hash'});
Router.map(function() { 'abc'.split('').forEach(x => this.route(x));});
export default Router;

// a/route.js
export default Ember.Route.extend({actions:{b:function(){this.transitionTo('b');}}});

// a/template.js
This is A.
<a href="#" {{action 'b'}}>Goto B!</a>

// b/route.js
import Ember from 'ember';
export default Ember.Route.extend({ actions: { link: function() { this.replaceWith('c'); } } });

// b/template.js
This is B.
<a href="#" {{action 'link'}}>GOTO C (no history entry)</a>

// c/route.js
export default Ember.Route.extend({ actions: { back: function() { history.back(); } } });

// c/template.hbs
This is C
<a href="#" {{action 'back'}}>Go back</a>

If I change the replaceWith in B with a transitionTo, and the history.back() in C with a history.go(-2) everything works fine and no reload occurs. But this is not a viable solution since the browser back button must also take the user back from C to A.

I am using locationType: 'hash' and cannot change this easily. The problem does not occur with locationType: 'history'.

The only reason I can think of why Firefox might be reloading the page when trying to return to A is due to more aggressive cache management. If that is in fact the problem, then I wonder if there's some way to tell Firefox to relax and take pages further back in the history from the cache instead of going back to the server again.

FYI, this is a fresh little Ember app running with the latest versions of everything in the stack.

Any and all ideas appreciated.




Aucun commentaire:

Enregistrer un commentaire