withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.62k stars 2.47k forks source link

Pre-rendered pages with Netlify SSR (edge) do not follow their 200 rewrite #6496

Closed christianpetty closed 1 year ago

christianpetty commented 1 year ago

What version of astro are you using?

2.0.14

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

Netlify Edge

What package manager are you using?

npm

What operating system are you using?

Linux Ubuntu 22.04.2 WSL

What browser are you using?

Firefox 110.0.1

Describe the Bug

.astro pages marked for pre-render export const prerender = true; result in a blank page unless you request the .html file.

For example: https://dev.rad.cm/404 is blank https://dev.rad.cm/404.html works

The _redirects file in the build folder correctly has this line:

/404         /404.html                         200

This is the same for other pre-rendered pages, but it then requires me to place the file inside a subdirectory of /pages and rename it to index.html. Is that always the case?

This issue does not occur with netlify dev or astro dev locally. So, unsure if this is a Netlify problem.

"dependencies": {
        "@astrojs/mdx": "^0.17.2",
        "@astrojs/netlify": "^2.1.2",
        "@astrojs/tailwind": "^3.0.1",
        "astro": "^2.0.14",
        "netlify": "^13.1.2",
        "netlify-cli": "^13.0.0",
        "tailwindcss": "^3.2.7"
    }

Link to Minimal Reproducible Example

https://dev.rad.cm/404

Participation

natemoo-re commented 1 year ago

Interesting, I'm getting a 500 error for https://dev.rad.cm/404 rather than a blank page. This is likely an issue on our end with the edge adapter? I'll look into this.

christianpetty commented 1 year ago

I think this may be related: with Netlify dev, non-extension requests will randomly begin to fail with this error on all the CSS files:

The stylesheet https://rad-cm-c23d5d.netlify.live/_astro/index.c1f7409e.css was not loaded because its MIME type, “text/html”, is not “text/css”.

I have to delete the repo from my machine and re-clone for this to resolve. localhost:3000 work fine though, so it's hard to say if this is Netlify or Astro.

christianpetty commented 1 year ago

If I modify the _redirects output, I can get things to work.

As built:

/           /.netlify/edge-functions/entry    200
/contact    /.netlify/edge-functions/entry    200

Modified:

/           /index.html    200
/contact    /contact/index.html    200

This would be bypassing the edge function though? This is in a GitHub codespace, so I'm seeing a similar but different issue now on SSR pages referenced without a file extension. Astro dev works though (not Netlify dev).

christianpetty commented 1 year ago

I posted a similar issue to Netlify where redirects are not working. They think it's an Astro issue.

https://wiki.radianrad.com/Tools/Tolerance+stack+analysis       https://bb.rad.cm/t/tolerance-analysis/133         301!
https://wiki.radianrad.com/*        https://bb.rad.cm                                       301!
https://radian.wiki/*               https://bb.rad.cm                                       301!
https://wiki.rad.cm/*               https://bb.rad.cm                                       301!
https://onshape.rad.cm/*            https://bb.rad.cm/t/about-onshape-cad/182               301!
https://mathcad.rad.cm/*            https://bb.rad.cm/t/ptc-mathcad/77                      301!
https://qr.rad.cm       https://rad.cm/                           301!
https://rad-cm.netlify.app/*          https://rad.cm/:splat       301!
https://www.christianpetty.com/*      https://rad.cm/:splat       301!
https://christianpetty.com/*          https://rad.cm/:splat       301!
https://www.radianrad.com/*           https://rad.cm/:splat       301!
https://radianrad.com/*               https://rad.cm/:splat       301!
https://www.radianrd.com/*            https://rad.cm/:splat       301!
https://radianrd.com/*                https://rad.cm/:splat       301!
https://www.radian.ltd/*              https://rad.cm/:splat       301!
https://radian.ltd/*                  https://rad.cm/:splat       301!
https://www.radian.llc/*              https://rad.cm/:splat       301!
https://radian.llc/*                  https://rad.cm/:splat       301!
https://fire.christianpetty.com       https://rad.cm/fire         301!

/qr                                   https://qr.rad.cm                                 301!

/portfolio                        /file/100010G%20RAD%20Portfolio.pdf             301!
/resume                           /file/christian_petty_resume.pdf                301!

/ty/*                               https://bb.rad.cm/:splat                      301!
/s/*                                https://bb.rad.cm/search?q=:splat             301!
/search/*                           https://bb.rad.cm/search?q=:splat             301!

/mathcad                            https://bb.rad.cm/t/ptc-mathcad/77                      301!
/met                                              https://bb.rad.cm/t/mathcad-excel-tool/61                 301!

/hello          /.netlify/functions/hello                         200
/rand_color     /.netlify/functions/random_hex_color              200

/calc/thread-profile*    /threads:splat                           301!
/tools/thread-profile*   /threads:splat                           301!
/tools/log*              /log:splat                               301!
/             /.netlify/edge-functions/entry    200
/calc-test    /.netlify/edge-functions/entry    200
/contact      /.netlify/edge-functions/entry    200
/success      /success/index.html               200
/threads      /.netlify/edge-functions/entry    200
/coils        /.netlify/edge-functions/entry    200
/fire         /.netlify/edge-functions/entry    200
/math         /.netlify/edge-functions/entry    200
/404          /404.html                         200
/log          /.netlify/edge-functions/entry    200
/ip           /.netlify/edge-functions/entry    200

Many of these redirects do not work, but do if they are moved to their own fresh repo without Astro.

For example, https://radian.llc does not redirect. Nor does https://radian.llc/contact

But https://radian.llc/123456, or https://radian.llc/abcdef (any random URL that isn’t an actual page) does.

christianpetty commented 1 year ago

Redirects with Netlify are not working in astrojs/netlify 2.2.2 and astro 2.4.5.

natemoo-re commented 1 year ago

Hey sorry for the delay @christianpetty, I am finally circling back to this. Sorry you're having trouble with redirects as well. I am going to try to repro this and find a fix.

natemoo-re commented 1 year ago

Hey @christianpetty!

I pulled rad-cm-min and was able to upgrade astro to the latest and @astrojs/netlify. I'm not seeing any issues with the generated _redirect file.

Seems like there's something more complicated going on here, so I'll either need access to the full repo or a new minimal reproduction to debug this further. You can also hop into our Discord and I can try to help you there.

github-actions[bot] commented 1 year ago

Hello @christianpetty. 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.

christianpetty commented 1 year ago

Hi @natemoo-re! Thank you for looking into this. I can upload a minimal repo soon. I checked and this is still a problem on the production site.

https://dev.rad.cm/contact when set to prerender, does not load unless you specify https://dev.rad.cm/contact/index.html.

christianpetty commented 1 year ago

@natemoo-re I'll update to the latest first to see if that fixes it.

christianpetty commented 1 year ago

No luck. I'll work on a minimal repo.

christianpetty commented 1 year ago

@natemoo-re ok check out https://github.com/christianpetty/rad-cm-min

https://min.rad.cm/404 does not properly route to https://min.rad.cm/404.html

natemoo-re commented 1 year ago

Thanks @christianpetty! I'll take a look at this as soon as I can!

matthewp commented 1 year ago

We have deprecated the Vercel Edge and Netlify Edge adapters due to compatibility issues and are encouraging people to instead use the serverless versions of these adapters, along with Edge Middleware, which we feel gives you the best of both worlds. Our adapter migration plan is laid out in this roadmap issue.

If you're still interested in deploying to these edge platforms I'd encourage you to build an adapter for it. You can use the edge adapter code as a starting point.

Closing as we are not planning on fixing edge adapter bugs (but will continue to support edge middleware).

christianpetty commented 1 year ago

Thank you for the info. When you say use the serverless adapter, which is that? I thought both function/edge-function were already serverless? Or is the entire Netlify adapter all together being deprecated?