iTwin / presentation

Monorepo for iTwin.js Presentation Library
https://www.itwinjs.org/presentation/
MIT License
4 stars 0 forks source link

Always report initial tree load duration #564

Closed saskliutas closed 6 months ago

saskliutas commented 6 months ago

Added workaround to make sure that we always report initial tree load. This was happening because of how node loads are scheduled and that observable that loads nodes and adds them into model event if outside subscribers are all unsubscribed. Scheduler always waits until completion if load was started. This leads to the situation like this:

  1. ControlledTree starts loading root nodes
  2. Scheduler subscribes to the load observable
  3. Nodes are loaded and added to the tree model
  4. ControlledTree rerenders and unsubscribes from root nodes load observable
  5. Root nodes load observable emits result and completes but observable returned by ReportingTreeNodeLoader is already unsubscribed and does not report duration.

To workaround this ReportingTreeNodeLoader never unsubscribes from observable loading root nodes. This makes implementation simple and does not require additional changes in @itwin/components-react. It works on assumption that root nodes will be always first request when tree is rendered and scheduler will immediately subscribes to it and also does not unsubscribe until nodes are loaded.

Also updated ReportingTreeNodeLoader to better handle multiple subscribers/unsubscribers by ref counting.

changeset-bot[bot] commented 6 months ago

🦋 Changeset detected

Latest commit: 093fc926ebc8e757a04f660319feba6bddd9f7ac

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages | Name | Type | | ------------------------------ | ----- | | @itwin/presentation-components | Patch | | @itwin/presentation-testing | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR