Skip to content
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

[Lit] Forwards compatiblity for streaming Declarative Shadow DOM #6055

Merged
merged 5 commits into from
Feb 1, 2023
Merged
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
5 changes: 5 additions & 0 deletions .changeset/hip-pots-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/lit': patch
---

Add forwards compatibility for streaming Declarative Shadow DOM
6 changes: 3 additions & 3 deletions packages/astro/test/custom-elements.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Custom Elements', () => {
expect($('my-element')).to.have.lengthOf(1);

// test 2: shadow rendered
expect($('my-element template[shadowroot=open]')).to.have.lengthOf(1);
expect($('my-element template[shadowroot=open][shadowrootmode=open]')).to.have.lengthOf(1);
});

it('Works with exported tagName', async () => {
Expand All @@ -34,7 +34,7 @@ describe('Custom Elements', () => {
expect($('my-element')).to.have.lengthOf(1);

// test 2: shadow rendered
expect($('my-element template[shadowroot=open]')).to.have.lengthOf(1);
expect($('my-element template[shadowroot=open][shadowrootmode=open]')).to.have.lengthOf(1);
});

it.skip('Hydration works with exported tagName', async () => {
Expand All @@ -46,7 +46,7 @@ describe('Custom Elements', () => {
expect($('my-element')).to.have.lengthOf(1);

// test 2: shadow rendered
expect($('my-element template[shadowroot=open]')).to.have.lengthOf(1);
expect($('my-element template[shadowroot=open][shadowrootmode=open]')).to.have.lengthOf(1);

// Hydration
// test 3: Component and polyfill scripts bundled separately
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function renderToStaticMarkup(component, props, innerHTML) {
const Component = getConstructor(component);
const el = new Component();
el.connectedCallback();
const html = `<${el.localName}><template shadowroot="open">${el.shadowRoot.innerHTML}</template>${el.innerHTML}</${el.localName}>`
const html = `<${el.localName}><template shadowroot="open" shadowrootmode="open">${el.shadowRoot.innerHTML}</template>${el.innerHTML}</${el.localName}>`
return {
html
};
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/lit/client-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async function polyfill() {
}

const polyfillCheckEl = new DOMParser()
.parseFromString(`<p><template shadowroot="open"></template></p>`, 'text/html', {
.parseFromString(`<p><template shadowroot="open" shadowrootmode="open"></template></p>`, 'text/html', {
includeShadowRoots: true,
})
.querySelector('p');
Expand Down
4 changes: 2 additions & 2 deletions packages/integrations/lit/client-shim.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var b = (t, n) => {
function s() {
if (d === void 0) {
let t = document.createElement('div');
(t.innerHTML = '<div><template shadowroot="open"></template></div>'),
(t.innerHTML = '<div><template shadowroot="open" shadowrootmode="open"></template></div>'),
(d = !!t.firstElementChild.shadowRoot);
}
return d;
Expand Down Expand Up @@ -80,7 +80,7 @@ async function g() {
window.addEventListener('DOMContentLoaded', () => t(document.body), { once: true });
}
var x = new DOMParser()
.parseFromString('<p><template shadowroot="open"></template></p>', 'text/html', {
.parseFromString('<p><template shadowroot="open" shadowrootmode="open"></template></p>', 'text/html', {
includeShadowRoots: !0,
})
.querySelector('p');
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/lit/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function* render(Component, attrs, slots) {
yield `>`;
const shadowContents = instance.renderShadow({});
if (shadowContents !== undefined) {
yield '<template shadowroot="open">';
yield '<template shadowroot="open" shadowrootmode="open">';
yield* shadowContents;
yield '</template>';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/lit/test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('renderToStaticMarkup', () => {
customElements.define(tagName, class extends LitElement {});
const render = await renderToStaticMarkup(tagName);
expect(render).to.deep.equal({
html: `<${tagName}><template shadowroot="open"><!--lit-part--><!--/lit-part--></template></${tagName}>`,
html: `<${tagName}><template shadowroot="open" shadowrootmode="open"><!--lit-part--><!--/lit-part--></template></${tagName}>`,
});
});

Expand Down