Skip to content

Conversation

ondreian
Copy link
Contributor

@ondreian ondreian commented Aug 12, 2025

This PR will...

Properly declare the type for NetworkDetails

Why is this Pull Request needed?

Removes reliance on any type in favor of properly declaring NetworkDetails for better developer ergonomics when matching against HTTP outcomes

Are there any points in the code the reviewer needs to double check?

I traced the usage of NetworkDetails as best as possible to all existing usages in the codebase and found that in some cases it is declared as networkDetails? type and sometimes is is passed as a null object. I did not clean this up because technically it could be a breaking change, but converging it so that networkDetails? is preferred would make sense for code clarity and overall maintainability in the future.

New Work Relative to Previous PR

There were several places where meaningful drift had occurred relative to my previous PR, most notably the new instanceof Response check to handle the url property in the playlist-loader.ts:
https://github.com/video-dev/hls.js/compare/master...flowplayer:hls.js:refactor/nullable-network-details?expand=1#diff-9da3ee2cb4fcb3e4fb98d46740cd4d9e071fa77e4b26336c0750ac2456945fb5R667-R670

I felt the differences were enough to warrant a separate PR with all of the new interstitial loading logic and such, it wasn't a simple rebase and fixup.

Resolves issues:

resolves unnecessary dependence on any type

Checklist

  • changes have been done against master branch, and PR does not conflict
  • new unit / functional tests have been added (whenever applicable)
  • API or design changes are documented in API.md

@ondreian
Copy link
Contributor Author

ondreian commented Aug 12, 2025

I'm not sure why the precommit hooks didn't fix up everything to match the prettier settings (i'll handle it on the next commit), but there are some issues with the types in the unit tests like this:
https://github.com/flowplayer/hls.js/blob/e6a4ecea332af2043e6b63fc921d24c4a9922a6f/tests/unit/controller/subtitle-track-controller.ts#L492-L500
and
https://github.com/flowplayer/hls.js/blob/e6a4ecea332af2043e6b63fc921d24c4a9922a6f/tests/unit/controller/level-controller.ts#L120-L124

Which I need to fix up now as well.

@robwalch
Copy link
Collaborator

I'm not sure why the precommit hooks didn't fix up everything to match the prettier settings (i'll handle it on the next commit)

Apologies for that. There's either an expectation that the IDE you use would be configured to run it on save, or you'd perform npm prettier prior to staging and reviewing your commit. I'm used it because I run npm run prettier && npm run sanity-check before committing changes.

there are some issues with the types in the unit tests like this

Let me know if I can help. Thanks for picking this up again 😄

@ondreian
Copy link
Contributor Author

ondreian commented Aug 13, 2025

Unit tests are working!

  • used a real Response instance for unit tests in place of {} since this has been available since Node 18 and the .node-version is 22
  • reran api-extractor so that it matches the new interface NullableNetworkDetails that we are exposing now in place of any

I added a couple of inline comments on the PR to the two places I thought maybe the reason could be slightly unclear about why I did something. I think this is good to review, the missing checks seem to require credentials I won't have access to as an outside contributor.

@@ -663,7 +664,10 @@ class PlaylistLoader implements NetworkComponentAPI {
};

if (response) {
const url = networkDetails?.url || context.url;
let url = context.url;
if (networkDetails instanceof Response) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we support any devices that are old enough that Response can be undefined? https://caniuse.com/?search=Response

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid this for devices running older (Safari 8 like) WebKit runtimes (Smart TV, and Android 4).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this?

Suggested change
if (networkDetails instanceof Response) {
if ('url' in networkDetails) {

Copy link
Contributor Author

@ondreian ondreian Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will have to be

if (networkDetails && 'url' in networkDetail)

to safely handle 'url' in null or else we will get Uncaught TypeError: right-hand side of 'in' should be an object, got null

This is definitely a safer check on older devices so I will fix that up!

Copy link
Collaborator

@robwalch robwalch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great work! If it's not too much trouble, please roll back the test string ws changes, and remove the instanceof Response reference just in case. Thank you.

@@ -663,7 +664,10 @@ class PlaylistLoader implements NetworkComponentAPI {
};

if (response) {
const url = networkDetails?.url || context.url;
let url = context.url;
if (networkDetails instanceof Response) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this?

Suggested change
if (networkDetails instanceof Response) {
if ('url' in networkDetails) {

@ondreian ondreian requested a review from robwalch August 15, 2025 13:09
robwalch
robwalch previously approved these changes Aug 18, 2025
@robwalch robwalch added this to the 1.7.0 milestone Aug 18, 2025
@robwalch robwalch enabled auto-merge (squash) August 26, 2025 22:19
@robwalch robwalch disabled auto-merge August 26, 2025 22:19
@robwalch
Copy link
Collaborator

Hi @ondreian,

Sorry but the last patch or two introduced branch conflicts. Can you resolve them? Let me know if you are not available to and I'll make an intermediate branch to address this in. Thank you!

@ondreian
Copy link
Contributor Author

I can do this tomorrow morning hopefully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

2 participants