Skip to content

Commit

Permalink
feat: experimental fastboot support
Browse files Browse the repository at this point in the history
Only works in Chrome 85+ with an experimental flag, see https://web.dev/declarative-shadow-dom/
  • Loading branch information
knownasilya committed Oct 4, 2020
1 parent 5523254 commit d9ea3e1
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 72 deletions.
5 changes: 4 additions & 1 deletion addon/components/shadow-dom/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';

const isFastBoot = typeof FastBoot !== 'undefined';

export default class ShadowDom extends Component {
@tracked shadow = null;
@tracked tagName = 'div';

defaultMode = 'open';
isFastBoot = isFastBoot;

constructor() {
super(...arguments);
Expand All @@ -18,6 +21,6 @@ export default class ShadowDom extends Component {
let mode = this.args.mode || this.defaultMode;
let shadow = element.attachShadow({ mode });

this.shadow = shadow;
this.shadow = shadow;
}
}
26 changes: 16 additions & 10 deletions app/templates/components/shadow-dom.hbs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{{#let (element this.tagName) as |Tag|}}
<Tag
{{did-insert this.setupRoot}}
...attributes
/>
{{/let}}
{{#if this.isFastBoot}}
<Tag ...attributes>
<template shadowroot={{@mode}}>
<slot></slot>
</template>
{{yield}}
</Tag>
{{else}}
<Tag ...attributes {{did-insert this.setupRoot}} />

{{#if this.shadow}}
{{#-in-element this.shadow}}
{{yield}}
{{/-in-element}}
{{/if}}
{{#if this.shadow}}
{{#-in-element this.shadow}}
{{yield}}
{{/-in-element}}
{{/if}}
{{/if}}
{{/let}}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@
"release": "standard-version"
},
"dependencies": {
"@ember/render-modifiers": "^1.0.0",
"@ember/render-modifiers": "^1.0.2",
"@glimmer/component": "^1.0.0",
"@glimmer/tracking": "^1.0.1",
"ember-cli-babel": "^7.22.1",
"ember-cli-htmlbars": "^5.3.1",
"ember-element-helper": "^0.3.1"
},
"devDependencies": {
"@ember/optional-features": "^2.0.0",
"@glimmer/component": "^1.0.1",
"@glimmer/tracking": "^1.0.1",
"babel-eslint": "^10.1.0",
"broccoli-asset-rev": "^3.0.0",
"ember-auto-import": "^1.6.0",
"ember-cli": "^3.21.2",
"ember-cli-app-version": "^3.2.0",
"ember-cli-dependency-checker": "^3.2.0",
"ember-cli-fastboot": "^2.2.3",
"ember-cli-inject-live-reload": "^2.0.2",
"ember-cli-sri": "^2.1.1",
"ember-cli-terser": "^4.0.0",
Expand Down

0 comments on commit d9ea3e1

Please sign in to comment.