Model-viewer: Transition back to nested source elements

Created on 13 Mar 2019  路  10Comments  路  Source: google/model-viewer

See thread in #5 for more information.

As @mikkoh points out, <video> is a good parallel with <model-viewer>, and the precedent set on that tag is to allow a set of nested <source> tags (with optional specification of mime types). Being in line with that allow us to avoid some overly specific names (like our current ios-src), support additional types easily in the future, and be inline with other tags.

Specifically, I believe we should:

  • Support nested <source> elements, with required src and optional type attributes
  • Remove the ios-src attribute (or deprecate it, moving towards a future removal)
  • Leave the src attribute as an easy fallback (this is in line with other elements)
customization extensibility partner feature

Most helpful comment

I'm cool using <source> if everyone else is 馃槀

All 10 comments

Just want to note that a lot of good discussion on this topic is taking place in the previously closed issue #5

FYI. I was working on this last night. Hopefully have something finished in the next two days.

Because I'm unfamiliar with the deprecation cycle for <model-viewer> what I've done is made it so that <model-viewer> prefers <source> to determine URLs to models but falls back to the src and ios-src.

See #452 for a sample of how we've renamed an attribute - although, that being said, the change to <source> feels a bit more fundamental so I appreciate the fallback. I'll add an issue to discuss (and then document) the deprecation cycle - see #473.

Because I'm unfamiliar with the deprecation cycle for <model-viewer> what I've done is made it so that <model-viewer> prefers <source> to determine URLs to models but falls back to the src and ios-src.

Does <video> prefer <source> over src?

Excellent question @mrdoob . From the embedded content section of the HTML5 spec:

There are three ways to specify a media resource, the srcObject IDL attribute, the src content attribute, and source elements. The IDL attribute takes priority, followed by the content attribute, followed by the elements.

From the sounds of things, the attribute always takes precedence. Another interesting tidbit is this:

If a src attribute of a media element is set or changed, the user agent must invoke the media element鈥檚 media element load algorithm. (Removing the src attribute does not do this, even if there are source elements present.)

This suggests two important things:

  1. No matter what, if src is set to null (e.g., the attribute is removed), nothing should be loaded
  2. <source> element URLs should not be considered fallbacks when the src attribute is removed / set to null

From elsewhere in the spec, it also has this to say about <source> elements:

Dynamically modifying a source element and its attribute when the element is already inserted in a video or audio element will have no effect. To change what is playing, just use the src attribute on the media element directly... Generally, manipulating source elements manually after the document has been parsed is an unnecessarily complicated approach.

This is a very helpful simplification of the problem. Otherwise, we would have to create a MutationObserver just to know when the src attribute on the <source> elements has changed in a meaningful way.

I don't think we can do:

<model-viewer>
  <source>
</model-viewer>

It's not valid HTML.

It would need to be something like:

<model-viewer>
  <model-viewer-source>
</model-viewer>

@mikkoh what aspect of it being not valid are you most concerned about?

Personally I would like us to strive for enabling content authors to write the most valid HTML possible. Here are some of my thoughts on this topic:

There are a lot of cases where child content might make semantic sense for a custom element, but is not explicitly allowed by the HTML spec. You could make a strong case that <model-viewer> is akin to other media elements such as <video> and <audio>, both of which are allowed to have <source> children by virtue of being media elements.

Perhaps more importantly, if you add a <source> tag as a child of <model-viewer>, it will remain in that logical relationship when parsed. The <source> tag won't be booted out, and it won't mysteriously disappear.

It is correct to say that an HTML validator will say that using <source> inside a custom element is invalid. In practice, it is very easy to "break" the rules, even if breaking them has no real consequence. For example, if I run the W3C validator against Shopify's front page I notice that there are many validation errors, but most of them are probably inconsequential enough to be ignored.

I'm cool using <source> if everyone else is 馃槀

@cdata This looks like a breaking change, yes? As such, should we prioritize it ahead of 1.0?

I think this could be implemented in a transitional way so that it works in lieu of attributes but will use the attributes if available. The <video> element works this way (see my comment above).

In other words: it would not necessarily need to be a breaking change.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pushmatrix picture pushmatrix  路  34Comments

hybridherbst picture hybridherbst  路  43Comments

pushmatrix picture pushmatrix  路  22Comments

jsantell picture jsantell  路  17Comments

hybridherbst picture hybridherbst  路  19Comments