-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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: deno run --unstable-hmr #20876
Conversation
I tried to compile this branch, but ran into the following errors:
|
@marvinhagemeister the error should go away if you tried to build after pulling this branch again. |
@bartlomieju Awesome, got it to work with the latest changes you pushed to the branch 👍 Played around with it and it's already amazing even in its early stages! It's soo much better than just having watch mode 💯 Some notes:
So, in conclusion this is likely a fair tradeoff to make. From a product standpoint the only thing I'd add before shipping is:
|
Thanks for trying this out!
Very reasonable and I believe we just need a few hours of works to provide all this functionality. In terms of DX - I really don't like |
I guess this depends on how confident we are in this. Long term it makes sense to combine the two. For now going with a separate My vote is for I think the difference can be described well:
|
Coming off a talk with @bartlomieju and we chatted a bit about an API so that user code can be notified when an HMR update is applied. A use case for that is for Fresh where we'd like to notify the browser that the server applied an HMR update so that the browser can then initiate a new render with the updated content. There is a bit of prior art on API designs for that in the vite ecosystem which went with a more modern spin on webpack's older HMR API. They went with For Deno though we both weren't sure if that's the right choice. VIte's API gets the module record passed as an argument which we don't have with the v8 API that we're basing this on. Instead a much more "web-like" alternative seems to instead go with a normal event dispatch instead. Something like: addEventListener("deno:hot", ev => {
console.log(`[hmr] Update applied to ${ev.data.file}`)
// prints: [hmr] Update applied to file://foo/bar/baz.tsx
}); A simple event listener would be quite a powerful API as we could hook it into lots of other things too like the test runner for example. For Fresh this would be perfect as well as this allows me to ping the browser and handle the update there. |
Found a scenario where the process isn't restarted anymore after an error anymore: // foo.tsx
// Uncomment these lines and comment them again
// import foobar from "bar";
// console.log(foobar);
export function foo() {
return `<h1>a</h1>`;
}
// main.ts
import { foo } from "./foo.tsx";
let i = 0;
setInterval(() => {
console.log(i++, foo());
}, 1000); Steps to reproduce:
|
Came across another issue: With |
Thanks for reporting that Marvin, both of these problems have been handled and are restarting properly 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be a nice feature.
adff3e9
to
f5412b7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This commit adds
--hmr
flag, that enabled Hot Module Replacement.This flag works like
--watch
and accepts the same arguments. IfHMR is not possible the process will be restarted instead.
Currently HMR is only supported in
deno run
subcommand.Upon HMR a
CustomEvent("hmr")
will be dispatched that containsinformation which file was changed in its
details
property.