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 with Astro SSR not working on Netlify #4269

Closed
1 task done
maxcell opened this issue Aug 11, 2022 · 9 comments · Fixed by #4274
Closed
1 task done

Custom 404 with Astro SSR not working on Netlify #4269

maxcell opened this issue Aug 11, 2022 · 9 comments · Fixed by #4274
Assignees
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)

Comments

@maxcell
Copy link

maxcell commented Aug 11, 2022

What version of astro are you using?

1.0.2

Are you using an SSR adapter? If so, which one?

Netlify

What package manager are you using?

npm

What operating system are you using?

MacOS

Describe the Bug

When a user applies the netlify adapter (and turns the output to 'server') to produce a SSR build, it appears as though a custom 404 page doesn't get picked up for the redirect rules anymore. Even if a user also tries to use the netlify.toml to manually conduct the 404 redirect, it doesn't pick up the custom page.

It was a user reported bug within the Discord.


You can see this live in these two experiences:

Link to Minimal Reproducible Example

maxcell/test-astro-ssr#1

Participation

  • I am willing to submit a pull request for this issue.
@maxcell maxcell changed the title Custom 404 with Astro SSR not Custom 404 with Astro SSR not working on Netlify Aug 11, 2022
@irg1008
Copy link

irg1008 commented Aug 11, 2022

Thank you for openning this issue. Has been driving me crazy for the past 2 days.

We talked about it on the discord channel and I have come with the next temporary solution using _redirects file in static folder. (It won't work using netlify config file).

We need to add the next redirect:

/* /.netlify/functions/entry 404

That way the 404 responses will be redirected and handled by the function like it does with the rest of pages.
I don't think it's the ultimate solution but It works for the moment

@irg1008
Copy link

irg1008 commented Aug 11, 2022

Okay so It turns out it after few attemps the function has crashed and the invocation has failed. 😕

The next error is displayed:

Error - Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

image

@irg1008
Copy link

irg1008 commented Aug 11, 2022

I retract from my previous message. It does work.

The displayed error is non-related about a react component used within the 404 page. For that I am sorry

With the redirect as stated above it works perfectly on production!

@natemoo-re
Copy link
Member

I'm curious if this has anything to do with #4247, which was merged but has not been released yet?

cc @matthewp

@natemoo-re natemoo-re added the - P4: important Violate documented behavior or significantly impacts performance (priority) label Aug 11, 2022
@matthewp
Copy link
Contributor

Thanks for the info @irg1008! Going to add that to our integration.

@matthewp
Copy link
Contributor

@irg1008 does that entry need to be the last one in the redirects file?

@yogthesharma
Copy link

Do we have the same functionality for vercel.com also ?

@Anurodhydv
Copy link

Thank you for openning this issue. Has been driving me crazy for the past 2 days.

We talked about it on the discord channel and I have come with the next temporary solution using _redirects file in static folder. (It won't work using netlify config file).

We need to add the next redirect:

/* /.netlify/functions/entry 404

That way the 404 responses will be redirected and handled by the function like it does with the rest of pages. I don't think it's the ultimate solution but It works for the moment

Thank you for openning this issue. Has been driving me crazy for the past 2 days.

We talked about it on the discord channel and I have come with the next temporary solution using _redirects file in static folder. (It won't work using netlify config file).

We need to add the next redirect:

/* /.netlify/functions/entry 404

That way the 404 responses will be redirected and handled by the function like it does with the rest of pages. I don't think it's the ultimate solution but It works for the moment

I don't see a _redirect file in static folder. It is only in dict folder and the last two line are these
/404 /.netlify/edge-functions/entry 200
/* /.netlify/edge-functions/entry 404
When ever i update this file it goes back to original state when i run yarn run build. Please help me with this @irg1008

@SStan-prog
Copy link

Unfortunately this solution is not working for my site.
Is there a way to replicate this with built in Astro redirects?

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)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants