Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

404 no longer sends slug and redirects ending in / no longer work #415

Closed
1 task done
disrae opened this issue Oct 4, 2024 · 3 comments
Closed
1 task done

404 no longer sends slug and redirects ending in / no longer work #415

disrae opened this issue Oct 4, 2024 · 3 comments
Labels
needs repro Issue needs a reproduction

Comments

@disrae
Copy link

disrae commented Oct 4, 2024

Astro Info

astro info
Astro                    v4.1.2
Node                     v20.10.0
System                   macOS (arm64)
Package Manager          unknown
Output                   hybrid
Adapter                  @astrojs/vercel
Integrations             @astrojs/tailwind

However, npm list shows the latest version of astro installed in the project.
npm list
[email protected] /.../404-issues
├── @astrojs/[email protected]
├── @astrojs/[email protected]
├── @astrojs/[email protected]
├── [email protected] <--- doesn't match astro info
├── [email protected]
└── [email protected]

Describe the Bug

As of late, the vercel adapter no longer passes the slug information to the 404 page, and slugs that need to be redirected that end in a '/' cause a 404 instead of being redirected.
Notice that a path of /en/ fails to redirect.

What's the expected result?

Previously, 404 pages had the slug so I could get the locale and have the correct assets and language.
Previously, redirects to pages ending in a slash were working, for example: /en/ successfully redirected to /en-ca/, but now it returns a 404.

Here is a repo with a reproduction: https://github.com/disrae/astro-404-and-redirects-errors

Link to Minimal Reproducible Example

https://astro-404-and-redirects-errors-git-main-disraes-projects.vercel.app/

Participation

  • I am willing to submit a pull request for this issue.
@ematipico
Copy link
Member

Previously, 404 pages had the slug

What do you mean by slug? I checked your reproduction but I don't see any "slug" used.

@disrae
Copy link
Author

disrae commented Oct 22, 2024

I hope this is more clear

Maybe slug was the wrong word, I meant the path requested.

I'm having trouble parsing the locale from the requested URL when using Astro with the Vercel adapter. In my app, the path after the domain is critical (e.g., /en-ca/my-dead-link). However, the 404 page with the Vercel adapter now just returns 404 as the path, so I can't determine the originally requested locale.

Details

  • Expected Behavior:

    • Given a URL like https://mydomain.com/en-ca/my-broken-link, the Astro 404 page should return the original path.
      • Works in Astro without Vercel adapter, works locally.
    • I need to extract the locale from the requested path (e.g., /en-ca/my-broken-link).
  • Actual Behavior with Vercel Adapter:

    • The path is returned as 404, not the original requested path.
    • This behavior started after a change in the Vercel adapter. It used to behave like Astro, returning the requested path even on 404s.
  • Why Vercel Matters:

    • I use Vercel for its edge network middleware, which dynamically swaps the domain based on the requested locale (different brands/domains for different countries).

Example

  • URL: https://mydomain.com/en-ca/my-broken-link
    • Expected: Astro returns /en-ca/my-broken-link.
    • Actual (Vercel): Returns 404.

Possible Cause

The initial URL parse is based on the Astro docs, but it may have changed, and the Vercel adapter now handles 404s differently.

Help Needed

I need a solution to properly parse the requested path (and locale) when using the Vercel adapter with Astro, even when the path is invalid.

Thanks in advance for your help! 🙏

@ematipico
Copy link
Member

ematipico commented Oct 23, 2024

Please provide a valid reproduction. I checked it out, and there's nothing. It's fine if it works locally but not on vercel, I will deploy, but please create a reproduction (it doesn't even use the vercel adapter). Without it, I find it difficult to understand what you're trying to achieve.

For example:

Astro 404 page should return the original path.

Original path? Do you mean that Astro.url should be https://mydomain.com/en-ca/my-broken-link? Why?

Do you use a custom 404.astro? I don't see it in the reproduction.

@ematipico ematipico added needs repro Issue needs a reproduction and removed needs response labels Oct 23, 2024
@ematipico ematipico closed this as not planned Won't fix, can't repro, duplicate, stale Feb 7, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs repro Issue needs a reproduction
Projects
None yet
Development

No branches or pull requests

2 participants