-
-
Notifications
You must be signed in to change notification settings - Fork 197
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
Hot-reloading #688
Comments
Thanks for thinking about this, @OhadRau ! We totally need this Some ideas from Discord: The API I was thinking for
Then we can use the let newUi = ui^(state) and do the reconciliation But the API would be pretty straightforward to implement on top of:
The main constraint being that the loaded In addition, I think one very first step called out by @Et7f3 is to set up byte-code builds. These are slower in runtime performance, but much faster to build - so whatever route we go for hot-reloading, it will improve the dev-iteration time 👍 For a more concrete example - we could slightly tweak our UI in Onivim 2:
And change our function here: from: One challenge with reloading the UI 'function' is that we don't have a way to know if hooks changed. Consider the following scenario:
...
We have no way of knowing that the hooks changed order, and thus, the backing objects will be incorrect (and probably crash). So for this, the safe thing to do would be to have a 'fresh' render. Which I think is reasonable to start. We could look at ways to improve this as a next step. To have a 'minimal viable product' of this feature, I think we could start with: Part 1: Just restart entire app:
Part 2: 'hot-link' parts of the app:
Part 3: finer-grained state reloading:
I'm not sure that this is needed - from the roadmap I see, we could start by just actually reloading the app. Then, when we move to the finer-grained hot reloading, like |
Ok so some update on the work done:
the current state: I have forked brisk-reconciler and added 2 commits. To explain: We have Main.re that contain the Toplevel component. and Component.re that contain Component1 and Component2. and our UI is.
We have 3 implementations:
Another idea is on hot-reload is detected: compare the hook element is they need the same hook list. ATM we can check at runtime
in
(this case is valid at runtime but can be seen has bug) another case is to detect some Also to test on a real project and finish the 7guis challenge: I have tried to set up hot-reload for a external project and it failed
I don't understand it because it work in the example app here. |
Hot-reloading has been discussed as a possible feature for quite some time and I wanted to go ahead and create a permanent discussion about it here in the issue tracker.
So far, what we've discussed has been very similar to what Reprocessing does, which consists of watching the code for changes & recompiling + relinking it with
Dynlink
.However, in order to be a competitive UI framework, we would prefer stateful hot reloading like what Flutter currently has. Because the UI is a pure function of state, hot-reloading is safe to perform in Flutter (and should be in Reason as well!). The goal here is to store the state of the program (which should be persistent) independently from the UI rendering (which should be volatile), so that upon hot-reloading the old state is recovered and the UI continues rendering as if nothing happens.
In order for that to work, we need some kind of semantic data about what the state is, so that the module knows how to relocate it. One solution for this is creating a centralized database (key-value store) of states with a unique tag for each state. When the application is launched, every state can query the database to see if it has an existing entry that it can adopt; otherwise it would use the default initial value. In the case where the state's type or name changes, the tag would no longer match so it would just use the default value. Reading and writing would happen directly within the DB so there would be no need to copy state back and forth.
To implement this system, it seems like we want some way of giving states an identifier. While this is a lot of extra work for the user to juggle these IDs, a fork of the brisk-reconciler PPX could generate these at compile-time and pass them in without the user having to worry about them. Note that this identifier has to be unique between different invocations of the same component, so if I created 2 checkboxes I need to make sure that their state is separate; at the same time, it has to be mapped back to the right checkboxes upon reloading. It is most likely not possible to preserve the state based on the order these components are rendered, so we need to be really smart about how to "hash" the component.
In terms of a roadmap, I think we'd need the following features for this system to work:
App.start
can probably handle this opaquely)The text was updated successfully, but these errors were encountered: