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.
Breaking change
Proposed change
Type of change
Example configuration
Additional information
This PR fixes an issue I've been having at least the last 6 months. On one of my dashboards the logbook card consistently fails to load the first time. It just spins forever. Changing to another page then coming back to the page loads the card correctly, which is why I've just been putting up with it until now.
This appears to be a race condition. If I put the logbook card by itself on a view then it loads correctly. I only experience this issue if the logbook card is in a view with many other cards.
I've attached a screen recording of the bug in action. When I click on the "Pool" view you will see the "Pool Activity" card just spinning. When I go back to the "Home" view then back to the "Pool" view you can see the "Pool Activity" loaded. I only stayed on the "Pool" view for a few seconds in this video but you can leave it forever and the card will never load.
Screen.Recording.2025-01-22.172322.mp4
The first commit removes a call to this._unsubscribe();. That function does nothing if this._subscribed is undefined, and the code right before this call returns if this._subscribed is undefined so the call to unsubscribe will never do anything.
The second commit adds an await to the call to subscribeLogbook, which is what actually fixes the bug. This changes the type of this._subscribed which is no longer a Promise.
It does seem that the original code should work fine and this change should result in identical behavior (we just moved the await from _unsubscribe to _subscribeLogbookPeriod) so i can't really explain why this fixes the problem but it does.
I was concerned that adding the await in _subscribeLogbookPeriod might end up blocking the page load or something, so I tested by adding an artificial 5 second delay before the call to subscribeLogbook. This causes the logbook card to spin for 5 seconds before loading (as expected) but the rest of the page loaded and functioned with no discernable issues.
Checklist
If user exposed functionality or configuration variables are added/changed: