refactor: more principled optimization animation support in @penrose/editor
#1017
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Related issue/PR: #1000
#1000 re-introduced optimization animation in
@penrose/editor
by allowing "step size" configuration. However, because we handled repeated stepping by a simple while loop, there can be race conditions when the user press "resample" multiple times, i.e. the frames from the previous state might get rendered.In general, the optimizer for a given diagram should stop running in the browser upon re-compilation and resample, but the animation is only possible if we call
stepState
andRenderStatic
sequentially. To solve this problem, this PR uses (1) Recoil to manage the state transition between diagram states and (2)requestAnimationFrame
to avoid too many recursive state updates in React and to ask the browser to render each frame. Importantly, we also callcancelAnimationFrame
to make sure that there is only one pending animation request (source). Otherwise, there can be race conditions among animation frames just as before.Implementation strategy and design decisions
roger
ifeditor
is running locallyExamples with steps to reproduce them
Checklist
diagrams/
folderOpen questions
N/A