-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add setTimeout before calling onRouteUpdate to ensure React has writt…
…en to DOM before plugins run code
- Loading branch information
1 parent
a89057f
commit b5907c4
Showing
3 changed files
with
13 additions
and
16 deletions.
There are no files selected for viewing
7 changes: 2 additions & 5 deletions
7
packages/gatsby-plugin-google-analytics/src/gatsby-browser.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters