From 9e8532a2f43c73a569123b98a9c31b8fe1940f2f Mon Sep 17 00:00:00 2001 From: Martin Trapp <94928215+martrapp@users.noreply.github.com> Date: Tue, 2 Apr 2024 21:05:01 +0200 Subject: [PATCH] Fix NPE (#59) --- .changeset/tidy-pots-turn.md | 5 +++++ components/starlight/StarlightConnector.astro | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 .changeset/tidy-pots-turn.md diff --git a/.changeset/tidy-pots-turn.md b/.changeset/tidy-pots-turn.md new file mode 100644 index 0000000..f1475cf --- /dev/null +++ b/.changeset/tidy-pots-turn.md @@ -0,0 +1,5 @@ +--- +"astro-vtbot": patch +--- + +Fixes a bug accessing an attribute of null when linking to view transition pages outside the starlight site. diff --git a/components/starlight/StarlightConnector.astro b/components/starlight/StarlightConnector.astro index 77400d7..4225986 100644 --- a/components/starlight/StarlightConnector.astro +++ b/components/starlight/StarlightConnector.astro @@ -17,9 +17,7 @@ export interface Props {} function closeMobileMenu() { if (document.body.hasAttribute('data-mobile-menu-expanded')) { document.body - .querySelector('starlight-menu-button')! - .closest('nav')! - .dispatchEvent( + .querySelector('starlight-menu-button')?.closest('nav')?.dispatchEvent( new KeyboardEvent('keyup', { key: 'Escape', code: 'Escape', @@ -35,7 +33,7 @@ export interface Props {} } function markMainFrameForReplacementSwap(doc: Document) { - doc.body.querySelector('div.main-frame')!.setAttribute('data-vtbot-replace', 'main'); + doc.body.querySelector('div.main-frame')?.setAttribute('data-vtbot-replace', 'main'); } function setTransitionScope(e: TransitionBeforePreparationEvent) {