question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onPreRouteUpdate is not called in correct order rerender and onRouteUpdate

See original GitHub issue

Description

I have a onPreRouteUpdate and a onRouteUpdate in gatsby-browser, both log to the console. I also have a layout component that logs on render and wrapped via gatsby-browsers wrapPageElement.

On initial render, the logging order is: onPreRouteUpdate > layout > onRouteUpdate On subsequent navigations, the logging order is: layout > onPreRouteUpdate > onRouteUpdate

This seems confusing and wrong. If onPreRouteUpdate is supposed to be triggered before a route update, layout cannot possibly be rerendered before that. Ordering seems wrong here.

Steps to reproduce

https://codesandbox.io/s/morning-silence-19rkd?file=/gatsby-browser.js https://19rkd-8000.sse.codesandbox.io/

Expected result

Logging order should always be: onPreRouteUpdate > layout > onRouteUpdate This should be the order for both initial render and subsequent navigations.

Actual result

On initial render, the logging order is: onPreRouteUpdate > layout > onRouteUpdate On subsequent navigations, the logging order is: layout > onPreRouteUpdate > onRouteUpdate

Environment

System: OS: Linux 4.19 Ubuntu 20.04.1 LTS (Focal Fossa) CPU: (8) x64 Intel® Core™ i7-7700K CPU @ 4.20GHz Shell: 5.8 - /usr/bin/zsh Binaries: Node: 12.18.3 - /tmp/yarn–1598220669129-0.9999174876381276/node Yarn: 1.22.4 - /tmp/yarn–1598220669129-0.9999174876381276/yarn npm: 6.14.6 - ~/.nvm/versions/node/v12.18.3/bin/npm Browsers: Chrome: 84.0.4147.125 npmPackages: gatsby: ^2.24.48-incbuild-collections.5 => 2.24.48-incbuild-collections.5+598335ebeb gatsby-image: ^2.4.5 => 2.4.5 gatsby-plugin-linaria: ^2.0.0 => 2.0.0 gatsby-plugin-manifest: ^2.4.9 => 2.4.9 gatsby-plugin-mdx: ^1.2.15 => 1.2.15 gatsby-plugin-offline: ^3.2.7 => 3.2.7 gatsby-plugin-react-helmet: ^3.3.2 => 3.3.2 gatsby-plugin-remove-generator: ^1.0.5 => 1.0.5 gatsby-plugin-sharp: ^2.6.9 => 2.6.9 gatsby-remark-copy-linked-files: ^2.3.12 => 2.3.12 gatsby-remark-shiki-twoslash: ^0.6.1 => 0.6.1 gatsby-source-filesystem: ^2.3.8 => 2.3.8 gatsby-transformer-sharp: ^2.5.3 => 2.5.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
WillMaygercommented, Oct 3, 2020

@clovis1122 Ah I see! - thanks for letting me take a look 😄 & I have a PR ready for review at https://github.com/gatsbyjs/gatsby/pull/27261

1reaction
clovis1122commented, Oct 3, 2020

@WillMayger sure thing! I’m still exploring the repo. I don’t mind if your fix is merged instead of mine – will be mostly a learning experience for me, haha.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gatsby Browser APIs
Documentation about leveraging standard browser APIs within Gatsby.
Read more >
Re-render a component in gatsby - Stack Overflow
Gatsby is a React-based framework, it uses React under the hood so the component and state management is identical to Reacts.
Read more >
Understanding the lifecycle of Gatsby's time-based Browser APIs
So we can see here the order is onClientEntry then onInitialClientRender. ... This gets called right after onPreRouteUpdate (who would've guessed).
Read more >
gatsby @ 2.6.0 .. 2.6.3 - Package Diff
n // Whether or not you have warnings or errors, ... onPreRouteUpdate = true\n\n/**\n * Called when changing location is longer than 1 ......
Read more >
https://preview.lqd.ch/app-40335d38df0f84615d64.js.map
node_modules/core-js/internals/fix-regexp-well-known-symbol-logic.js" ... node_modules/core-js/internals/correct-is-regexp-logic.js","webpack:///.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found