From 3066a133ac339bfbc0c1707b3c8c7af10ea2d082 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 3 Mar 2023 11:43:53 +0900 Subject: [PATCH] fix(client): prevent null reference error --- .../src/components/global/MkStickyContainer.vue | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/frontend/src/components/global/MkStickyContainer.vue b/packages/frontend/src/components/global/MkStickyContainer.vue index 3f9c1bc353..44c02088da 100644 --- a/packages/frontend/src/components/global/MkStickyContainer.vue +++ b/packages/frontend/src/components/global/MkStickyContainer.vue @@ -32,11 +32,17 @@ const parentStickyBottom = inject>(CURRENT_STICKY_BOTTOM, ref(0)); provide(CURRENT_STICKY_BOTTOM, $$(childStickyBottom)); const calc = () => { - childStickyTop = parentStickyTop.value + headerEl.offsetHeight; - headerHeight = headerEl.offsetHeight.toString(); + // コンポーネントが表示されてないけどKeepAliveで残ってる場合などは null になる + if (headerEl != null) { + childStickyTop = parentStickyTop.value + headerEl.offsetHeight; + headerHeight = headerEl.offsetHeight.toString(); + } - childStickyBottom = parentStickyBottom.value + footerEl.offsetHeight; - footerHeight = footerEl.offsetHeight.toString(); + // コンポーネントが表示されてないけどKeepAliveで残ってる場合などは null になる + if (footerEl != null) { + childStickyBottom = parentStickyBottom.value + footerEl.offsetHeight; + footerHeight = footerEl.offsetHeight.toString(); + } }; const observer = new ResizeObserver(() => {