Skip to content
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

Feedback on trailingSlash option + GH Pages #2

Closed
jsamr opened this issue Jun 26, 2021 · 4 comments
Closed

Feedback on trailingSlash option + GH Pages #2

jsamr opened this issue Jun 26, 2021 · 4 comments

Comments

@jsamr
Copy link

jsamr commented Jun 26, 2021

@slorber

Issue / Bug?

I've set "trailingSlash": false on my project following suggestions by the CLI. I have a non-empty base-url, and here is what happens when fetching https://meliorence.github.io/react-native-render-html:

> http -h https://meliorence.github.io/react-native-render-html
HTTP/1.1 301 Moved Permanently
Location: https://meliorence.github.io/react-native-render-html/
...

OK, so GH pages redirects the root (a file named react-native-render-html.html in the gh-pages branch) to the slash-forwards path. That's not great for SEO (unless the sitemap reflects that), but at least if it works... Let's fetch the redirected-url:

> http -h https://meliorence.github.io/react-native-render-html/
HTTP/1.1 200 OK

Good.... However, if you try that out in a browser, you'll see a "Not Found" flash. My understanding of what's happening:

  1. The browser loads the static HTML asset, build the DOM and paints.
  2. The DOM is hydrated.
  3. Docusaurus router (if there is such thing) finds that this route is a mismatch because of the trailingSlash option. It thus flashes a "Not Found" route after which it manages to find the actual route.
404.mp4

Workaround

After a docusaurus build, the gh-pages branch folder structure looks like this:

├── api
├── assets
├── blog
├── docs
├── favicons
├── img
├── video
├── 404.html
├── api.html
├── blog.html
├── opensearch.xml
├── react-native-render-html.html
├── search.html
└── sitemap.xml

By copying react-native-render-html.html into index.html and pushing, the "Not Found" flash bug disappears.

Additional information

@docusaurus/*@2.0.0-beta.4d93c894f

Remarks

Ideally, the sitemap generated for gh-pages would add a trailing slash to the root URL to avoid redirects, or there could be an option to deal with the root.

@slorber
Copy link
Owner

slorber commented Jun 26, 2021

Hi!

This project is not directly related to Docusaurus so can you re-open this issue on Docusaurus instead?

I'll look at this on Monday anyway
It makes me think about another issue opened recently (facebook/docusaurus#5055)

├── react-native-render-html.html

I don't understand, Docusaurus does not create an index.html file anymore in beta.2, while it did before?

Can you deploy your site with the bug somewhere (a fork?), so that I can see the live site + have the ability to inspect the gh-branch?

Ideally, the sitemap generated for gh-pages would add a trailing slash to the root URL to avoid redirects, or there could be an option to deal with the root.

I don't think, we don't want to hardcode special cases per host.

GH pages should be able to serve files without needing/redirecting a trailing slash, cf https://slorber.github.io/trailing-slash-guide/file

@jsamr
Copy link
Author

jsamr commented Jun 26, 2021

@slorber All right, I'll try to make a reproduction and file a report. I didn't report on Docusaurus because I wasn't sure it's really a bug...

I don't think, we don't want to hardcode special cases per host.

Sure hardcoding is bad, however there could be an actionable solution for all those who're using GH pages and don't want to suffer from degraded SEO. Perhaps trailingSlash: 'root' meaning, one trailing slash is expected for the top level route, no trailing slash for other routes. That would match per-repository GH Pages deployments.

@slorber
Copy link
Owner

slorber commented Jun 27, 2021 via email

@jsamr
Copy link
Author

jsamr commented Jun 28, 2021

Closing in favor of facebook/docusaurus#5077

@jsamr jsamr closed this as completed Jun 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants