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

Add an environment variable when HMR is active (DENO_HMR or similar) #28770

Open
GroophyLifefor opened this issue Apr 6, 2025 · 1 comment
Open

Comments

@GroophyLifefor
Copy link

Hi Deno team!

I have a feature request that would be super helpful for development workflows: could we add an environment variable (something like DENO_HMR=true) whenever Hot Module Replacement is active?

The problem I'm facing

I'm building a web server (Yelix) with Deno that does some initialization work before handling requests. During development with HMR enabled, I'd like to skip this initialization step on hot reloads since the server is still running and doesn't need to redo everything.

The challenge is that I can't detect if HMR is active at the beginning of my program. The "hmr" event fires after the initial load, so I can't make decisions based on it early enough.

My suggestion

Set an environment variable like DENO_HMR=true when the HMR runtime starts up. This could be done in the HmrRunner::run method or its constructor.

This would let applications detect HMR from the very start and optimize their behavior accordingly. It seems like a small change that could help developers create better development experiences.
I think this would be especially useful for framework authors who want to optimize startup behavior during development cycles.

The relevant code would be in cli/tools/run/hmr.rs.

@GroophyLifefor
Copy link
Author

I actually thought of analyzing the codebase and opening a pr, but unfortunately I am not very familiar with the rust environment that I need to test the code I wrote, and there will be written tests of this, so I opened it as a feature request.

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

No branches or pull requests

1 participant