mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Previously, the `user-tips` service included a couple of calls to `next()`. These were introduced to work around errors like ``` You attempted to update `availableTips` on `<UserTips:ember659>`, but it had already been used previously in the same computation ``` These errors come from the fact that various `<UserTip>` components are rendering at slightly different times in the runloop and stepping on each other. Normally this doesn't happen in Ember, but the implementation details of our 'Widget' system and its 'RenderGlimmer' helper mean that RenderGlimmer components are rendered later than normal Ember components. Using `next()` avoids the problem because it means that all the updates are scheduled together in the following runloop interation. However, the use of `next()` can create some subtle timing issues, which have been evident in the recent flakiness of some qunit tests. This commit makes a few changes to improve the situation: 1. Use a TrackedMap to provide fine-grained `shouldRender()` reactivity for each user-tip id. That means that different user tips will not be trying to update the same piece of tracked state (previously the entire `availableTips` array was `@tracked`, and was completely re-assigned every time a new `<UserTip>` was rendered 2. Avoid reassigning any tracked state unless the value has actually changed 3. Remove the `next()` workarounds