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

Fix lit integration nested component rendering #6752

Merged
merged 3 commits into from
Apr 5, 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/angry-hounds-train.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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