Skip to content
This repository was archived by the owner on May 16, 2019. It is now read-only.

Commit 39d48e1

Browse files
committed
fixing issue where navigating to a cached page we are already on looks like nothing happened because page is rendered so fast
1 parent e19fbe1 commit 39d48e1

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

js/router.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ module.exports = Backbone.Router.extend({
198198
};
199199
},
200200

201-
newView: function(View, options, ignoreCache) {
201+
newView: function(View, options) {
202202
var now = Date.now(),
203203
cached = this.viewCache[View.getCacheIndex(Backbone.history.getFragment())],
204204
requestedRoute = Backbone.history.getFragment(),
@@ -251,7 +251,7 @@ module.exports = Backbone.Router.extend({
251251
}
252252
}
253253

254-
if (cached && (now - cached.cachedAt < cached.view.cacheExpires && !ignoreCache)) {
254+
if (cached && (now - cached.cachedAt < cached.view.cacheExpires)) {
255255
// we have an un-expired cached view, let's reattach it
256256
this.view = cached.view;
257257

@@ -352,8 +352,6 @@ module.exports = Backbone.Router.extend({
352352
},
353353

354354
home: function(state, searchText){
355-
//if search terms have been given, don't use cached views
356-
var ignoreCache = Boolean(searchText);
357355
this.newView(homeView, {
358356
viewArgs: {
359357
userModel: this.userModel,
@@ -362,7 +360,7 @@ module.exports = Backbone.Router.extend({
362360
state: state,
363361
searchItemsText: searchText
364362
}
365-
}, ignoreCache);
363+
});
366364

367365
// hide the discover onboarding callout
368366
this.$discoverHolder = this.$discoverHolder || $('.js-OnboardingIntroDiscoverHolder');

js/start.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,16 @@ $(window).bind('keydown', function(e) {
347347

348348
if (route !== null) {
349349
e.preventDefault();
350-
Backbone.history.navigate(route, {
351-
trigger: true
352-
});
350+
351+
if (location.hash.startsWith('#' + route)) {
352+
// Hard refresh if we're already on the page we're trying to route to
353+
// so a cached page is not served.
354+
app.router.refresh();
355+
} else {
356+
Backbone.history.navigate(route, {
357+
trigger: true
358+
});
359+
}
353360
}
354361
}
355362
});
@@ -471,7 +478,19 @@ var loadProfile = function(landingRoute, onboarded) {
471478
}).on('click-restart-now', () => {
472479
location.reload();
473480
}).render().open();
474-
});
481+
});
482+
483+
// If navigating to a page you're already on, we'll hard refresh so
484+
// a cached page is not served, which avoids the issue of it looking
485+
// like nothing happened.
486+
$(document).on('click', '[href^="#"]', (e) => {
487+
var href = $(e.target).attr('href');
488+
489+
if (location.hash.startsWith(href)) {
490+
app.router.refresh();
491+
e.preventDefault();
492+
}
493+
});
475494

476495
app.router = new router({userModel: user, userProfile: userProfile, socketView: newSocketView});
477496

0 commit comments

Comments
 (0)