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

fix(core): prevent useBaseUrl returning /base/base when on /base #6993

Merged
merged 1 commit into from
Mar 25, 2022

Conversation

Josh-Cena
Copy link
Collaborator

@Josh-Cena Josh-Cena commented Mar 25, 2022

Motivation

Fix #6315. It's a pretty trivial fix; not sure if a better solution exists. Since we have this duplicate base URL detection anyways, this fix only exists to make the behavior more consistent. Related to #6294

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Added two tests

@Josh-Cena Josh-Cena added the pr: bug fix This PR fixes a bug in a past release. label Mar 25, 2022
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Mar 25, 2022
@netlify
Copy link

netlify bot commented Mar 25, 2022

[V2]

Name Link
🔨 Latest commit 766ccc2
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/623d34baa340c600089c0d15
😎 Deploy Preview https://deploy-preview-6993--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 53
🟢 Accessibility 100
🟢 Best practices 92
🟢 SEO 100
🟢 PWA 90

Lighthouse ran on https://deploy-preview-6993--docusaurus-2.netlify.app/

@github-actions
Copy link

Size Change: +36 B (0%)

Total Size: 805 kB

Filename Size Change
website/build/assets/js/main.********.js 612 kB +36 B (0%)
ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 49.9 kB
website/build/assets/css/styles.********.css 105 kB
website/build/index.html 38.3 kB

compressed-size-action

@slorber
Copy link
Collaborator

slorber commented Mar 25, 2022

I'm not sure to understand how this fixes the other issue.

To me the problem is that if user use baseUrl: "/docusaurus/" and routeBasePath: "docusaurus", then we want:

expect(mockUseBaseUrl('/docusaurus')).toBe('/docusaurus/docusaurus');

(which we prevented on purpose as a workaround/security)

instead of

expect(mockUseBaseUrl('/docusaurus')).toBe('/docusaurus/');

Can we build our own site with baseUrl: "/docs" and the current fix? That's the relevant test here

@Josh-Cena
Copy link
Collaborator Author

No, this one fixes the other issue, which is exactly that the base URL is prepended twice, because we only check url.startsWidth(baseUrl), but in this case, we are on /base instead of /base/ because of trailingSlash: false

@slorber
Copy link
Collaborator

slorber commented Mar 25, 2022

@slorber
Copy link
Collaborator

slorber commented Mar 25, 2022

👍 that looks good yes

@slorber
Copy link
Collaborator

slorber commented Mar 25, 2022

But in practice does it really solve the problem?

Because afaik the problem is when accessing the site on /docusaurus instead of /docusaurus/, not clicking a link

Have you tested this with a host that serves Docusaurus with baseUrl: "/docusaurus/" under /docusaurus?

We may need a client-side redirect or something

@Josh-Cena
Copy link
Collaborator Author

This is only about the canonical and nothing else (not about content hoster serving the right file or redirecting). The problem is that if you are on /base, the SiteMetadata component would call useBaseUrl("/base") and thus add a canonical of "/base/base". This PR would correct that to adding a canonical of "/base/".

@slorber
Copy link
Collaborator

slorber commented Mar 25, 2022

👍 agree, this fixes the issue above

Although serving the site through /docusaurus instead of /docusaurus/ might still trigger other issues in the future (cf #6315 (comment)), at least it's a bit more resilient now for the reported case

@slorber slorber merged commit e8800b9 into main Mar 25, 2022
@slorber slorber deleted the jc/fix-baseUrl branch March 25, 2022 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Canonical tag contains duplicated base URL when trailingSlash is false
3 participants