Affects Version/s: None
Fix Version/s: None
Component/s: Storytelling Tool UI
The introduction of the reorderer component in the storyEditor grade brought along with it the potential for a race condition whenever new blocks are added.
Ideally, we would like the reorderer to call its "refresh" invoker any time a new block is added, but if this is called while many blocks are being added simultaneously, errors will occur and break the page.
The temporary solution is to delay calling "refresh" until any block has focus, but this results in many superfluous calls to refresh along with subsequent activation of various model relays and listeners related to autosave. These aren't harmful per se (yet), but they do waste cycles and the solution is inelegant and somewhat obscure.
A better solution (proposed by Justin Obara) would be to implement a sort of event queue which, when a block is added:
- enqueues (pushes) an object containing the args of the viewComponentContainerRequested event and whatever else is needed for queue management (maybe nothing),
- fires the event, passing the args,
- dequeues (shifts) the object when the block fires its onTemplateRendered event, and finally
- calls refresh once the queue is empty (when length === 0)
This solution may also require disabling adding new blocks while the refresh is underway (perhaps with a model value and associated listeners), otherwise the race condition is still present.