Problem/Motivation

The Video.js formatters expose Width and Height settings that output fixed pixel width/height attributes on the media element. That conflicts with the module’s responsive CSS (width: 100%, aspect-ratio) and is an unusual way to size video players today. The defaults are already “Auto”, so the settings add UI complexity with little benefit.

Steps to reproduce

Remove width and height from formatter settings, config schema, SDC props, and Twig templates. Add an update hook to strip those keys from existing entity view display configs. Sites that need fixed sizing can handle it with CSS on .video-player or the surrounding layout.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork videojs-3619630

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

grevil created an issue. See original summary.

grevil’s picture

Status: Active » Needs review

All done, please review!

thomas.frobieter’s picture

Title: [10.x] Remove width and height settings, as they are quite untypical for a video element » [10.x] Remove width and height settings from the formatter
Status: Needs review » Needs work

Width and height attributes are still required on the video element to prevent Cumulative Layout Shift (CLS).

But I agree, we don't need this in the formatter settings. Its just confusing.

So lets stick with the height and with properties on the video-player SDCs, fix the docs:

* - width: Player width in pixels (overridden by CSS, required to prevent CLS).
* - height: Player height in pixels (overridden by CSS, required to prevent
* CLS).

I've tested a bit in order to reduce CLS and FOUC.

At the moment, we only set the height and width of the video HTML element (and on the video-player-rmote SDCs mediaComponent). I think we should set them for the video player element too. So additonaly:

{# Always set width and height to prevent CLS #}
{% set attributes = attributes.setAttribute('width', width|default('640')) %}
{% set attributes = attributes.setAttribute('height', height|default('360')) %}
{# Only required on the video-player SDC, can be remove on video-player-remote because we dont print the iframe element #}
{% set mediaAttributes = mediaAttributes.setAttribute('width', width|default('640')) %}
{% set mediaAttributes = mediaAttributes.setAttribute('height', height|default('360')) %}

We should also add this to the poster image (turn off JS to see the problem):

// Hide the poster image to prevent FOUC.
$poster['#attributes']->addClass('hidden');

The Video.js player doesn't care about this class, grabs the poster image and everything works fine.

We also should add some CSS to reduce FOUC:

video-player {
  display: block;
  video {
    width: 100%;
  }
}
youtube-video,
vimeo-video {
  display: block;
}
thomas.frobieter’s picture

Status: Needs work » Needs review

Done

grevil’s picture

Status: Needs review » Reviewed & tested by the community

Great stuff! LGTM!

  • grevil committed a30793cb on 10.x
    task: #3619630 [10.x] Remove width and height settings, as they are...
grevil’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.