You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mostly just collecting thoughts on error recovery and handling.
Errors during render methods
Most fundamentally: if an error occurs during a render method, correct recovery is currently difficult as we mutate the internal NodeTree as we go. Catching and aborting an error may thus yield missed or double updates. I believe ReactJS does not have that problem because their system around fibers is specifically designed to be incremental and resumable, only describing the pending changes and carrying them out at a later stage. A cheap solution for us could be to shallow copy the tree and update pointers only once the user code ran successfully.
Restoring state of hooks
ReactJS's (React-Refresh) approach here appears to be to create ad-hoc "keys" for each hook of a changed component. They do so via a BabelJS plugin that generates a signature of each hook invocation, e.g. const [a, setA] = useState(0) would become something like [a, setA], useState, 0. This system allows them to recognize re-orders, deletions, and additions. I assume modifying the signature of a hook may simply drop the state, even if not always required (didn't check that deeply).
For us, an implementation could also be quite simple and actually even more advanced than React's. In particular, React only has good support for built-in hooks and rudimentary support for custom hooks. One idea could be to Sandbox-simulate a component whose class was changed (i.e., make each externally visible state mutation a no-op) and have CMFCurrentReact provide custom implementations of each hook that fetch the source code statement from which they were invoked. Running this for both the old and the new code should yield "hook signatures" in the same way that ReactJS uses them.
The text was updated successfully, but these errors were encountered:
Mostly just collecting thoughts on error recovery and handling.
Errors during render methods
Most fundamentally: if an error occurs during a render method, correct recovery is currently difficult as we mutate the internal NodeTree as we go. Catching and aborting an error may thus yield missed or double updates. I believe ReactJS does not have that problem because their system around fibers is specifically designed to be incremental and resumable, only describing the pending changes and carrying them out at a later stage. A cheap solution for us could be to shallow copy the tree and update pointers only once the user code ran successfully.
Restoring state of hooks
ReactJS's (React-Refresh) approach here appears to be to create ad-hoc "keys" for each hook of a changed component. They do so via a BabelJS plugin that generates a signature of each hook invocation, e.g.
const [a, setA] = useState(0)
would become something like[a, setA], useState, 0
. This system allows them to recognize re-orders, deletions, and additions. I assume modifying the signature of a hook may simply drop the state, even if not always required (didn't check that deeply).For us, an implementation could also be quite simple and actually even more advanced than React's. In particular, React only has good support for built-in hooks and rudimentary support for custom hooks. One idea could be to Sandbox-simulate a component whose class was changed (i.e., make each externally visible state mutation a no-op) and have CMFCurrentReact provide custom implementations of each hook that fetch the source code statement from which they were invoked. Running this for both the old and the new code should yield "hook signatures" in the same way that ReactJS uses them.
The text was updated successfully, but these errors were encountered: