You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enable runtime updates of environment variables in React Native applications. When .env files are modified while the app is running, the changes will be reflected in JavaScript immediately without requiring a rebuild. Note that native-side environment variables will still require a rebuild to update, as they are compile-time values.
Motivation
Building React Native apps can be time-consuming, especially for larger projects. Many applications only use environment variables in JavaScript code, making runtime updates valuable for development workflows. Currently, even simple environment variable changes require a full rebuild.
Technical Considerations
I am not sure if the current behavior (requiring rebuilds) is intentional, or merely due to technical reasons? Any relevant previous discussions or issues would be helpful context (i haven't found anything on a quick search)!
There's a potential for confusion if JavaScript and native environment variables become out of sync. However, developers using native-side environment variables typically understand that changes would require a rebuild.
Proposed Implementation
Create a Metro plugin that:
Watches .env files for changes
Serves dynamic environment values to JavaScript
The library code internally would first check if the import from JS is available, but otherwise fallback to the native values. Something like importFromJs ?? envVarsFromNativeSide
In release we would always use the envs from the native side
[Note: i haven't looked very closely at the code of this lib yet, let me know if there are reasons why this solution wouldn't work.]
Making this a Metro plugin would:
Keep the feature opt-in
Preserve existing behavior for users who don't configure the plugin, which would avoid breaking changes when someone updates to the latest version
I'm willing to implement this functionality as I have a direct use case for it. I just wanted to discuss this with the maintainers first, so let me know what you think please ✌️
The text was updated successfully, but these errors were encountered:
What?
Enable runtime updates of environment variables in React Native applications. When
.env
files are modified while the app is running, the changes will be reflected in JavaScript immediately without requiring a rebuild. Note that native-side environment variables will still require a rebuild to update, as they are compile-time values.Motivation
Building React Native apps can be time-consuming, especially for larger projects. Many applications only use environment variables in JavaScript code, making runtime updates valuable for development workflows. Currently, even simple environment variable changes require a full rebuild.
Technical Considerations
Proposed Implementation
Create a Metro plugin that:
importFromJs ?? envVarsFromNativeSide
[Note: i haven't looked very closely at the code of this lib yet, let me know if there are reasons why this solution wouldn't work.]
Making this a Metro plugin would:
I'm willing to implement this functionality as I have a direct use case for it. I just wanted to discuss this with the maintainers first, so let me know what you think please ✌️
The text was updated successfully, but these errors were encountered: