veliovgroup / Meteor-flow-router-title

Change document.title on the fly within flow-router
https://atmospherejs.com/ostrio/flow-router-title
BSD 3-Clause "New" or "Revised" License
25 stars 4 forks source link

Prevent new title showing as old title in browser history #10

Closed fishsaidno closed 5 years ago

fishsaidno commented 5 years ago

Hey, thanks for all the great work on these packages.

The issue I'm experiencing:

It seems that when changing the page title at the route level, the title updates before the old route is pushed to the browser's history.

E.g.

FlowRouter.route('/', {
   name: 'index',
   title(params, query, data) {
      return 'Home Page'
   }
});
FlowRouter.route('/page-2', {
   name: 'page-2',
   title(params, query, data) {
      return 'Page 2'
   }
});

Upon navigating to the site's index the browser's history will be like so: Flow-router-title-1 All is well. However after navigating to Page 2, the history will be: Flow-router-title-2

This is the issue. Page 2 should be Home Page. Navigating back will correctly take you to the home page, it's just the title in the history is incorrect.

This PR resolves the issue by adding a 0ms timeout to the setting of document.title.

Cheers, Morgan

dr-dimitru commented 5 years ago

Hello @FishSaidNo ,

Thank you for contribution!

  1. Do you have more insights? Like what browsers and platforms are affected?
  2. Does it acts the same way when title is String?
  3. Have you successfully ran tests after those changes?