{"action":"created","issue":{"url":"https://api.github.com/repos/whatwg/dom/issues/510","repository_url":"https://api.github.com/repos/whatwg/dom","labels_url":"https://api.github.com/repos/whatwg/dom/issues/510/labels{/name}","comments_url":"https://api.github.com/repos/whatwg/dom/issues/510/comments","events_url":"https://api.github.com/repos/whatwg/dom/issues/510/events","html_url":"https://github.com/whatwg/dom/issues/510","id":257200716,"number":510,"title":"Declarative Shadow DOM","user":{"login":"tabatkins","id":682840,"avatar_url":"https://avatars0.githubusercontent.com/u/682840?v=4","gravatar_id":"","url":"https://api.github.com/users/tabatkins","html_url":"https://github.com/tabatkins","followers_url":"https://api.github.com/users/tabatkins/followers","following_url":"https://api.github.com/users/tabatkins/following{/other_user}","gists_url":"https://api.github.com/users/tabatkins/gists{/gist_id}","starred_url":"https://api.github.com/users/tabatkins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tabatkins/subscriptions","organizations_url":"https://api.github.com/users/tabatkins/orgs","repos_url":"https://api.github.com/users/tabatkins/repos","events_url":"https://api.github.com/users/tabatkins/events{/privacy}","received_events_url":"https://api.github.com/users/tabatkins/received_events","type":"User","site_admin":false},"labels":[{"id":429410107,"url":"https://api.github.com/repos/whatwg/dom/labels/needs%20implementer%20interest","name":"needs implementer interest","color":"0052cc","default":false},{"id":371408695,"url":"https://api.github.com/repos/whatwg/dom/labels/topic:%20shadow","name":"topic: shadow","color":"009800","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":107,"created_at":"2017-09-12T22:17:18Z","updated_at":"2018-03-02T04:46:07Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"One of the promises of early Shadow DOM (and several other Parkour-descended products) was that while we would build the first version as an imperative (JS-based) API, for flexibility and composability, we'd come in later and backfill a declarative version that made it very easy to use for common cases.  We haven't done this yet for Shadow DOM, and the spec is stable enough now that I think we can safely do it.\r\n\r\n-------\r\n\r\nRough proposal:\r\n\r\n```\r\n<div-or-something>\r\n  <template attach-shadow shadow-mode=\"open | closed\">\r\n    ...shadow content...\r\n  </template>\r\n</div-or-something>\r\n```\r\n\r\nThat is, using a `<template>` element with an `attach-shadow` attribute automatically (during parsing) attaches its contents to its parent element as a shadow root.  The mode is selected by the optional `shadow-mode` attribute; if omitted, it defaults to \"open\" (or we can make it required, like the JS API does?).\r\n\r\n-------\r\n\r\nReasoning:\r\n\r\nToday you can get something *close* to declarative with JS like:\r\n\r\n```\r\n<parent-element>\r\n</parent-element>\r\n<script>\r\n\"use strict\";\r\n\r\nconst shadowRoot = document.currentScript.previousElementSibling.attachShadow({ mode: \"open\" });\r\nshadowRoot.innerHTML = `<child-element></child-element>`;\r\n</script>\r\n```\r\n\r\nThis has several downsides:\r\n\r\n1. Doesn't work nicely with syntax highlighting.\r\n2. Doesn't work nicely with any tooling that wants to be able to output HTML.\r\n3. Doesn't nest easily. (That is, having an element in the shadow contain *another* declarative shadow.)\r\n4. Can't include `<script>` in the shadow unless you remember to do the various tricks to avoid having a literal `</script>` in the string.\r\n6. Also have to be aware of which quoting character you're using, and remember to escape it when you're writing your page.\r\n5. Including user-generated content is now more complicated; it not only needs to be escaped as safe HTML, but as safe script and string contents, too, which are decently more complex (and not, afaik, supported by the core libraries in PHP or Python).\r\n7. Lots of non-trivial typing for something intended to be easy and widespread.\r\n8. Inline script isn't compatible with safe CSP practice, unless you go the extra mile to add nonces (more effort! must use crypto safely!)\r\n9. Inline script isn't run for .mhtml archives (at least in Chrome, for historical reasons).\r\n10. Users with JS turned off won't get any page at all, for no good reason - page might have just been wanting style isolation, but is now tied to JS evaluation.\r\n11. Inline script halts the speculative parser, I think?\r\n12. Doesn't allow for server-side rendering (doing as much of the page as possible on the server, only using client-side JS for final fixups and event hookups, etc).  The page instead has to do all this work on client-side (which is apparently fairly slow, per <https://github.com/whatwg/dom/issues/510#issuecomment-329179035>)"},"comment":{"url":"https://api.github.com/repos/whatwg/dom/issues/comments/369818961","html_url":"https://github.com/whatwg/dom/issues/510#issuecomment-369818961","issue_url":"https://api.github.com/repos/whatwg/dom/issues/510","id":369818961,"user":{"login":"hayatoito","id":160288,"avatar_url":"https://avatars2.githubusercontent.com/u/160288?v=4","gravatar_id":"","url":"https://api.github.com/users/hayatoito","html_url":"https://github.com/hayatoito","followers_url":"https://api.github.com/users/hayatoito/followers","following_url":"https://api.github.com/users/hayatoito/following{/other_user}","gists_url":"https://api.github.com/users/hayatoito/gists{/gist_id}","starred_url":"https://api.github.com/users/hayatoito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hayatoito/subscriptions","organizations_url":"https://api.github.com/users/hayatoito/orgs","repos_url":"https://api.github.com/users/hayatoito/repos","events_url":"https://api.github.com/users/hayatoito/events{/privacy}","received_events_url":"https://api.github.com/users/hayatoito/received_events","type":"User","site_admin":false},"created_at":"2018-03-02T04:46:07Z","updated_at":"2018-03-02T04:46:07Z","author_association":"COLLABORATOR","body":"Google is interested in implementing the [proposal](https://github.com/w3c/webcomponents/blob/gh-pages/proposals/Declarative-Shadow-DOM.md). The general idea matches my expectation."}}
{"actor":{"display_login":"hayatoito"}}