This came up on a recent Chromium bug. Currently adopting a shadow root with non-empty adoptedStyleSheets into a <template> document will clear the adoptedStyleSheets, and vice versa.
Say we have a Document X and it has a <template> element in it. The <template>'s contents' node document is the Document's associated-inert-template-document. This is a different Document than X, and adopting into or out of the <template>'s contents will clear the adoptedStyleSheets per our spec).
Maybe it's ok if we treat a Document and its associated-inert-template-document as the same document for adoptedStyleSheets related purposes, by adding a special case to the "adopting steps" to not clear adoptedStyleSheets if:
And I think the constructor document will never be an associated-inert-template-document itself because that document is inert and shouldn't be able to construct stylesheets via script, but I might be wrong.
The main reasons we disallowed reusing constructed stylesheets on different documents are the concern that a constructed stylesheet from a document might keep the document alive, and different documents might have different fetch groups. I think this should be ok with the new addition. The <template>'s contents lifetime should be bounded by the document it is in, unless it gets adopted to a different document, in which case the adoptedStyleSheets will be cleared.
This came up on a recent Chromium bug. Currently adopting a shadow root with non-empty
adoptedStyleSheetsinto a<template>document will clear theadoptedStyleSheets, and vice versa.Say we have a
DocumentX and it has a<template>element in it. The<template>'s contents' node document is theDocument's associated-inert-template-document. This is a differentDocumentthan X, and adopting into or out of the<template>'s contents will clear theadoptedStyleSheetsper our spec).Maybe it's ok if we treat a
Documentand its associated-inert-template-document as the same document foradoptedStyleSheetsrelated purposes, by adding a special case to the "adopting steps" to not clearadoptedStyleSheetsif:And I think the constructor document will never be an associated-inert-template-document itself because that document is inert and shouldn't be able to construct stylesheets via script, but I might be wrong.
The main reasons we disallowed reusing constructed stylesheets on different documents are the concern that a constructed stylesheet from a document might keep the document alive, and different documents might have different fetch groups. I think this should be ok with the new addition. The
<template>'s contents lifetime should be bounded by the document it is in, unless it gets adopted to a different document, in which case theadoptedStyleSheetswill be cleared.