Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign uponPreRouteUpdate is not called in correct order rerender and onRouteUpdate #26608
Comments
|
This makes sense to me. I'll discuss internally to see if there is a reason we cant make this change. Would you be interested in submitting a PR to fix this? |
|
Nope, just wanted to let you know |
|
Hiya! This issue has gone quiet. Spooky quiet. We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! |
|
Keep open, seems problematic. |
|
We won't be able to prioritize this change but we're happy to get a pull request for it. Make sure to add tests to test this behavior in one of our e2e tests. gatsby/packages/gatsby/cache-dir/navigation.js Lines 200 to 233 in 55052ef This is a nice graph on why this bug exists: diff --git a/packages/gatsby/cache-dir/navigation.js b/packages/gatsby/cache-dir/navigation.js
index d870bfec6..b50d88d91 100644
--- a/packages/gatsby/cache-dir/navigation.js
+++ b/packages/gatsby/cache-dir/navigation.js
@@ -207,6 +207,14 @@ class RouteUpdates extends React.Component {
onRouteUpdate(this.props.location, null)
}
+ shouldComponentUpdate(nextProps) {
+ if (this.props.location.pathname !== nextProps.location.pathname) {
+ onPreRouteUpdate(nextProps.location, this.props.location)
+ }
+
+ return true
+ }
+
componentDidUpdate(prevProps, prevState, shouldFireRouteUpdate) {
if (shouldFireRouteUpdate) {
onRouteUpdate(this.props.location, prevProps.location)
@@ -215,7 +223,6 @@ class RouteUpdates extends React.Component {
getSnapshotBeforeUpdate(prevProps) {
if (this.props.location.pathname !== prevProps.location.pathname) {
- onPreRouteUpdate(this.props.location, prevProps.location)
return true
} |
If you consider this a bug, i would expect you to fix it. Your intention is not clear. What does "won't be able to prioritize" mean for you in this context? |
|
I'm sorry I feel like I gave enough information for community members to pick it up. We have many things in flight and we have to juggle where we put most of our effort in. I hope you understand and feel free to create a PR! |


Description
I have a
onPreRouteUpdateand aonRouteUpdatein gatsby-browser, both log to the console. I also have a layout component that logs on render and wrapped via gatsby-browserswrapPageElement.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
onPreRouteUpdateis 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(R) Core(TM) 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