From 8e6274a88a0f835da716f3dc72a461cb803e799f Mon Sep 17 00:00:00 2001 From: Erik Tiekstra Date: Wed, 4 Jun 2025 10:30:27 +0000 Subject: [PATCH] fix(SW-1960): Changes to how we handle hash inside hotelpages after Next15 upgrade Approved-by: Michael Zetterberg Approved-by: Linus Flood --- .../ContentType/HotelPage/TabNavigation/index.tsx | 14 +++++++++++--- apps/scandic-web/hooks/useHash.tsx | 15 --------------- 2 files changed, 11 insertions(+), 18 deletions(-) delete mode 100644 apps/scandic-web/hooks/useHash.tsx diff --git a/apps/scandic-web/components/ContentType/HotelPage/TabNavigation/index.tsx b/apps/scandic-web/components/ContentType/HotelPage/TabNavigation/index.tsx index 47c3172a0..edf11c1c5 100644 --- a/apps/scandic-web/components/ContentType/HotelPage/TabNavigation/index.tsx +++ b/apps/scandic-web/components/ContentType/HotelPage/TabNavigation/index.tsx @@ -3,13 +3,19 @@ import { cx } from "class-variance-authority" import NextLink from "next/link" import { useRouter } from "next/navigation" -import { useCallback, useEffect, useLayoutEffect, useMemo, useRef } from "react" +import { + useCallback, + useEffect, + useLayoutEffect, + useMemo, + useRef, + useState, +} from "react" import { Typography } from "@scandic-hotels/design-system/Typography" import { StickyElementNameEnum } from "@/stores/sticky-position" -import useHash from "@/hooks/useHash" import useScrollShadows from "@/hooks/useScrollShadows" import useScrollSpy from "@/hooks/useScrollSpy" import useStickyPosition from "@/hooks/useStickyPosition" @@ -25,7 +31,7 @@ interface TabNavigationProps { } export default function TabNavigation({ pageSections }: TabNavigationProps) { - const activeHash = useHash() + const [activeHash, setActiveHash] = useState() const router = useRouter() const tabNavigationRef = useRef(null) const tabRefs = useMemo(() => new Map(), []) @@ -80,6 +86,7 @@ export default function TabNavigation({ pageSections }: TabNavigationProps) { useEffect(() => { if (activeSectionId) { router.replace(`#${activeSectionId}`, { scroll: false }) + setActiveHash(activeSectionId) } }, [activeSectionId, router]) @@ -117,6 +124,7 @@ export default function TabNavigation({ pageSections }: TabNavigationProps) { }} onClick={() => { pauseScrollSpy() + setActiveHash(hash) trackHotelTabClick(heading) }} > diff --git a/apps/scandic-web/hooks/useHash.tsx b/apps/scandic-web/hooks/useHash.tsx deleted file mode 100644 index 5c0ab8e12..000000000 --- a/apps/scandic-web/hooks/useHash.tsx +++ /dev/null @@ -1,15 +0,0 @@ -"use client" - -import { useParams } from "next/navigation" -import { useEffect, useState } from "react" - -export default function useHash() { - const [hash, setHash] = useState(undefined) - const params = useParams() - - useEffect(() => { - setHash(window.location.hash) - }, [params]) - - return hash?.slice(1) -}