From 467108730e4f45e4cd99779a7126b9dbd93d9ce5 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Thu, 25 Aug 2022 22:01:22 +0800 Subject: [PATCH] Remove optional chaining in astro-island (#4473) --- .changeset/olive-gifts-hope.md | 5 +++++ packages/astro/src/runtime/server/astro-island.ts | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .changeset/olive-gifts-hope.md diff --git a/.changeset/olive-gifts-hope.md b/.changeset/olive-gifts-hope.md new file mode 100644 index 0000000000..32a01c519b --- /dev/null +++ b/.changeset/olive-gifts-hope.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Remove optional chaining in astro-island diff --git a/packages/astro/src/runtime/server/astro-island.ts b/packages/astro/src/runtime/server/astro-island.ts index 2e16a547a3..706ccdd88e 100644 --- a/packages/astro/src/runtime/server/astro-island.ts +++ b/packages/astro/src/runtime/server/astro-island.ts @@ -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')