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

Astro v3: dev server returns 404 for other locales when using [dynamic].astro paths #19

Open
gustawdaniel opened this issue Aug 26, 2023 · 8 comments

Comments

@gustawdaniel
Copy link

gustawdaniel commented Aug 26, 2023

Problem:

I using this package with astro:content, but can't achieve stable behaviour of my blog when I working on routing to content.

I assumed convention when the first component of the path is language if it is a language different than English.

Example for static pages:

/ - main page in English
/pl - main page in Polish

Example for blog posts

/post/hello-world - blog post in English
/pl/post/widaj-swiecie - blog post in Polish

I have no problem with static pages, like index or about but for content I see that some posts work or do not work depending on the page on which I have opened the browser during the npm run dev command.

Test

I have closed the browser. I starting my blog.

npm run dev 

I see http://localhost:3000/ in English, http://localhost:3000/pl in Polish, and http://localhost:3000/es in Spanish as I expected.
My blog post http://localhost:3000/post/hi is displayed correctly.

but when I enter http://localhost:3000/pl/post/witaj-swiecie I see 404.
To see its content I have to use http://localhost:3000/post/witaj-swiecie but then I lose info about the language in the URL and the language of the rest layout is wrongly recognized.

But it is only half of the problem...

Now I typing http://localhost:3000/pl/post/witaj-swiecie in the browser address again to see 404.

I turned down the server in the Linux console.

Then typed

npm run dev 

again and saw my Polish blog post on http://localhost:3000/pl/post/witaj-swiecie

But... it is not a solution because of when I entered now

http://localhost:3000/pl or http://localhost:3000/ I see it works because these are static pages, but when I want to check an English blog post and type

http://localhost:3000/post/hi

I see now 404, to see this post I can't see it even typing

http://localhost:3000/en/post/hi

because I am instantly redirected to http://localhost:3000/post/hi

In the console, I can see warnings

09:11:13 [getStaticPaths] A `getStaticPaths()` route pattern was matched, but no matching static path was found for the requested path `/post/hi`.

Possible dynamic routes being matched: src/pages/post/[...slug].astro.
09:11:13 [serve]    404      

I created the branch astro-i18n-aut in my blog so you can reproduce it.

https://github.com/gustawdaniel/gustawdaniel/tree/astro-i18n-aut

Update 1

I found an example #8 and it works great. I investigating where I made bug.

Update 2

I downloaded your example from mentioned issue and it was working perfectly until I typed

npm update

Then I seed error

[config] Astro found issue(s) with your configuration:
  ! experimental  Invalid experimental key: `redirects`. 
Make sure the spelling is correct, and that your Astro version supports this experiment.
See https://docs.astro.build/en/reference/configuration-reference/#experimental-flags for more information..

and when I removed

  experimental: {
    redirects: true,
  },

I was able to reproduce the same error using your code astro-i18n-blog

Update 3

To simplify reproduction I used your example and created 2 branches:

First - your original code with blog, when we do not see this error (it works but has outdated packages)

https://github.com/gustawdaniel/gustawdaniel/tree/astro-i18n-blog-no-update

Second - with a bug that is possible to reproduce after the npm update

https://github.com/gustawdaniel/gustawdaniel/tree/astro-i18n-blog-npm-update

There is open PR with changes in package-lock.json that was reason of problem.

https://github.com/gustawdaniel/gustawdaniel/pull/7/files


Potentially connected issues:

withastro/astro#8226
withastro/astro#8236
withastro/astro#7808

@jlarmstrongiv
Copy link
Owner

jlarmstrongiv commented Aug 26, 2023

You are right!

One change that is needed is updating the imports in the astro.config.mjs file:

import { i18n, defaultLocaleSitemapFilter } from "astro-i18n-aut/integration";

However, from what I’ve tested, I believe the injectRoutes() behavior has changed and broken astro-i18n-aut in the dev environment. The build and preview still work as expected.

@jlarmstrongiv
Copy link
Owner

Follow withastro/astro#8241 for updates

@jlarmstrongiv jlarmstrongiv changed the title Content and slug behaviour dependent from currently opened page when npm run dev starts (astro:content) Astro V3: Content and slug behaviour dependent from currently opened page when npm run dev starts (astro:content) Sep 2, 2023
@jlarmstrongiv jlarmstrongiv changed the title Astro V3: Content and slug behaviour dependent from currently opened page when npm run dev starts (astro:content) Astro v3: Content and slug behaviour dependent from currently opened page when npm run dev starts (astro:content) Sep 2, 2023
@jlarmstrongiv jlarmstrongiv changed the title Astro v3: Content and slug behaviour dependent from currently opened page when npm run dev starts (astro:content) Astro v3: dev server returns 404 when using [dynamic].astro paths Sep 2, 2023
@jlarmstrongiv jlarmstrongiv changed the title Astro v3: dev server returns 404 when using [dynamic].astro paths Astro v3: dev server returns 404 for other locales when using [dynamic].astro paths Sep 2, 2023
@ansmlc
Copy link

ansmlc commented Sep 16, 2023

Similar issues here. I've been trying for days but can't make heads or tails of the erratic behavior, both in dev and preview modes.

@jlarmstrongiv
Copy link
Owner

Hey @ansmlc there was an issue with handling trailing slashes that I just fixed, please try again with the latest version!

If you have an issue with translations in preview, please open a new issue. The preview and dev commands depend on different Astro internals, so only dev is broken. Otherwise, it’s a fixable bug in the library.

@jlarmstrongiv
Copy link
Owner

Also @ansmlc if you have a repository or example project I could look at, please send it my way

@dallyh
Copy link

dallyh commented Dec 25, 2023

@jlarmstrongiv Please is this still an issue? I'd like to know before I get to work on a blog, I'd like to have this clarified. I'm assuming that it still happens with version 4 of astro, am I right? Also I see that you updated the status of this issue, but I have figured that I'd still ask just to be sure. Thanks!

@dallyh
Copy link

dallyh commented Dec 26, 2023

@jlarmstrongiv Please is this still an issue? I'd like to know before I get to work on a blog, I'd like to have this clarified. I'm assuming that it still happens with version 4 of astro, am I right? Also I see that you updated the status of this issue, but I have figured that I'd still ask just to be sure. Thanks!

To save you some time, this indeed still happens. My setup was slightly different, but dev server returns erratic 404's and build/preview is fine.

@jlarmstrongiv
Copy link
Owner

@dallyh feel free to ask in the Astro discord. I’ve done everything I can to try and get that issue prioritized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants