Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions packages/gatsby-plugin-google-analytics/src/gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
exports.onRouteUpdate = function({ location }) {
// Don't track while developing.
if (process.env.NODE_ENV === `production` && typeof ga === `function`) {
// Wait for the title update (see #2478)
setTimeout(() => {
window.ga(`set`, `page`, (location || {}).pathname)
window.ga(`send`, `pageview`)
}, 0)
window.ga(`set`, `page`, (location || {}).pathname)
window.ga(`send`, `pageview`)
}
}
17 changes: 7 additions & 10 deletions packages/gatsby-plugin-twitter/src/gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
exports.onRouteUpdate = function({ location }) {
// Wait to ensure page is rendered first.
setTimeout(() => {
if (
typeof twttr !== `undefined` &&
window.twttr.widgets &&
typeof window.twttr.widgets.load === `function`
) {
window.twttr.widgets.load()
}
}, 0)
if (
typeof twttr !== `undefined` &&
window.twttr.widgets &&
typeof window.twttr.widgets.load === `function`
) {
window.twttr.widgets.load()
}
}
5 changes: 4 additions & 1 deletion packages/gatsby/cache-dir/production-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ apiRunnerAsync(`onClientEntry`).then(() => {

history.listen((location, action) => {
if (!maybeRedirect(location.pathname)) {
apiRunner(`onRouteUpdate`, { location, action })
// Make sure React has had a chance to flush to DOM first.
setTimeout(() => {
apiRunner(`onRouteUpdate`, { location, action })
}, 0)
}
})
}
Expand Down