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

Locale switcher has confusing behavior in dev #8652

Open
6 of 7 tasks
start940315 opened this issue Feb 10, 2023 · 8 comments
Open
6 of 7 tasks

Locale switcher has confusing behavior in dev #8652

start940315 opened this issue Feb 10, 2023 · 8 comments
Labels
bug An error in the Docusaurus core causing instability or issues with its execution

Comments

@start940315
Copy link

Have you read the Contributing Guidelines on issues?

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

After I chose a language, the locale added to the url one by one. I assumed it to be replaced. For example, my locales is ['en', 'zh-Hant', 'zh-Hans'], the initial url is http://localhost:3000/docu/docs/intro, after I chose zh-Hant then chose zh-Hans, the url became http://localhost:3000/zh-Hans/zh-Hant/docu/docs/intro. And I found currentLocale is not updated.

Reproducible demo

No response

Steps to reproduce

  1. start a new repo
  2. npm install
  3. npm run start
  4. change language
  5. the lang added one by one, making the url longer and longer

Expected behavior

language url be replaced

Actual behavior

language url added one by one

Your environment

  • Public source code:
  • Public site URL:
  • Docusaurus version used:2.3.1
  • Environment name and version (e.g. Chrome 89, Node.js 16.4):node 16
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS):macos newest

Self-service

  • I'd be willing to fix this bug myself.
@start940315 start940315 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 Feb 10, 2023
@slorber
Copy link
Collaborator

slorber commented Feb 15, 2023

Please provide a repro using Docusaurus.new so I can easily inspect your setup.

It's hard to figure out with text only and it's not very clear to me what this bug is, so any screenshot is also welcome. I don't know what you mean by "language URL added one by one" for example. Please use real examples using real URLs for expected/actual results.

We'll re-open #8651 if the bug report is valid and if the code seems to fix it, and if possible add tests.

@slorber slorber removed the status: needs triage This issue has not been triaged by maintainers label Feb 15, 2023
@Josh-Cena Josh-Cena added the status: needs more information There is not enough information to take action on the issue. label Feb 19, 2023
@Josh-Cena
Copy link
Collaborator

Josh-Cena commented Feb 19, 2023

I can reproduce this in dev but not in prod. This is because in dev there's only one locale anyway, so useAlternatePageUtils naïvely believes that we are still in the default locale and tries to prepend the base URL instead of replacing it. I think it's better if we can simply disable the locale switcher in dev. @slorber WDYT? If you are still unsure what the bug is, it's when you are on localhost:3000 with locale en, and you use the locale dropdown to go to zh-Hans, you end up on localhost:3000/zh-Hans, which is non-existent, but the layout still exists, and it still says you are on en, so you use the locale dropdown to go to zh-Hant, and it prepends that to your URL so the URL becomes localhost:3000/zh-Hant/zh-Hans/.

@Josh-Cena Josh-Cena changed the title I18n not working Locale switcher has confusing behavior in dev Feb 19, 2023
@slorber
Copy link
Collaborator

slorber commented Feb 23, 2023

I see thanks, saw that before

Maybe we could add an alert("this does not work in dev") on locale click and prevent the navigation?

That looks better than simply removing the locale dropdown in dev, which might confuse users?

@Josh-Cena
Copy link
Collaborator

When I say "disable" I mean have it show the "forbidden" icon when hovered. (We may still show the dropdown content for the purpose of preview).

@slorber
Copy link
Collaborator

slorber commented Feb 24, 2023

Yes using forbidden + prevent selection looks like a nice idea

@Code-Milker
Copy link

@slorber just to clarify, we should not expect locale switching to work correctly in local environments right? When I attempt to do it locally my docs get a 404, however when I build and serve everything works as expected.

@Josh-Cena
Copy link
Collaborator

That's right; in dev we can only start the site in one locale.

@Code-Milker
Copy link

ah good to know, spent a couple hours troubleshooting this

@slorber slorber removed the status: needs more information There is not enough information to take action on the issue. label Sep 3, 2024
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
Development

No branches or pull requests

4 participants