-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix hanging playback when no stream is available #1562
Fix hanging playback when no stream is available #1562
Conversation
Lines 209-215Oh, brave soul, marching into the battlefield of splicing arrays! But watch out, you just introduced a magic trick in your code. 🧙♀️✨ const firstStream = streamData[0];
if (!firstStream?.stream) {
removeFirstStream(track, index, streamData, dispatch);
return;
} Here's what's happening:
Nuki sees what you did there. Trying to avoid duplication? Kawaii, but it could be more elegant. Also, since Consider this glittering refactored snippet ✨: // If there's no valid stream in the first element, handle appropriately
const [firstStream, ...remainingStreams] = streamData;
if (!firstStream?.stream) {
await handleInvalidFirstStream(track, index, remainingStreams, dispatch);
return;
} And then, Nuki recommends renaming Lines 237-252Oh my, an anonymous function grew up and became a real boy! Or function, in this case. 🎉 function removeFirstStream(track: QueueItem, trackIndex: number, streams: TrackStream[], dispatch) {
// Code here
} Here's Nuki's checklist:
And now, spice it up with async flavor: async function handleInvalidFirstStream(track: QueueItem, trackIndex: number, remainingStreams: TrackStream[], dispatch) {
// Add some cute and helpful comments here
if (remainingStreams.length === 0) { // Look ma, no magic number! 🎩
await dispatch(removeFromQueue(trackIndex));
} else {
await dispatch(updateQueueItem({
...track,
loading: true,
error: false,
streams: remainingStreams // More descriptive variable name, yay!
}));
}
} Remember, code without tests is just a ticking time bomb! ⏰💣 Make sure you defuse it by writing tests for this new functionality. Nuki demands it! 🧪🔬 Keep coding, keep refining, and let's make this code as kawaii as possible! (づ。◕‿‿◕。)づ |
6fabc2f
to
9764d30
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1562 +/- ##
==========================================
- Coverage 72.02% 71.99% -0.03%
==========================================
Files 362 362
Lines 6698 6721 +23
Branches 484 493 +9
==========================================
+ Hits 4824 4839 +15
- Misses 1477 1478 +1
- Partials 397 404 +7 ☔ View full report in Codecov by Sentry. |
Thanks, looks like I missed the data->stream change when I was refactoring this some time ago. This is an alright solution to the problem, and we should go ahead with this PR. |
Sorry it's taking so long, but I don't have much time and have quite some issues getting the tests green, even if the change (coincidentally) works in practice. Failing to resolve stream URLs causes an avalanche of updates to the queue, also the current logic for searching streams is hard to test and possibly not adequate for such cases. I might have to make additional changes, a thing which I initially tried to avoid. I would be grateful for any advice on how to move this PR forward, @nukeop . |
No problem, maybe it'll be easier if I do it for you? |
I don't mind if you take over. I assumed that Here's what I found so far:
Please let me know what you find out, even if it's not the final solution. |
Here's my local WIP state if you are curious and want to take a look: sferra#1
Edit: |
Ok, please go ahead. And I might add some sort of a check for missing fields so that these actions fail instead of hanging. |
I see that you added me to your fork as a collaborator. But actually, you only have to open a PR here, and Github will let me push directly to your branch (unless you explicitly forbid it). I'll take a closer look at this today. |
Thanks, for the feedback and assistance. There's no hurry from my side. Regarding the fork, I added you as a collaborator to the fork so you can comment and review the linked "WIP PR" more easily. The PR (which is now merged into this one) was within the fork, against the branch of this PR so it contained just the diff to this PR. I just wanted to provide you with a convenient way to verify those changes. Regarding this PR, I suppose that I should add unit test coverage to the functions I extracted, since the coverage didn't increase with this PR. The component tests cover just specific use cases and it's not possible to cover all combination of execution paths with that type of test. I understand that you prefer the component tests, but IMO it's better to have both. Unit tests help a lot in preventing regressions when making bigger changes or refactoring. They also keep the code tested as it moves between the use cases. And I don't mind writing them. : ) |
I'm fine with this amount of coverage to be honest. The functionality you added is covered. Do you want to add anything else, or can this be merged? |
You can merge if you feel it's safe enough. Thanks. |
Awesome, thanks for contributing. |
Addresses #1560.
I can add test coverage for the new code if this solution is generally accepted.