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

Should lang be propagated across shadow tree boundaries? #4906

Open
emilio opened this issue Sep 12, 2019 · 9 comments
Open

Should lang be propagated across shadow tree boundaries? #4906

emilio opened this issue Sep 12, 2019 · 9 comments
Labels
i18n-tracker Group bringing to attention of Internationalization, or tracked by i18n but not needing response. topic: shadow Relates to shadow trees (as defined in DOM)

Comments

@emilio
Copy link
Contributor

emilio commented Sep 12, 2019

See also #3821, #3699.

Testcase:

<!doctype html>
<html lang="en">
<div id="host"></div>
<script>
host.attachShadow({ mode: "open" }).innerHTML = `
<style>
  div:lang(en) {
    width: 100px;
    height: 100px;
    background-color: green;
  }
</style>
<div></div>
`;
</script>
@emilio
Copy link
Contributor Author

emilio commented Sep 12, 2019

Well, this is not so obvious. More complex test-case:

<!doctype html>
<html lang="en">
<link rel="author" href="mailto:emilio@crisal.io" title="Emilio Cobos Álvarez">
<link rel="author" href="https://mozilla.org" title="Mozilla">
<link rel="help" href="https://html.spec.whatwg.org/#attr-lang">
<link rel="help" href="https://github.com/whatwg/html/issues/4906">
<link rel="match" href="lang-001-ref.html">
<style>
#host > div {
  width: 100px;
  height: 100px;
}
#host > div:lang(de) {
  background-color: green;
}
#host > div:lang(en) {
  background-color: red;
}
</style>
<div id="host"><div></div></div>
<script>
host.attachShadow({ mode: "open" }).innerHTML = `
<style>
  div:lang(en) {
    width: 100px;
    height: 100px;
    background-color: green;
  }
</style>
<div></div>
<slot lang="de"></slot>
`;
</script>
</html>

Seems like WebKit and Gecko follow the spec as-written (light DOM parent).

Blink uses parent-or-host-node, that is, not going through slots.

How do we want this to behave? cc @rniwa @domenic @smaug---- @annevk

@smaug----
Copy link
Collaborator

smaug---- commented Sep 12, 2019

My initial thinking is: I would expect lang to use light DOM. And with host... It is a bit weird to propagate semantic information to the shadow DOM automatically when light DOM has no idea whether shadow DOM might use the same lang. If shadow DOM has need for some particular language, it should explicitly set it.

But then, how to deal with text nodes under shadow root. Or perhaps one is just forced to use an extra element there in that case.

One option is to add some flags to ShadowRoot init to have whatever behavior shadow dom author wants, but not sure we want to go that route.

@tabatkins
Copy link
Collaborator

Yeah, I don't think lang should use the flat tree. In the light dom, it should use the visible relationships; that's the interface you're programming the lang against. It should then propogate from the shadow host to its tree, just for good defaulting, but then apply to shadow tree elements solely according to the shadow tree relationships, same as light tree.

Like smaug, I don't think it's reasonable to assume that the component author has a good idea of what lang will be shoved into its slots.

@emilio emilio changed the title lang should be propagated using the flattened tree Should lang be propagated across shadow tree boundaries? Sep 12, 2019
@emilio
Copy link
Contributor Author

emilio commented Sep 12, 2019

Retitling, because I agree with y'all :)

@annevk annevk added i18n-tracker Group bringing to attention of Internationalization, or tracked by i18n but not needing response. topic: shadow Relates to shadow trees (as defined in DOM) labels Sep 13, 2019
@annevk
Copy link
Member

annevk commented Sep 13, 2019

The one thing I care somewhat strongly about is that this behaves the same as dir. They're both semantic and describe the content and both also have an impact on the content. Having them work differently would be rather confusing.

@rniwa
Copy link
Collaborator

rniwa commented Sep 15, 2019

Somewhat tricky issue here is what happens with "dir=auto". See #3699 (comment). Whatever we decide to do with lang content attribute should be consistent with how dir content attribute works.

@fantasai
Copy link
Contributor

@rniwa lang doesn't have an auto value, that is, it doesn't do any introspection of the element's own content. But I agree lang and dir should be consistent.

@rniwa
Copy link
Collaborator

rniwa commented Mar 25, 2020

@fantasai : Per today's F2F discussion, lang should also propagate into the shadow root but not into slot. Does that match your expectation / understanding?

@annevk
Copy link
Member

annevk commented Mar 25, 2020

So we'd need to update

If node's inclusive ancestors do not have either attribute set, but there is a pragma-set default language set, then that is the language of the node. If there is no pragma-set default language set, then language information from a higher-level protocol (such as HTTP), if any, must be used as the final fallback language instead. In the absence of any such language information, and in cases where the higher-level protocol reports multiple languages, the language of the node is unknown, and the corresponding language tag is the empty string.

To something like

If node's inclusive ancestors do not have either attribute set and node's root is a document, then:

  1. If there is a pragma-set default language set, then that is the language of the node.
  2. Otherwise, language information from a higher-level protocol (such as HTTP), if any, must be used as the final fallback language instead. In the absence of any such language information, and in cases where the higher-level protocol reports multiple languages, the language of the node is unknown, and the corresponding language tag is the empty string.

Otherwise, if node's inclusive ancestors do not have either attribute set and node's root is a shadow root, then the language of the node is the language of the node's root's host.

(Probably the whole section could do with a bit of a refactoring, but this is mostly to illustrate the normative change.)

This can result in weird cases where the language of a text node is different from its composed/flat element parent (though never different from its (actual) element parent), but that's probably okay.

Edit: for clarity, this is the behavior of Blink per @emilio above and what more or less had agreement already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
i18n-tracker Group bringing to attention of Internationalization, or tracked by i18n but not needing response. topic: shadow Relates to shadow trees (as defined in DOM)
Development

No branches or pull requests

6 participants