Skip to content

Commit

Permalink
Fix lit integration nested component rendering (#6752)
Browse files Browse the repository at this point in the history
* Provide renderInfo to renderShadow

* Add test for rendering nested components

* Add changeset
  • Loading branch information
augustjk committed Apr 5, 2023
1 parent 4cc1bf6 commit c7eb0d4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/angry-hounds-train.md
@@ -0,0 +1,5 @@
---
'@astrojs/lit': patch
---

Provide `renderInfo` when rendering Lit components. Fixes issue with rendering nested components.
7 changes: 6 additions & 1 deletion packages/integrations/lit/server.js
Expand Up @@ -59,7 +59,12 @@ function* render(Component, attrs, slots) {
yield `<${tagName}${shouldDeferHydration ? ' defer-hydration' : ''}`;
yield* instance.renderAttributes();
yield `>`;
const shadowContents = instance.renderShadow({});
const shadowContents = instance.renderShadow({
elementRenderers: [LitElementRenderer],
customElementInstanceStack: [instance],
customElementHostStack: [],
deferHydration: false,
});
if (shadowContents !== undefined) {
const { mode = 'open', delegatesFocus } = instance.shadowRootOptions ?? {};
// `delegatesFocus` is intentionally allowed to coerce to boolean to
Expand Down
24 changes: 24 additions & 0 deletions packages/integrations/lit/test/server.test.js
Expand Up @@ -90,6 +90,30 @@ describe('renderToStaticMarkup', () => {
expect($(`${tagName} template`).text()).to.contain(`Hello ${prop1}`);
});

it('should render nested components', async () => {
const tagName = 'parent-component';
const childTagName = 'child-component';
customElements.define(
childTagName,
class extends LitElement {
render() {
return html`<p>child</p>`;
}
}
);
customElements.define(
tagName,
class extends LitElement {
render() {
return html`<child-component></child-component>`;
}
}
);
const render = await renderToStaticMarkup(tagName);
const $ = cheerio.load(render.html);
expect($(`${tagName} template`).text()).to.contain('child');
});

it('should render DSD attributes based on shadowRootOptions', async () => {
const tagName = 'shadow-root-options-component';
customElements.define(
Expand Down

0 comments on commit c7eb0d4

Please sign in to comment.