Open joewalnes opened 8 years ago
Musings...
The more I think about it, the more it makes sense to have the browser handle try to do as much as possible and to keep complexity out of the generated code.
How? For Chrome at least, it seems it's possible to use the debugging API to replace the contents a script live at runtime while the app is running. This is what happens when you edit code and hit save in the dev tools.
There are two options for controlling the debugger API:
My suspicion is:
To start with, I'll probably use remote debugging, but the extension will be the final goal.
Either way, it seems the relevant debug protocol hooks are:
Here's some examples I found that show how to update the JS live on a running page:
In addition to updating the JS, a trigger must be sent to the page to tell it to do something (e.g. re-render react components).
This will require a bit of code to be added but it should be straight forward:
window.addEventListener('hotreload', render)
Example triggering this remotely:
Accessing debugger from Chrome extension:
The goal of hot reloading is to allow code changes to propagate to the browser without forcing a refresh. This allows insanely fast feedback loops for UI changes.
This is a placeholder for a discussion on how to implement it.
One thing I don't want to do is force users to have to run a custom development server. This tightly couples users to Node based apps and doesn't support the needs of other server side web stacks (e.g. Rails, PHP, Go, Java, etc...).
Also, users should not have to write any additional code to get this to work. It should simply be a matter of
--hot
.My preference is for hot loading to be provided by the browser developer tools, and should not require bundling additional code into a web-app. There may have to be a small out of band trigger that the cmd line tool can use to notify the browser that it should refresh the code and trigger a render.