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

feat(env): load new env variable on update #1368

Merged
merged 8 commits into from Oct 6, 2022

Conversation

Slashgear
Copy link
Contributor

@Slashgear Slashgear commented Oct 4, 2022

Why

Close #1363

How

  • Add new event type for preview app
  • Handle new behaviour for onUpdate for getProcessEnv
  • Handle filewatcher on .env file

Todo

  • I still need to check that everything works correctly but I think this would do the job.
  • Do we need to update documentation about env variable ?
  • Do we need to add new tests on that ?

IssueHunt Summary

Referenced issues

This pull request has been submitted to:


@vercel
Copy link

vercel bot commented Oct 4, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
remotion ✅ Ready (Inspect) Visit Preview Oct 6, 2022 at 9:08AM (UTC)

Copy link
Member

@JonnyBurger JonnyBurger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reload when the file changes is beautifully done! Very nice!
The main point of the PR does not yet work though - when opening the preview and entering process.env in the console, the old environment variables are still present.

Let me know if you have an idea on how to solve this, or if I should help come up with something!

@Slashgear
Copy link
Contributor Author

So I need to flush the previous variable before reinjecting the new one.

  • Run 1 variable A is defined
  • User removes variable A and add a variable B
  • Refresh of the preview app
  • A is not defined anymore and B is defined

That what you mean ?

@JonnyBurger
Copy link
Member

@Slashgear Yes, that would be the desired behavior! Since we currently don't make use of environment variables in Node.JS
during the preview but just in the browser, it needs to be re-injected into Webpack or added into a <script> tag when loading index.html, this would be a relatively simple solution actually.

Another possibility: We currently use DefinePlugin by Webpack, and I found a way to dynamically change the values: https://webpack.js.org/plugins/define-plugin/#runtime-values-via-runtimevalue We could add a dependency on the .env file.

@JonnyBurger
Copy link
Member

JonnyBurger commented Oct 5, 2022

My preferred solution would be if there is a refactor and the environment variables get added to index-html.ts instead of DefinePlugin() like we do for inputProps, since then we use the same pattern for both and we don't rely on Webpack in case we want to support more bundlers in the future.

@JonnyBurger
Copy link
Member

Works super reliably and is very snappy! Thanks a lot for fixing the typo as well 🙌

JonnyBurger
JonnyBurger previously approved these changes Oct 6, 2022
@JonnyBurger
Copy link
Member

Implemented the deluxe version and also added handling for adding / removing a .env file 😇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Load new env variables if .env has changed
2 participants