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

Custom 404 page not working on Vercel (output mode static) #9578

Closed
1 task done
devmatteini opened this issue Jan 2, 2024 · 10 comments · Fixed by #9591
Closed
1 task done

Custom 404 page not working on Vercel (output mode static) #9578

devmatteini opened this issue Jan 2, 2024 · 10 comments · Fixed by #9591
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority) feat: error pages Related to 404 and 500 handling (scope) pkg: vercel Related to Vercel adapter (scope)

Comments

@devmatteini
Copy link

devmatteini commented Jan 2, 2024

Astro Info

Astro                    v4.0.9
Node                     v18.18.2
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  @astrojs/vercel
Integrations             @astrojs/tailwind
                         astro-icon
                         @astrojs/mdx

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

  • Create a custom 404.astro page.
  • Deploy to Vercel with Astro output mode on static
    I use vercel cli:
    vercel pull --yes --environment production --token "$VERCEL_TOKEN"
    astro build
    vercel deploy --prebuilt --prod --token "$VERCEL_TOKEN"
    
  • Open your website in a non-existing route and the custom 404 page is not shown. The vercel 404 default page is shown instead.
    vercel default 404 page

This is the repository: https://github.com/devmatteini/website
I just ported this repository from Next.js to Astro, so I might have done something wrong somewhere.

Just to give more information, I can see from Vercel deployment Source tab that the deployed files and the 404.html exists (.vercel/output/static/404.html).

This is the rest of the content:
vercel deployed source

Interestingly, if you go to https://<domain>/404.html the custom 404 page is rendered correctly.

What's the expected result?

The custom defined 404 page should be used instead of Vercel's default one when reaching a non-existing route

Link to Minimal Reproducible Example

I'm not sure a minimal example with Vercel is doable since it would require a personal Vercel account

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 2, 2024
@florian-lefebvre
Copy link
Member

Instead of a repro, you could create a minimal github repo (I didn't have a look but looks like it's already the case) and host the website on vercel until this issue is closed

@florian-lefebvre florian-lefebvre added pkg: vercel Related to Vercel adapter (scope) feat: error pages Related to 404 and 500 handling (scope) labels Jan 2, 2024
@devmatteini
Copy link
Author

Hi! If you consider this repository minimal, it's already hosted on vercel (https://cosimomatteini.com/).

Otherwise, I can create a new repository with minimal setup.

@florian-lefebvre
Copy link
Member

Not really minimal imo. Have a look at #9206 to see an example

@lilnasy lilnasy added needs repro Issue needs a reproduction and removed needs triage Issue needs to be triaged labels Jan 3, 2024
Copy link
Contributor

github-actions bot commented Jan 3, 2024

Hello @devmatteini. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

@lilnasy
Copy link
Contributor

lilnasy commented Jan 3, 2024

Can you try @astrojs/vercel@experimental--9591?

@devmatteini
Copy link
Author

Here it is a minimal repo to reproduce the issue: https://github.com/devmatteini/astro-vercel-404-issue
Website: https://astro-vercel-404-issue.vercel.app/

@florian-lefebvre florian-lefebvre added needs triage Issue needs to be triaged and removed needs repro Issue needs a reproduction labels Jan 3, 2024
@devmatteini
Copy link
Author

devmatteini commented Jan 3, 2024

Can you try @astrojs/vercel@experimental--9591?

I installed it, but it didn't solve the issue

@lilnasy lilnasy added - P4: important Violate documented behavior or significantly impacts performance (priority) and removed needs triage Issue needs to be triaged labels Jan 3, 2024
@devmatteini
Copy link
Author

@lilnasy Starting from your patch, I changed the src value to /.* and now it works!

@lilnasy
Copy link
Contributor

lilnasy commented Jan 3, 2024

Forgot I was doing regex 😭

Thanks for looking into it!

@devmatteini
Copy link
Author

Thank you @lilnasy for your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority) feat: error pages Related to 404 and 500 handling (scope) pkg: vercel Related to Vercel adapter (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants