-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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
fix(core): prevent 404 when accessing /page.html #7184
Conversation
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-7184--docusaurus-2.netlify.app/ |
Size Change: +356 B (0%) Total Size: 802 kB
ℹ️ View Unchanged
|
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.
2 important things to consider:
-
Many legacy doc sites moving to Docusaurus want to preserve older canonical urls for SEO. We have users that explicitly want to use
.html
in router paths (I even recommended some users to useslug: /xyz.html
for site migration purposes) => we should dogfood this and ensure it keeps working, not stripping the extension if the route actually exists. -
This page renders better than before but produces FOUC after hydration: https://deploy-preview-7184--docusaurus-2.netlify.app/docs/installation.html , unlike https://deploy-preview-7184--docusaurus-2.netlify.app/docs/installation => that seems unexpected to me, but we'd rather fix it
That's the entire purpose of this PR. Before, the
Do you have a repro? It looks the same to me even under throttling. |
TBF, that looks like a horrible pattern. You shouldn't encode the extension in the location. We should have made this fix long ago, then, if people have to commit to such horrible solutions. |
There is no strict rule here. Some users really want the links to contain the extension, and the canonical URL to contain it too, for SEO and migration reasons. If you have an existing doc site and all the links contain the extension, and all the canonical URLs known by google contain the extension, then when upgrading you want to minimize the SEO impact and migrate to Docusaurus while keeping this extension in site links and canonical URLs. Allowing That's why I'd like this PR to contain a dogfood doc with |
Okay, I see |
This link is good enough to reproduce: https://deploy-preview-7184--docusaurus-2.netlify.app/docs/installation.html Just hit refresh, eventually throttle your CPU video: https://cln.sh/RNi85L This doesn't happen on https://deploy-preview-7184--docusaurus-2.netlify.app/docs/installation |
Okay, I see what you mean. |
@slorber I've tested. Using Do you think I need to fix the flash of loading screen in this PR, or should we figure that out later, considering it's much more minor compared to the 404 page before? |
If it's easy to fix in this PR let's do this now, otherwise we can merge Similarly, does it make sense to also ensure this URL works? https://deploy-preview-7184--docusaurus-2.netlify.app/tests/docs/dummy => should be quite easy and similar to current code? Does all this work with trailing slash: true? |
@@ -18,8 +20,16 @@ export default function normalizeLocation<T extends Location>(location: T): T { | |||
}; | |||
} | |||
|
|||
// If the location was registered with an `.html` extension, we don't strip it | |||
// away, or it will render to a 404 page. | |||
const matchedRoutes = matchRoutes(routes, 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.
also handle matchRoutes(routes, location.pathname + ".html");
?
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.
I wouldn't do that for now, because it makes less sense.
/docs/installation.html
is a physical file that exists and can be served, so using this as a location makes sense. If the route is /docs/installation
, we should try to normalize /docs/installation.html
to that.
However, if both the route and the physical file is /docs/installation.html
, then /docs/installation
doesn't really make sense—it's nowhere to be found. Moreover, I'm worried that this would lead to more edge cases, especially around trailing slash and index.html
.
We can test this before merging, when I revert the |
Everything works as expected @slorber The |
Motivation
Because we use
trailingSlash: false
in production, https://docusaurus.io/docs/installation.html will send the correct HTML file, but the router doesn't understand it because it only normalizes paths with/index.html
suffix. I think we can extend this to.html
extensions in general.Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Interestingly
yarn serve
seems to be happy with/docs/installation.html
. I don't know if it has anything to do with thecleanUrls
or related settings. Anyways, I simply forcedtrailingSlash: false
in the preview. https://deploy-preview-7184--docusaurus-2.netlify.app/docs/installation.html is now accessible.