Skip to content
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(no-autoplay-audio): don't timeout for preload=none media elements #4684

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

straker
Copy link
Contributor

@straker straker commented Jan 28, 2025

Closes: #4665

@straker straker requested a review from a team as a code owner January 28, 2025 22:14
Copy link

@zlayaAvocado zlayaAvocado left a comment

Choose a reason for hiding this comment

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

should this PR be marked as a breaking change? Since point 3 in the ticket suggests that it should

Comment on lines +21 to +23
if (
actualNode.preload === 'none' &&
actualNode.networkState !== actualNode.NETWORK_LOADING

Choose a reason for hiding this comment

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

should we ignore the preload="metadata" too? it seems like it doesn't put the media in a ready to play state either

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to wait for the media to be playable, we just need the metadata so we can identify the duration (that's why isMediaElementReady waits for any non-zero ready state, rather than specifically waiting for a contentful ready state)

});
it('returns false when <video> can autoplay and has no controls mechanism', async () => {
const checkArgs = checkSetup(`
<video id="target" autoplay="true">

Choose a reason for hiding this comment

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

why are we explicitly specifying the value of the autoplay? it's it just a boolean attribute? E.g. autoplay = "false" is equal to autoplay="true" and will still autoplay.

'<source src="/test/assets/video.mp4" type="video/mp4" />' +
'</video>',
{ allowedDuration: 15 }
it('returns false when <video> loops and has no controls mechanism when duration is unknown', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the duration actually unknown for this (and all the other test cases meant to exercise unknown duration paths?) It looks like this is using the same media sources as the other test cases for known durations

}

/**
* Ignore media nodes which are `paused` or `muted`
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this comment explain why it's doing this, as opposed to what it's doing? The what is already clear from the code.

* Ignore media nodes which are `paused` or `muted`
*/
if (
actualNode.hasAttribute('paused') ||
Copy link
Contributor

Choose a reason for hiding this comment

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

no-autoplay-audio also omits cases without an autoplay attribute; did you leave out that case intentionally?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm just realizing now on a fresh reading of the spec that if we do restrict to only waiting for autoplay cases, we actually might want to not add the new logic for preload="none" because of this note in the spec:

Note: The autoplay attribute can override the preload attribute (since if the media plays, it naturally has to buffer first, regardless of the hint given by the preload attribute). Including both is not an error, however.

Comment on lines +21 to +23
if (
actualNode.preload === 'none' &&
actualNode.networkState !== actualNode.NETWORK_LOADING
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to wait for the media to be playable, we just need the metadata so we can identify the duration (that's why isMediaElementReady waits for any non-zero ready state, rather than specifically waiting for a contentful ready state)

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

Successfully merging this pull request may close these issues.

preload-media should avoid blocking on uninteresting media elements
3 participants