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

useRuntimeConfig does not inherits env variables without passing env param in cloudflare workers #2054

Open
pi0 opened this issue Jan 5, 2024 · 4 comments
Assignees
Labels
bug Something isn't working preset:cloudflare

Comments

@pi0
Copy link
Member

pi0 commented Jan 5, 2024

Ref: nuxt/nuxt#25047

In the cloudflare workers runtime, the useRuntimeConfig utility without passing explicit (event) parameter fallsback to the ambient context's value which because of cf limitation of env passed to first request, is not extended from env. (src)

Ideally event context should default to useEvent() however ironically CF is one of the only presets that does not have LocalAsyncStorage support out of the box.

To make DX better and consistent for CF users, we can reevaluate _sharedRuntimeConfig value after first request to make sure useRuntimeConfig() will be upgraded at least once.

Other alternative would be to disable caching for _sharedRuntimeConfig value at all. This has benefit of having synchronized runtime config even when running in ambient context but downside of less performance. (I will probably do this as is more straight forward and covering)

@danielroe
Copy link
Member

useRuntimeConfig(event) does not work at the moment in CF, nor does import.meta.env.NUXT_VAR, only process.env.NUXT_VAR.

I think @Atinux also is experiencing this. Not sure if this is the same bug as here or if we should raise a new one, but it seems like a new regression.

cc: @pi0

@pi0
Copy link
Member Author

pi0 commented Apr 29, 2024

@danielroe i appreciate reproduction + new issue to investigate 🙏🏼

@oritwoen
Copy link
Contributor

oritwoen commented Apr 29, 2024

@pi0 @danielroe here is a great reproduction and overall test for envs on Cloudflare:

But from what I see and test, it works as it should. Either I'm missing information or it was a temporary problem with Cloudflare.

I also checked my production applications and it works fine.

@MickL
Copy link
Contributor

MickL commented May 24, 2024

I am using nitropack 2.9.6 and useRuntimeConfig() works fine without passing explicit (event). I think this one can be closed, as @oritwoen also reported it works fine?

However there is another issue that variables starting with NITRO_ are not passed automatically into runtimeConfig as expected: #2468

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working preset:cloudflare
Projects
None yet
Development

No branches or pull requests

4 participants