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

Cloudflare runtime no longer accessible from 404.astro #10421

Closed
1 task
TorbjornHoltmon opened this issue Mar 13, 2024 · 6 comments · Fixed by #10427
Closed
1 task

Cloudflare runtime no longer accessible from 404.astro #10421

TorbjornHoltmon opened this issue Mar 13, 2024 · 6 comments · Fixed by #10427
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: error pages Related to 404 and 500 handling (scope) feat: middleware Related to middleware (scope)

Comments

@TorbjornHoltmon
Copy link
Contributor

TorbjornHoltmon commented Mar 13, 2024

Astro Info

Astro                    v4.5.2
Node                     v21.6.1
System                   macOS (arm64)
Package Manager          pnpm
Output                   server
Adapter                  @astrojs/cloudflare
Integrations             none

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

No response

Describe the Bug

Cloudflare pages runtime bindings are no longer accessible from the 404.astro page.

Download repro, build, and run pnpm preview.

On the index page, you will see the object keys for Astro.locals.runtime and Astro.locals. Here you will see that the runtime is accessible.

Going to a page that does not exist and landing on the 404.astro page, you will see that the object keys are now empty.

What's the expected result?

Cloudlfare pages bindings should be accessible from the 404.astro page.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-xsxm5k?file=src%2Fpages%2F404.astro

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 Mar 13, 2024
@hkbertoson
Copy link

I don't see any bindings defined in your Config. I just tested this out on my repo and it works just fine. I can access Astro.locals on all my pages.

@TorbjornHoltmon
Copy link
Contributor Author

I didn't add any local dev bindings.

Astro local cloudflare pages bindings and stackblitz does not work.
So I only provided a repro that works when downloaded and built.

I have setup everything in the repro, download the project, install dependencies, build and run preview.

@TorbjornHoltmon
Copy link
Contributor Author

CleanShot 2024-03-13 at 16 21 19@2x
CleanShot 2024-03-13 at 16 21 47@2x

@hkbertoson
Copy link

Oh I see it now. Interesting. Have you checked out the Discord? Setting Up Cloudflare Functions for an Astro Project

This post helped me a lot.

Then I also made this post as well that helped. Cloudflare API Routes

The docs need some work I have noticed.

You don't need to run wrangler pages dev ./dist --kv KV You just need to define your bindings in your astro.config and then define them in the Cloudflare Dashboard.

@TorbjornHoltmon
Copy link
Contributor Author

This is issue is probably related to the very recent changes to how 404.astro works.

The bindings you define in the Astro config is for local development only.

Running the built app through wrangler with bindings is basically the same thing as running it Cloudflare.

I am not asking for help here, I am just reporting a reproducible bug.

@lilnasy
Copy link
Contributor

lilnasy commented Mar 13, 2024

Do you know if this behavior changed with a specific version?

@lilnasy lilnasy added - P3: minor bug An edge case that only affects very specific usage (priority) feat: middleware Related to middleware (scope) feat: error pages Related to 404 and 500 handling (scope) and removed needs triage Issue needs to be triaged labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: error pages Related to 404 and 500 handling (scope) feat: middleware Related to middleware (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants