0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Remove optional chaining in astro-island (#4473)

This commit is contained in:
Bjorn Lu 2022-08-25 22:01:22 +08:00 committed by GitHub
parent 8a2d6958f1
commit 467108730e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Remove optional chaining in astro-island

View file

@ -90,7 +90,10 @@ declare const Astro: {
);
}
hydrate = () => {
if (!this.hydrator || this.parentElement?.closest('astro-island[ssr]')) {
if (
!this.hydrator ||
(this.parentElement && this.parentElement.closest('astro-island[ssr]'))
) {
return;
}
const slotted = this.querySelectorAll('astro-slot');
@ -99,12 +102,14 @@ declare const Astro: {
// This happens if slots were passed but the client component did not render them.
const templates = this.querySelectorAll('template[data-astro-template]');
for (const template of templates) {
if (!template.closest(this.tagName)?.isSameNode(this)) continue;
const closest = template.closest(this.tagName);
if (!closest || !closest.isSameNode(this)) continue;
slots[template.getAttribute('data-astro-template') || 'default'] = template.innerHTML;
template.remove();
}
for (const slot of slotted) {
if (!slot.closest(this.tagName)?.isSameNode(this)) continue;
const closest = slot.closest(this.tagName);
if (!closest || !closest.isSameNode(this)) continue;
slots[slot.getAttribute('name') || 'default'] = slot.innerHTML;
}
const props = this.hasAttribute('props')