-
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
[gatsby] WIP Fix 404 page rendered with missing props and without correct location.pathname #5583
[gatsby] WIP Fix 404 page rendered with missing props and without correct location.pathname #5583
Conversation
Deploy preview for gatsbygram ready! Built with commit ce1de9b |
Deploy preview for using-drupal ready! Built with commit ce1de9b |
FWIW I posted about this on the Gatsby Spectrum when I was trying to track down the problem and it seems a number of other people are dealing with the same issue. |
This is not ready to merge. |
Hey @Undistraction, let us know if You are still insterested in working on this? Code that You change in this PR will most likely be changed by this #6918 |
@pieh I've been meaning to take another look at this, but just starting a new Job so short on time. Do you know if this is still an issue in v2? I'll try and take a look again soon. |
fc4ca3e
to
2116fff
Compare
404 page should have uniform handling with other pages now. There seems to be issue now when visiting non existing page directly (not by I'll close this PR as code base evolved since this was opened. |
@pieh Sure. Thanks. |
Currently no props (other than
location.pathname
are passed in to a custom 404 page, causing lots of potential errors when components used in the layout or in the page itself rely on props. This came to light in #5498 which highlighted the problem, but has lots of potential to effect projects that don't use styled components as well. The current implementation also overwritesprops.location.pathname
, meaning the path of the page that triggered the 404 is obliterated and is not available to the 404 page, so a message like 'There was no page found at /nopeis not possible because no matter what path triggered the 404,
location.pathnameis incorrectly forced to
/404`. This is doubly wrong because the url will still reflect the bad path.It seems that there is duplicate handling of 404 pages both in
gatsby/cache-dir/production-app
and ingatsby/cahce-dir/component-renderer
. Both check to see if the page is available, however the check that happens inproduction-app
results in hardcoding of the404.html
path, whereas the check that happens incomponent-renderer
only results in the rendering of the 404 page, leavingprops.location.pathname
intact. In short, the check performed incomponent-renderer
is enough on its own, so the extra check (which also has the negative side-effects of 1. obliterating the missing page path and 2. obliterating all props that the layout or other page components might be relying on) is unnecessary.This PR removes that check. I have verified that this fixes #5498 and also resolves #5544 because the path is now available at
props.location.pathname
.closes #5498
closes #5544