Open firelizzard18 opened 7 years ago
From stack overflow:
I seem to have things working. I patched aurelia/templating-resources/css-resource.js
:
beforeCompile(content: DocumentFragment, resources: ViewResources, instruction: ViewCompileInstruction): void {
+ if (this.done) {
+ return
+ } else {
+ this.done = true
+ }
if (instruction.targetShadowDOM) {
DOM.injectStyles(this.css, content, true);
} else if (FEATURE.scopedCSS) {
let styleNode = DOM.injectStyles(this.css, content, true);
styleNode.setAttribute('scoped', 'scoped');
} else if (!this.owner._alreadyGloballyInjected) {
DOM.injectStyles(this.css);
this.owner._alreadyGloballyInjected = true;
}
}
I have been running with this patch for a week plus and nothing weird has happened.
I wish all issues were this thorough!
I'm submitting a bug report
From stack overflow by request of @AshleyGrant.
^2.0.1
1.0.8
Please tell us about your environment:
Operating System: Windows 10
Node Version: 7.7.3
NPM Version: 4.1.2
JSPM JSPM 0.17.0-beta.42
Browser: Chrome 59 (no other supported browser supports Shadow DOM)
Language: ESNext
Current behavior: Shadow DOM scoped CSS includes are injected into the shadow root and into
<head>
.Expected/desired behavior: Shadow DOM scoped CSS includes are injected only into the shadow root.
From Stack Overflow: In my aurelia application, one of my custom elements
panel
(shadow DOM) includes another custom elementwidget
(shadow DOM) that has a custom attributeown-attribute
(template controller) on it.panel
has a scoped stylesheet (<require from="./panel.css" as="scoped"></require>
). While compiling, aurelia correctly injects./panel.css
into the shadow root ofpanel
. However, in a separate step, while compilingown-context
onwidget
withinpanel
, aurelia injects./panel.css
into<head>
, thus breaking the abstraction of custom element stylesheets and generally playing havoc with my app.How do I fix this?
I tried making a plunker here but it doesn't work. I'm using ES2017 so that makes life more complicated.
panel
is being compiled byViewCompiler.compile()
ViewCompiler._compileNode()
widget
ViewCompiler._compileElement()
onwidget
own-context
as a "lifting instruction" and callsHtmlBehaviorResource.compile()
ViewCompiler.compile()
onwidget
beforeCompile
invokeHook
,CSSViewEngineHooks.beforeCompile()
, is called, which injects a bunch of styles into<head>
This is an issue.
HtmlBehaviorResource.compile()
's call toViewResource.compile()
does not pass a compile instruction, so the latter uses the default. Thus the CSS hooks don't get the message that they should be injecting into the shadow root. Not to mention this is double-injecting these styles for no good reason.panel.js
panel.html
widget.js
widget.html
own-context.js