fix(SW-3075): Fixed issue where URLs rendered differently in source HTML in compared to client
Approved-by: Matilda Landström
This commit is contained in:
@@ -12,6 +12,7 @@ import Breadcrumbs from "@/components/Breadcrumbs"
|
|||||||
import BreadcrumbsSkeleton from "@/components/TempDesignSystem/Breadcrumbs/BreadcrumbsSkeleton"
|
import BreadcrumbsSkeleton from "@/components/TempDesignSystem/Breadcrumbs/BreadcrumbsSkeleton"
|
||||||
import { getIntl } from "@/i18n"
|
import { getIntl } from "@/i18n"
|
||||||
import DestinationDataProvider from "@/providers/DestinationDataProvider"
|
import DestinationDataProvider from "@/providers/DestinationDataProvider"
|
||||||
|
import { getPathname } from "@/utils/getPathname"
|
||||||
|
|
||||||
import Blocks from "../Blocks"
|
import Blocks from "../Blocks"
|
||||||
import ExperienceList from "../ExperienceList"
|
import ExperienceList from "../ExperienceList"
|
||||||
@@ -40,6 +41,7 @@ export default async function DestinationCityPage({
|
|||||||
filterFromUrl,
|
filterFromUrl,
|
||||||
}: DestinationCityPageProps) {
|
}: DestinationCityPageProps) {
|
||||||
const intl = await getIntl()
|
const intl = await getIntl()
|
||||||
|
const pathname = await getPathname()
|
||||||
const pageData = await getDestinationCityPage()
|
const pageData = await getDestinationCityPage()
|
||||||
|
|
||||||
if (!pageData) {
|
if (!pageData) {
|
||||||
@@ -90,6 +92,7 @@ export default async function DestinationCityPage({
|
|||||||
allFilters={allFilters}
|
allFilters={allFilters}
|
||||||
filterFromUrl={filterFromUrl}
|
filterFromUrl={filterFromUrl}
|
||||||
sortItems={sortItems}
|
sortItems={sortItems}
|
||||||
|
pathname={pathname}
|
||||||
>
|
>
|
||||||
{isMapView ? (
|
{isMapView ? (
|
||||||
<CityMap
|
<CityMap
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import Breadcrumbs from "@/components/Breadcrumbs"
|
|||||||
import BreadcrumbsSkeleton from "@/components/TempDesignSystem/Breadcrumbs/BreadcrumbsSkeleton"
|
import BreadcrumbsSkeleton from "@/components/TempDesignSystem/Breadcrumbs/BreadcrumbsSkeleton"
|
||||||
import { getIntl } from "@/i18n"
|
import { getIntl } from "@/i18n"
|
||||||
import DestinationDataProvider from "@/providers/DestinationDataProvider"
|
import DestinationDataProvider from "@/providers/DestinationDataProvider"
|
||||||
|
import { getPathname } from "@/utils/getPathname"
|
||||||
|
|
||||||
import Blocks from "../Blocks"
|
import Blocks from "../Blocks"
|
||||||
import CityListing from "../CityListing"
|
import CityListing from "../CityListing"
|
||||||
@@ -40,6 +41,7 @@ export default async function DestinationCountryPage({
|
|||||||
filterFromUrl,
|
filterFromUrl,
|
||||||
}: DestinationCountryPageProps) {
|
}: DestinationCountryPageProps) {
|
||||||
const intl = await getIntl()
|
const intl = await getIntl()
|
||||||
|
const pathname = await getPathname()
|
||||||
const pageData = await getDestinationCountryPage()
|
const pageData = await getDestinationCountryPage()
|
||||||
|
|
||||||
if (!pageData) {
|
if (!pageData) {
|
||||||
@@ -89,6 +91,7 @@ export default async function DestinationCountryPage({
|
|||||||
allFilters={allFilters}
|
allFilters={allFilters}
|
||||||
filterFromUrl={filterFromUrl}
|
filterFromUrl={filterFromUrl}
|
||||||
sortItems={sortItems}
|
sortItems={sortItems}
|
||||||
|
pathname={pathname}
|
||||||
>
|
>
|
||||||
{isMapView ? (
|
{isMapView ? (
|
||||||
<CountryMap
|
<CountryMap
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
"use client"
|
"use client"
|
||||||
import { usePathname, useSearchParams } from "next/navigation"
|
import { useSearchParams } from "next/navigation"
|
||||||
import { useRef } from "react"
|
import { useRef } from "react"
|
||||||
|
|
||||||
import { createDestinationDataStore } from "@/stores/destination-data"
|
import { createDestinationDataStore } from "@/stores/destination-data"
|
||||||
@@ -17,10 +17,10 @@ export default function DestinationDataProvider({
|
|||||||
allFilters,
|
allFilters,
|
||||||
filterFromUrl,
|
filterFromUrl,
|
||||||
sortItems,
|
sortItems,
|
||||||
|
pathname,
|
||||||
children,
|
children,
|
||||||
}: DestinationDataProviderProps) {
|
}: DestinationDataProviderProps) {
|
||||||
const storeRef = useRef<DestinationDataStore>(undefined)
|
const storeRef = useRef<DestinationDataStore>(undefined)
|
||||||
const pathname = usePathname()
|
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
|
|
||||||
if (!storeRef.current) {
|
if (!storeRef.current) {
|
||||||
|
|||||||
@@ -47,6 +47,15 @@ const CITY_SORTING_STRATEGIES: Partial<
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sortFilters(filters: Filter[]): Filter[] {
|
||||||
|
return [...filters].sort((a, b) => {
|
||||||
|
// First sort by sortOrder
|
||||||
|
const orderDiff = a.sortOrder - b.sortOrder
|
||||||
|
// If sortOrder is the same, sort by name as secondary criterion
|
||||||
|
return orderDiff === 0 ? a.name.localeCompare(b.name) : orderDiff
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function getFilteredHotels(
|
export function getFilteredHotels(
|
||||||
hotels: DestinationPagesHotelData[],
|
hotels: DestinationPagesHotelData[],
|
||||||
filters: string[]
|
filters: string[]
|
||||||
@@ -125,10 +134,7 @@ export function getFiltersFromHotels(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const filters = hotels.flatMap(({ hotel }) => hotel.detailedFacilities)
|
const filters = hotels.flatMap(({ hotel }) => hotel.detailedFacilities)
|
||||||
const sortedFilters = filters.sort((a, b) => b.sortOrder - a.sortOrder)
|
const uniqueFilterNames = [...new Set(filters.map((filter) => filter.name))]
|
||||||
const uniqueFilterNames = [
|
|
||||||
...new Set(sortedFilters.map((filter) => filter.name)),
|
|
||||||
]
|
|
||||||
const filterList = uniqueFilterNames
|
const filterList = uniqueFilterNames
|
||||||
.map((filterName) => {
|
.map((filterName) => {
|
||||||
const filter = filters.find((filter) => filter.name === filterName)
|
const filter = filters.find((filter) => filter.name === filterName)
|
||||||
@@ -137,18 +143,21 @@ export function getFiltersFromHotels(
|
|||||||
name: filter.name,
|
name: filter.name,
|
||||||
slug: filter.slug,
|
slug: filter.slug,
|
||||||
filterType: filter.filter,
|
filterType: filter.filter,
|
||||||
|
sortOrder: filter.sortOrder,
|
||||||
}
|
}
|
||||||
: null
|
: null
|
||||||
})
|
})
|
||||||
.filter((filter): filter is Filter => !!filter)
|
.filter((filter): filter is Filter => !!filter)
|
||||||
|
|
||||||
|
const facilityFilters = filterList.filter((filter) =>
|
||||||
|
HOTEL_FACILITIES_FILTER_TYPE_NAMES.includes(filter.filterType)
|
||||||
|
)
|
||||||
|
const surroundingsFilters = filterList.filter((filter) =>
|
||||||
|
HOTEL_SURROUNDINGS_FILTER_TYPE_NAMES.includes(filter.filterType)
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
facilityFilters: filterList.filter((filter) =>
|
facilityFilters: sortFilters(facilityFilters),
|
||||||
HOTEL_FACILITIES_FILTER_TYPE_NAMES.includes(filter.filterType)
|
surroundingsFilters: sortFilters(surroundingsFilters),
|
||||||
),
|
|
||||||
surroundingsFilters: filterList.filter((filter) =>
|
|
||||||
HOTEL_SURROUNDINGS_FILTER_TYPE_NAMES.includes(filter.filterType)
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export interface Filter {
|
|||||||
name: string
|
name: string
|
||||||
slug: string
|
slug: string
|
||||||
filterType: string
|
filterType: string
|
||||||
|
sortOrder: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CategorizedFilters {
|
export interface CategorizedFilters {
|
||||||
|
|||||||
@@ -11,4 +11,5 @@ export interface DestinationDataProviderProps extends React.PropsWithChildren {
|
|||||||
allFilters: CategorizedFilters
|
allFilters: CategorizedFilters
|
||||||
filterFromUrl?: string
|
filterFromUrl?: string
|
||||||
sortItems: SortItem[]
|
sortItems: SortItem[]
|
||||||
|
pathname: string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
import { headers } from "next/headers"
|
import { getPathname } from "./getPathname"
|
||||||
|
|
||||||
import { getLang } from "@/i18n/serverContext"
|
|
||||||
|
|
||||||
export async function appendSlugToPathname(slug?: string) {
|
export async function appendSlugToPathname(slug?: string) {
|
||||||
const headersList = await headers()
|
const pathname = await getPathname()
|
||||||
const pathname = headersList.get("x-pathname")
|
|
||||||
const lang = await getLang()
|
|
||||||
|
|
||||||
if (!pathname || !slug) {
|
if (!slug) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return `/${lang}${pathname}/${slug}`
|
return `${pathname}/${slug}`
|
||||||
}
|
}
|
||||||
|
|||||||
11
apps/scandic-web/utils/getPathname.ts
Normal file
11
apps/scandic-web/utils/getPathname.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { headers } from "next/headers"
|
||||||
|
|
||||||
|
import { getLang } from "@/i18n/serverContext"
|
||||||
|
|
||||||
|
export async function getPathname() {
|
||||||
|
const headersList = await headers()
|
||||||
|
const lang = await getLang()
|
||||||
|
const pathname = headersList.get("x-pathname") || ""
|
||||||
|
|
||||||
|
return `/${lang}${pathname}`
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user