-
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
a entry page with no trailing slash will break back button behaviour for that page #8357
Comments
@tony1377 Thanks for reporting this issue. We'll look into this. |
Hey folks, just wondered if anyone has had a chance to look into this issue? |
Also wondering ^ encountering same issue. I can provide our production site with the issue if helpful |
I can't reproduce this, e.g. with this repository: https://github.com/a-botermans/test-case-history-bug However the steps described in this repo are confirmed. But this line is important:
You don't mention that. And what you describe has no issue as far as I can tell. |
I believe the problem is caused by the following code (please take this with a grain of salt as I don't have much react experience) gatsby/packages/gatsby/cache-dir/production-app.js Lines 64 to 84 in bbeae87
this causes reach router to set but https://github.com/reach/router/blob/b60e6dd781d5d3a4bdaaf4de665649c0f6a7e78d/src/index.js#L86-L90 since |
@LekoArts here are the reproduction steps based on that repo: assuming base url is:
This is more noticeable when you have the site configured to have trailing slashes as the user will most likely not add the trailing slash for a well known route. In my case the route is https://smartcar.com/docs (which also exhibits the above behavior) |
Here's a kind of workaround anyone can use for now, place the following code in import {globalHistory} from '@reach/router';
export const onInitialClientRender = () => {
/**
* This is a workaround for a bug in Gatsby
*
* See https://github.com/gatsbyjs/gatsby/issues/8357 for more details
*/
globalHistory._onTransitionComplete();
} |
The above workaround by @gurpreetatwal worked for my own project. Does anyone know if the fix for this issue should be done in Gatsby or in Reach Router? |
Also commenting on here - seeing the same issue using Netlify & Gatsby. |
@gurpreetatwal 's solution did not work for my site - Has anyone found other solutions? |
I did suffer from a similar bug: when navigating around my app clicking links, all went well, but when pressing the back button or using window.location.back it was sending me to the root path (Not only skipping one history state as others have mentioned). |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! Thanks for being a part of the Gatsby community! 💪💜 |
@kakadiadarpan Are there any team members who'll have time to look into this? It looks like there may be some good hints at a proper solution based on what @gurpreetatwal posted above. |
I'm seeing the same issue, uncommenting these lines seems to have worked for now: gatsby/packages/gatsby/cache-dir/production-app.js Lines 80 to 83 in bbeae87
|
I have got some mileage out of @gurpreetatwal's workaround, but I'm not sure why. I had this problem with a site running on Netlify. Sometimes (and it's difficult to know exactly how to reliably reproduce) clicking a link wouldn't seem to increase the I also didn't seem to have an issue in Firefox... |
I don't think it's linked to Netlify because I can reproduce locally |
@jalada can reproduce in firefox, and also locally, when built.
|
Having the same issue. Only occurs with gatsby build (not develop) and locally as well as on Netlify. |
I had the same issue. Our app is deployed on Heroku. @gurpreetatwal's fixed worked, but only after this issue cost of days of pain. Hoping this gets resolved soon. |
We are having this issue regardless of host (it's reproduce-able with |
I don't currently have this issue with the latest version of Gatsby, maybe it's fixed? |
@t2ca I have updated my test repo : https://github.com/a-botermans/test-case-history-bug |
I have the same issue, back button doesn't work and typing manual pathname doesn't redirect to the page. @gurpreetatwal's solution didn't work for our app. |
This isn't an ideal fix, but this bug is apparently a known thing in Gatsby and the suggested solution [here](gatsbyjs/gatsby#8357 (comment)) has resolved #35. We considered fixing this in our Workers script but we generally want the Workers part of this to be as out of the box as possible, so we're resolving on the Gatsby side instead. Closes #35
This isn't an ideal fix, but this bug is apparently a known thing in Gatsby and the suggested solution [here](gatsbyjs/gatsby#8357 (comment)) has resolved #35. We considered fixing this in our Workers script but we generally want the Workers part of this to be as out of the box as possible, so we're resolving on the Gatsby side instead. Closes #35
I had the same problem in my project but not for every link. I tried to apply the solutions here mentioned but it had the drawback that when going back it reloaded everything. I continued researching and found something, crazy, but worked. Let me know if this worked for you. I am using a WordPress site as a source. I was doing:
It was fixed removing the las "/". Like this:
|
This is now fixed with the Gatsby v2.19.15 release! 🎉 @reach/router v1.3.1 has the corresponding fix. |
I confirm that it is fixed in the test case I created with latest Gatsby Release https://github.com/a-botermans/test-case-history-bug |
@bernharduw @a-botermans this means we can close this issue? |
For me yes :) |
We're marking this issue as answered and closing it for now but please feel free to reopen this and comment if you would like to continue this discussion. We hope we managed to help and thank you for using Gatsby! 💜 |
i can confirm the fix is working fine! |
Description
When a users first page on the site is a page which has been created with no trailing slash.
Then that page will be skipped if the user uses the back button on the next page they view
Steps to reproduce
in the examples/no-trailing-slashes gatsby folder
Expected result
You should be on http://localhost:9000/a
Actual result
If you opened the entry page in a new tab then you'll probably see whatever is the default starting page for a new browser tab
Environment
System:
OS: Linux 4.15 Ubuntu 18.04.1 LTS (Bionic Beaver)
CPU: x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Shell: 4.4.19 - /bin/bash
Binaries:
Node: 8.10.0 - /usr/bin/node
Yarn: 1.9.4 - /usr/bin/yarn
npm: 3.5.2 - /usr/bin/npm
Browsers:
Chrome: 69.0.3497.81
Firefox: 62.0
npmPackages:
gatsby: ^2.0.0 => 2.0.4
gatsby-plugin-google-analytics: ^2.0.5 => 2.0.6
gatsby-plugin-offline: ^2.0.5 => 2.0.5
npmGlobalPackages:
gatsby-cli: 1.1.58
The text was updated successfully, but these errors were encountered: