-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v2] [cache-dir] Fix navigation after reload #7812
Conversation
Some context on commented out |
With @pieh's PR improving our Cypress setup landing, it'd be nice for this PR to write a test for the reload and back button behavior which fails without the changes made here but then which the changes here do fix . |
@KyleAMathews I've just added the new test - |
@davidbailey00 |
@pieh With the Travis tests, currently we're not using |
It will wait ~4s, which sometimes proved to be not enough on Travis - when you test this locally with |
@pieh In that case perhaps we can override Cypress's default timeout with something like 10 seconds - but I think it's unlikely Travis will be that slow in most cases, given that only two of the tests took longer than 1 second: |
The plan is to build code & run gatsby-dev for tests but yeah, that makes it more difficult now. @davidbailey00 could you add tests to here as well? https://github.com/gatsbyjs/gatsby/tree/master/integration-tests/production-runtime Gatsbygram is running the develop server. |
Hey, when I was diving deep into
then :
-loader.getResourcesForPathnameSync(pathName, pageResources => {
+loader.getResourcesForPathname(pathName).then(pageResources => { I think changing this and reverting your changes from |
@pieh Nice find, I'll try changing this later tomorrow (just sorting out college stuff now). |
Change I commented above fixed this for production, but development has a little different setup and we are getting stuck in |
@pieh Sounds good, thanks for making the changes! I've got my initial college homework out the way now so I'll try adding the tests requested by Kyle later on. |
this is mostly covered by navigation code, but in case of using history.back / forward functions, browser will change URL immediately and it's not handled by navigation code then.
Just thinking. We should publish our Cypress plugin to npm as people will want to use it when testing their gatsby sites as well. Plus it could lead to more useful Cypress plugins being added. |
…at for publicly exported PageRenderer
I agree, I just didn't want to focus on finding proper way of packaging cypress extension + that API is very fresh and I'm not sure if it will stick and if we won't have to change it - I guess it would work if we release it as |
Feeling pretty good about. Here is some manual testing I did to ensure
Production:Console output: textNavigated to http://localhost:9000/
VM284 app-e36d6dfe3bf7e083bcc8.js:1 [wait-for-route-change] resetRouteChangePromise
VM284 app-e36d6dfe3bf7e083bcc8.js:6 [gatsby-browser] onPreRouteUpdate {titleElementInDOM: "IndexPage", pathname: "/"}
VM284 app-e36d6dfe3bf7e083bcc8.js:6 [gatsby-browser] onRouteUpdate {titleElementInDOM: "IndexPage", pathname: "/"}
VM284 app-e36d6dfe3bf7e083bcc8.js:1 [wait-for-route-change] resolveRouteChangePromise
window.___navigate('/hi-folks/')
VM284 app-e36d6dfe3bf7e083bcc8.js:1 [wait-for-route-change] resetRouteChangePromise
undefined
VM284 app-e36d6dfe3bf7e083bcc8.js:6 [gatsby-browser] onPreRouteUpdate {titleElementInDOM: "IndexPage", pathname: "/hi-folks/"}
VM284 app-e36d6dfe3bf7e083bcc8.js:6 [gatsby-browser] onRouteUpdate {titleElementInDOM: "Post: New Beginnings", pathname: "/hi-folks/"}
VM284 app-e36d6dfe3bf7e083bcc8.js:1 [wait-for-route-change] resolveRouteChangePromise
window.___navigate('/this-will-be-404')
VM284 app-e36d6dfe3bf7e083bcc8.js:1 [wait-for-route-change] resetRouteChangePromise
VM284 app-e36d6dfe3bf7e083bcc8.js:1 A page wasn't found for "/this-will-be-404"
undefined
VM284 app-e36d6dfe3bf7e083bcc8.js:6 [gatsby-browser] onPreRouteUpdate {titleElementInDOM: "Post: New Beginnings", pathname: "/404.html"}
VM284 app-e36d6dfe3bf7e083bcc8.js:6 [gatsby-browser] onRouteUpdate {titleElementInDOM: "NOT FOUND", pathname: "/404.html"}
VM284 app-e36d6dfe3bf7e083bcc8.js:1 [wait-for-route-change] resolveRouteChangePromise
window.location.reload()
undefined
Navigated to http://localhost:9000/this-will-be-404
VM393 app-e36d6dfe3bf7e083bcc8.js:1 [wait-for-route-change] resetRouteChangePromise
VM393 app-e36d6dfe3bf7e083bcc8.js:6 [gatsby-browser] onPreRouteUpdate {titleElementInDOM: "NOT FOUND", pathname: "/404.html"}
VM393 app-e36d6dfe3bf7e083bcc8.js:6 [gatsby-browser] onRouteUpdate {titleElementInDOM: "NOT FOUND", pathname: "/404.html"}
VM393 app-e36d6dfe3bf7e083bcc8.js:1 [wait-for-route-change] resolveRouteChangePromise
window.history.back()
undefined
VM393 app-e36d6dfe3bf7e083bcc8.js:1 [wait-for-route-change] resetRouteChangePromise
VM393 app-e36d6dfe3bf7e083bcc8.js:6 [gatsby-browser] onPreRouteUpdate {titleElementInDOM: "NOT FOUND", pathname: "/hi-folks/"}
VM393 app-e36d6dfe3bf7e083bcc8.js:6 [gatsby-browser] onRouteUpdate {titleElementInDOM: "Post: New Beginnings", pathname: "/hi-folks/"}
VM393 app-e36d6dfe3bf7e083bcc8.js:1 [wait-for-route-change] resolveRouteChangePromise
window.location.reload()
undefined
Navigated to http://localhost:9000/hi-folks/
wait-for-route-change.js:3 [wait-for-route-change] resetRouteChangePromise
gatsby-browser.js:11 [gatsby-browser] onPreRouteUpdate {titleElementInDOM: "Post: New Beginnings", pathname: "/hi-folks/"}
gatsby-browser.js:3 [gatsby-browser] onRouteUpdate {titleElementInDOM: "Post: New Beginnings", pathname: "/hi-folks/"}
wait-for-route-change.js:12 [wait-for-route-change] resolveRouteChangePromise
window.history.forward()
undefined
wait-for-route-change.js:3 [wait-for-route-change] resetRouteChangePromise
gatsby-browser.js:11 [gatsby-browser] onPreRouteUpdate {titleElementInDOM: "Post: New Beginnings", pathname: "/404.html"}
gatsby-browser.js:3 [gatsby-browser] onRouteUpdate {titleElementInDOM: "NOT FOUND", pathname: "/404.html"}
wait-for-route-change.js:12 [wait-for-route-change] resolveRouteChangePromise Development:Console output: textNavigated to http://localhost:8000/
VM2352 wait-for-route-change.js:18 [wait-for-route-change] resetRouteChangePromise
VM2193 __webpack_hmr&reload=true&overlay=false:92 [HMR] connected
VM2308 gatsby-browser.js:13 [gatsby-browser] onPreRouteUpdate {titleElementInDOM: null, pathname: "/"}
VM2308 gatsby-browser.js:4 [gatsby-browser] onRouteUpdate {titleElementInDOM: "IndexPage", pathname: "/"}
VM2352 wait-for-route-change.js:31 [wait-for-route-change] resolveRouteChangePromise
window.___navigate('/hi-folks/')
VM2352 wait-for-route-change.js:18 [wait-for-route-change] resetRouteChangePromise
undefined
VM2308 gatsby-browser.js:13 [gatsby-browser] onPreRouteUpdate {titleElementInDOM: "IndexPage", pathname: "/hi-folks/"}
VM2308 gatsby-browser.js:4 [gatsby-browser] onRouteUpdate {titleElementInDOM: "Post: New Beginnings", pathname: "/hi-folks/"}
VM2352 wait-for-route-change.js:31 [wait-for-route-change] resolveRouteChangePromise
window.___navigate('/this-will-be-404')
VM2352 wait-for-route-change.js:18 [wait-for-route-change] resetRouteChangePromise
VM2309 loader.js:340 A page wasn't found for "/this-will-be-404"
undefined
VM2308 gatsby-browser.js:13 [gatsby-browser] onPreRouteUpdate {titleElementInDOM: "Post: New Beginnings", pathname: "/404.html"}
VM2308 gatsby-browser.js:4 [gatsby-browser] onRouteUpdate {titleElementInDOM: "NOT FOUND", pathname: "/404.html"}
VM2352 wait-for-route-change.js:31 [wait-for-route-change] resolveRouteChangePromise
window.location.reload()
undefined
Navigated to http://localhost:8000/this-will-be-404
VM2787 wait-for-route-change.js:18 [wait-for-route-change] resetRouteChangePromise
VM2744 loader.js:340 A page wasn't found for "/this-will-be-404"
VM2628 __webpack_hmr&reload=true&overlay=false:92 [HMR] connected
VM2743 gatsby-browser.js:13 [gatsby-browser] onPreRouteUpdate {titleElementInDOM: null, pathname: "/404.html"}
VM2743 gatsby-browser.js:4 [gatsby-browser] onRouteUpdate {titleElementInDOM: "NOT FOUND", pathname: "/404.html"}
VM2787 wait-for-route-change.js:31 [wait-for-route-change] resolveRouteChangePromise
window.history.back()
undefined
VM2787 wait-for-route-change.js:18 [wait-for-route-change] resetRouteChangePromise
VM2743 gatsby-browser.js:13 [gatsby-browser] onPreRouteUpdate {titleElementInDOM: "NOT FOUND", pathname: "/hi-folks/"}
VM2743 gatsby-browser.js:4 [gatsby-browser] onRouteUpdate {titleElementInDOM: "Post: New Beginnings", pathname: "/hi-folks/"}
VM2787 wait-for-route-change.js:31 [wait-for-route-change] resolveRouteChangePromise
window.location.reload()
undefined
Navigated to http://localhost:8000/hi-folks/
Users/misiek/dev/my-blog/.cache/wait-for-route-change.js:18 [wait-for-route-change] resetRouteChangePromise
Users/misiek/dev/my-blog/node_modules/webpack-hot-middleware/client.js?path=http:/localhost:8000/__webpack_hmr&reload=true&overlay=false:92 [HMR] connected
Users/misiek/dev/my-blog/gatsby-browser.js:13 [gatsby-browser] onPreRouteUpdate {titleElementInDOM: null, pathname: "/hi-folks/"}
Users/misiek/dev/my-blog/gatsby-browser.js:4 [gatsby-browser] onRouteUpdate {titleElementInDOM: "Post: New Beginnings", pathname: "/hi-folks/"}
Users/misiek/dev/my-blog/.cache/wait-for-route-change.js:31 [wait-for-route-change] resolveRouteChangePromise
window.history.forward()
undefined
Users/misiek/dev/my-blog/.cache/wait-for-route-change.js:18 [wait-for-route-change] resetRouteChangePromise
Users/misiek/dev/my-blog/gatsby-browser.js:13 [gatsby-browser] onPreRouteUpdate {titleElementInDOM: "Post: New Beginnings", pathname: "/404.html"}
Users/misiek/dev/my-blog/gatsby-browser.js:4 [gatsby-browser] onRouteUpdate {titleElementInDOM: "NOT FOUND", pathname: "/404.html"}
Users/misiek/dev/my-blog/.cache/wait-for-route-change.js:31 [wait-for-route-change] resolveRouteChangePromise Difference between dev and prod is that DOM element exists in production for |
note to self: consider moving |
} | ||
|
||
static getDerivedStateFromProps({ pageResources, location }, prevState) { | ||
if (prevState.location.pathname !== location.pathname) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to make shallow compare - location changes doesnt mean pathname changes
// Check if location has changed on a page using internal routing | ||
// via matchPath configuration. | ||
if ( | ||
this.props.location.key !== nextProps.location.key && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verify key
is there in @reach/router
|
||
return null | ||
} else if ( | ||
process.env.NODE_ENV !== `production` && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verify if this ever happen
…back-after-reload
The Cypress production test I added is failing 80% of the time with Electron 59, but working perfectly every time on the latest Chrome (which we can't use with CI). I spent a while this morning trying to figure out the problem but couldn't find it, and then had to do some other things - I'll have another look now. |
Great work @davidbailey00! Totally fine merging this w/ manual local testing until #7936 is working. I assume @pieh will get this in before I'm awake in the morning but if not, I'll test and merge. |
We had conversation with @davidbailey00 and there is one more issue that need fixing here - in production sync |
still TO-DO - move scroll context component to PageRenderer |
We added
popstate
listeners toapp.js
andproduction-app.js
which load the resources / render the page when back/forward is pressed.onPreRouteUpdate
andonRouteUpdate
aren't currently being called when navigating with back/forward so this will need to be fixed later in order for plugins to work properly.Note: wait until #7936 is merged to master before merging this PR, so we can properly test CI beforehand.
Just merged masteroops I got mixed up with a different one of DSchau's PRs which was mergedFixes #7261