allen-cell-animated / volume-viewer

https://allen-cell-animated.github.io/volume-viewer/
Other
90 stars 7 forks source link

Fix zarr loading from cache #145

Closed frasercl closed 11 months ago

frasercl commented 11 months ago

Fixes a bug where Volumes loaded from OmeZarrLoader would appear blank when the data was fetched from cache.

This problem was caused because the volume's imageInfo was not being updated until after the data had been loaded. Consider the following pseudocode:

// ...
loadSomeData((data) => { // callback
  setData(data);
});
setImageInfo(imageInfo);

If loadSomeData is asynchronous, like it is when the data has to come from a network source, it yields control and allows setImageInfo to run before setData. BUT if it is synchronous, as is the case when data comes straight from cache, then setData is called immediately, before setImageInfo gets a chance to run.

The solution is just to move setImageInfo up to before loadSomeData. So that's what this fix does. No code behavior is actually modified besides being shuffled around.