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 hydration ordering #9018

Merged
merged 2 commits into from
Nov 8, 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/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