Skip to content

Commit

Permalink
Fix Lit integration hydration ordering (#9018)
Browse files Browse the repository at this point in the history
* Provide renderer instance to `customElementHostStack`

* Add changeset
  • Loading branch information
augustjk authored Nov 8, 2023
1 parent 3c17b59 commit 23c9a30
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/spotty-rings-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/lit': patch
---

Fix hydration ordering of nested custom elements. Child components will now wait for their parents to hydrate before hydrating themselves.
2 changes: 1 addition & 1 deletion packages/integrations/lit/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function* render(Component, attrs, slots) {
const shadowContents = instance.renderShadow({
elementRenderers: [LitElementRenderer],
customElementInstanceStack: [instance],
customElementHostStack: [],
customElementHostStack: [instance],
deferHydration: false,
});
if (shadowContents !== undefined) {
Expand Down
3 changes: 3 additions & 0 deletions packages/integrations/lit/test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ describe('renderToStaticMarkup', () => {
const render = await renderToStaticMarkup(tagName);
const $ = cheerio.load(render.html);
expect($(`${tagName} template`).text()).to.contain('child');
// Child component should have `defer-hydration` attribute so it'll only
// hydrate after the parent hydrates
expect($(childTagName).attr('defer-hydration')).to.equal('');
});

it('should render DSD attributes based on shadowRootOptions', async () => {
Expand Down

0 comments on commit 23c9a30

Please sign in to comment.