Configure delay for 'onRouteUpdateDelayed' hook ?
See original GitHub issueSummary
Is it possible to configure the delay for ‘onRouteUpdateDelayed’ hook ?
Relevant information
Documentation link: https://www.gatsbyjs.org/docs/browser-apis/#onRouteUpdateDelayed
For my page I implement a loading indicator. Therefore I would like to configure the default delay for the ‘onRouteUpdateDelayed’ hook. Currently I use it inside the gatsby-browser.js like so:
exports.onRouteUpdateDelayed = () => {
window.___emitter.emit('onRouteUpdateDelayed');
};
The default delay is 1s but i would like to show the spinner earlier like after 500ms or so…
Gatsby info
System:
OS: macOS 10.15.4
CPU: (8) x64 Intel(R) Core(TM) i7-4980HQ CPU @ 2.80GHz
Shell: Unknown
Binaries:
Node: 12.13.0 - ~/.nvm/versions/node/v12.13.0/bin/node
npm: 6.13.7 - ~/.nvm/versions/node/v12.13.0/bin/npm
Languages:
Python: 2.7.16 - /usr/bin/python
Browsers:
Chrome: 81.0.4044.129
Firefox: 75.0
Safari: 13.1
npmPackages:
gatsby: ^2.20.12 => 2.20.15
gatsby-image: ^2.3.1 => 2.3.1
gatsby-plugin-layout: ^1.2.2 => 1.2.2
gatsby-plugin-manifest: ^2.3.3 => 2.3.3
gatsby-plugin-offline: ^3.1.2 => 3.1.2
gatsby-plugin-react-helmet: ^3.2.1 => 3.2.1
gatsby-plugin-react-svg: 3.0.0 => 3.0.0
gatsby-plugin-sass: ^2.2.1 => 2.2.1
gatsby-plugin-sharp: ^2.5.3 => 2.5.3
gatsby-source-filesystem: 2.3.0 => 2.3.0
gatsby-source-multi-api: 1.0.3 => 1.0.3
gatsby-transformer-json: 2.4.0 => 2.4.0
gatsby-transformer-sharp: ^2.4.3 => 2.4.3
File contents (if changed)
gatsby-config.js
: N/A
package.json
: N/A
gatsby-node.js
: N/A
gatsby-browser.js
:
exports.onRouteUpdateDelayed = () => {
window.___emitter.emit('onRouteUpdateDelayed');
};
exports.onRouteUpdate = () => {
window.___emitter.emit('onRouteUpdate');
};
gatsby-ssr.js
: N/A
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Strange behavior of React hooks: delayed data update
The state update is asynchronous so if you are using Hooks you can use useEffect to be notified after an update. Here is...
Read more >Eight Time-Saving Gatsby Plugins - Better Programming
Just add the plugin to the plugins array in your gatsby-config.js ... Delays sending pageview hits on route update (in milliseconds)
Read more >Caching with service worker and Workbox | Node.js Developer
After successful installation, the updated service worker delays ... It requires the initialization of the DataSource configuration.
Read more >Fix delayed state update in React. Receiving Previous value ...
useState() Hook in class and function components, respectively. ... but React may delay the changes, updating several components in a single ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Suggest reopening this as I’ve also come across this problem - I want to be able to adjust this delay, and the suggestion of using
onPreRouteUpdate
is incorrect, as this hook gets called too late (after the new page is loaded, but before it’s rendered)@jzabala I don’t think
onPreRouteUpdate
is the correct API. I’ve done some testing on https://xzvto-8000.sse.codesandbox.io/page-2/ (source) and on a simulated slow network, theonRouteUpdateDelayed
event is fired beforeonPreRouteUpdate
(make sure you click a link before it’s prefetched)