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

Multi-instance docs with baseUrl doesn't work #5799

Closed
5 tasks done
semoal opened this issue Oct 27, 2021 · 4 comments · Fixed by #5824
Closed
5 tasks done

Multi-instance docs with baseUrl doesn't work #5799

semoal opened this issue Oct 27, 2021 · 4 comments · Fixed by #5824
Labels
bug An error in the Docusaurus core causing instability or issues with its execution

Comments

@semoal
Copy link
Contributor

semoal commented Oct 27, 2021

🐛 Bug Report

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io
  • I have read the console error message carefully (if applicable)

Description

Basically adding a baseUrl to our config, and two docs one pointing to "/" and other to "/example", "/example" won't work.

Have you read the Contributing Guidelines on issues?

Yes

Steps to reproduce

https://stackblitz.com/edit/github-fjbw7h?file=docusaurus.config.js

Here it is a reproducible repo, you can check that chaning baseUrl to "/" will make it work, or keeping the "/latest/" but adding a baseUrl to "/" docs path.

Expected behavior

(Write what you thought would happen.)

  • It should accept a baseUrl like: /latest/
  • One doc, should be able to navigate to root: /latest/{docURL} (without /docs/ prefix)
  • Other doc, should be able to navigate to basePath passed: latest/{routeBasePath}/{docUrl}

I entered on debug mode and I think the problem is that the router since it is not exact, it tries to navigate to the first group to routes, but on there isn't the /latest/forms/.

Not sure how we can fix this ^^

Screenshot 2021-10-27 at 19 00 01

Actual behavior

It should navigate correctly.

Reproducible demo

https://stackblitz.com/edit/github-fjbw7h?file=docusaurus.config.js

@semoal semoal added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Oct 27, 2021
@slorber
Copy link
Collaborator

slorber commented Oct 27, 2021

Agree, it seems our route ordering logic does not handle baseUrl and /baseUrl/ could end-up being before /baseUrl/someDocPluginInstance.

Related to #5645

@lex111 do you want to fix it?

Note I found some interesting route ranking algo in ReachUI recently: https://reach.tech/router/ranking
https://github.com/zoontek/react-chicane/blob/main/src/matcher.ts#L7

@slorber slorber removed the status: needs triage This issue has not been triaged by maintainers label Oct 27, 2021
@lex111
Copy link
Contributor

lex111 commented Oct 27, 2021

Do you mean just add support for baseUrl or implement route ranking algo? Apparently as a quick fix, it would be better to add baseUrl instead simply slash as now?

@semoal
Copy link
Contributor Author

semoal commented Oct 27, 2021

An easy and fast fix (if introducing router ranking it's complex) could be:

server.ts file on @docusaurus/core

-    sortConfig(pluginsRouteConfigs)
+    sortConfig(pluginsRouteConfigs, context.siteConfig.baseUrl);

SortConfig url checking with baseUrl:

- if (a.path === "/" && b.path !== "/") {
-   return 1;
- }
- if (a.path !== "/" && b.path === "/") {
-   return -1;
- }
+ if (a.path === baseUrl && b.path !== baseUrl) {
+   return 1;
+ }
+ if (a.path !== baseUrl && b.path === baseUrl) {
+   return +1;
+ }

@lex111
Copy link
Contributor

lex111 commented Oct 27, 2021

Yes, that's what I meant, it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution
Projects
None yet
3 participants