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

Images in src folder are not working in vercel branch preview with deployment protection enabled #10752

Closed
1 task
Trombach opened this issue Apr 11, 2024 · 4 comments · Fixed by #10775
Closed
1 task
Labels
needs triage Issue needs to be triaged pkg: vercel Related to Vercel adapter (scope)

Comments

@Trombach
Copy link

Trombach commented Apr 11, 2024

Astro Info

Astro                    v4.5.18
Node                     v21.6.2
System                   Linux (x64)
Package Manager          pnpm
Output                   hybrid
Adapter                  @astrojs/vercel/serverless
Integrations             @astrojs/tailwind
                         @astrojs/svelte
                         @astrojs/mdx
                         @astrojs/react
                         adds-to-head

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

No response

Describe the Bug

I have not fully understood the cause of this bug, but I am able to reproduce it with a minimal example. It is possible this is entirely on vercel's side but I'm hoping to gain some insight to what's causing this issue here.

It is possible that this bug is also caused under different circumstances, but this is the specific set of conditions I found (also see linked stackblitz). The project must be set to "hybrid" mode and the vercel integration must be added. On pages that are not prerendered, i.e export const prerender = false; is set, images imported won't show on vercel preview deployments when deployment protection (vercel authentication) is enabled for that environment (only alt text is shown). The network tab shows 404 responses for the image requests. Prerendered pages, local development and when deployed to vercel's production environment, everything works as expected.

When I disable vercel authentication in the project settings the 404 responses disappear.

image
image

Please let me know if this issue is entirely on Vercel's end so I can file a bug report with them.

What's the expected result?

Images should work when vercel deployment protection is active.

Link to Minimal Reproducible Example

https://stackblitz.com/~/github.com/Trombach/astro-image-test

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 Apr 11, 2024
@Princesseuh
Copy link
Member

Our image endpoint cannot actually return a 404, so this is either Astro or Vercel returning a 404. Since this only happens when a specific setting in the UI is enabled and only in previews, I would assume that this is on Vercel's end

@Princesseuh Princesseuh added the pkg: vercel Related to Vercel adapter (scope) label Apr 11, 2024
@Trombach
Copy link
Author

Thanks @Princesseuh. I have started a discussion on the vercel Github

@Princesseuh
Copy link
Member

I slept on it and I know what the issue is, the endpoint that runs on Vercel can in fact return a 404.

This happens because the server has to fetch the image from itself to process it (since you cannot access the filesystem in serverless). Since the route is protected with this setting on, the server doesn't have access to itself.

I'm not sure what we, ourselves, can do about that however, probably that Vercel should make it so a deployed function has access to fetch itself even with that setting enabled.

@Trombach
Copy link
Author

I see, that makes sense. I didn't mention this in my original post, but this actually all used to work just a few weeks ago. I wonder if something changed on Vercel's end 🤔
Thanks for looking into this and making a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged pkg: vercel Related to Vercel adapter (scope)
Projects
None yet
2 participants