Skip to content

Fix for scope=global on clientside render #6

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const CustomElementMixin = (superclass) => class extends superclass {
const styles = this.parseCSS(tag.textContent)

if (scope === 'global') {
return styles
const sheet = new CSSStyleSheet();
sheet.replaceSync(tag.textContent)
return sheet
}

const rules = styles.cssRules
Expand Down
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"@web/test-runner": "^0.17.0",
"@web/test-runner-playwright": "^0.10.1",
"npm-run-all": "^4.1.5",
"playwright": "^1.36.2"
"playwright": "^1.44.0"
}
}
8 changes: 8 additions & 0 deletions test/mixin-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
const { attrs={} } = state
const { heading='default' } = attrs
return html`
<style scope="global">
h1 { color:green; }
my-element { h1 { color:blue; } }
</style>
<style>
:host {
color: red;
Expand Down Expand Up @@ -65,6 +69,10 @@ <h1>${heading}</h1>
const textContent = testComponent.querySelector('h1').textContent
assert.equal(textContent, 'one', 'Should expand template with heading')

const heading = testComponent.querySelector('h1')
const textColor = window.getComputedStyle(heading).color
assert.equal(textColor, 'rgb(0, 0, 255)', 'global nested styles made it');

const testComponentTwo = document.querySelector('my-element[heading="two"]')
const textContentTwo = testComponentTwo.querySelector('h1').textContent
assert.equal(textContentTwo, 'two', 'Should expand template with heading')
Expand Down
Loading