Skip to content

Commit 3934f6c

Browse files
authored
Fix sentry error with cookiebot #3862 (#3874)
* WIP next-root * Fix Type #3862 * Fix typo #3862 * Make the layout static to see if it flashes #3862 * Right way #3862 * Fix build #3862 * Duplicate script #3862
1 parent cc079d7 commit 3934f6c

16 files changed

Lines changed: 531 additions & 363 deletions

File tree

web/app/[locale]/(pages)/[...slug]/page.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Metadata } from 'next'
44
import dynamic from 'next/dynamic'
55
import { draftMode } from 'next/headers'
66
import { notFound } from 'next/navigation'
7-
import { setRequestLocale } from 'next-intl/server'
7+
import { locale as rootLocale } from 'next/root-params'
88
import { getValidLanguagesLocales } from '@/languageConfig'
99
import { decodeSlugs } from '@/lib/helpers/getFullUrl'
1010
import { Flags } from '@/sanity/helpers/datasetHelpers'
@@ -30,12 +30,12 @@ const NewsPage = dynamic(() => import('@/templates/news/News'))
3030
const TopicPage = dynamic(() => import('@/templates/topic/TopicPage'))
3131
const MagazineRoom = dynamic(() => import('@/templates/magazine/Magazineroom'))
3232

33-
export async function generateMetadata({ params }: Props): Promise<Metadata> {
33+
export async function generateMetadata({
34+
params,
35+
}: PageProps<'/[locale]/[...slug]'>): Promise<Metadata> {
3436
//array, separated by /. e.g. [news, last slug]
35-
const { slug: encodedSlug, locale } = await params
36-
37-
if (!getValidLanguagesLocales().includes(locale)) notFound()
38-
37+
const { slug: encodedSlug } = await params
38+
const locale = await rootLocale()
3939
const slug = decodeSlugs(encodedSlug) as string[]
4040

4141
const sanityLang = getNameFromIso(locale)
@@ -80,10 +80,6 @@ export default async function Page({ params, searchParams }: Props) {
8080
/* const isInPresentationToolContext =
8181
(await cookies()).get('preview-fetch-dest')?.value === 'iframe' */
8282
const { isEnabled: isDraftMode } = await draftMode()
83-
84-
if (!getValidLanguagesLocales().includes(locale)) notFound()
85-
86-
setRequestLocale(locale)
8783
let pageContent = null
8884
const [siteMenuResult, pageResults] = await Promise.all([
8985
routeSanityFetch({
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
1-
import { notFound } from 'next/navigation'
2-
import { hasLocale } from 'next-intl'
3-
import { setRequestLocale } from 'next-intl/server'
4-
import { routing } from '@/i18n/routing'
51
import { FriendlyCaptchaSdkWrapper } from '../FriendlyCaptchaWrapper'
62

7-
type Params = Promise<{ locale: string }>
8-
9-
export default async function PagesLayout({
3+
export default function PagesLayout({
104
children,
11-
params,
125
}: {
136
children: React.ReactNode
14-
params: Params
157
}) {
16-
const { locale } = await params
17-
18-
setRequestLocale(locale)
19-
20-
if (!hasLocale(routing.locales, locale)) {
21-
notFound()
22-
}
23-
248
return <FriendlyCaptchaSdkWrapper>{children}</FriendlyCaptchaSdkWrapper>
259
}

web/app/[locale]/(pages)/news/archive/[...slug]/layout.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
import { notFound } from 'next/navigation'
2-
import { hasLocale } from 'next-intl'
3-
import { routing } from '@/i18n/routing'
42
import { Flags } from '@/sanity/helpers/datasetHelpers'
5-
6-
type Params = Promise<{ locale: string; slug: string[] }>
7-
83
export default async function LocaleLayout({
94
children,
10-
params,
11-
}: {
12-
children: React.ReactNode
13-
params: Params
14-
}) {
15-
// Ensure that the incoming `locale` is valid
16-
const { locale } = await params
17-
18-
if (!hasLocale(routing.locales, locale) || !Flags.HAS_ARCHIVED_NEWS) {
5+
}: LayoutProps<'/[locale]/news/archive/[...slug]'>) {
6+
if (!Flags.HAS_ARCHIVED_NEWS) {
197
notFound()
208
}
219

web/app/[locale]/(pages)/news/page.tsx

Lines changed: 42 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { algoliasearch } from 'algoliasearch'
33
import type { Metadata } from 'next'
44
import { unstable_cache } from 'next/cache'
55
import dynamic from 'next/dynamic'
6-
import { setRequestLocale } from 'next-intl/server'
6+
import { notFound } from 'next/navigation'
7+
import { locale as rootLocale } from 'next/root-params'
78
import { algolia } from '@/lib/config'
89
import { Flags } from '@/sanity/helpers/datasetHelpers'
910
import { getNameFromIso } from '@/sanity/helpers/localization'
@@ -17,19 +18,8 @@ import NewsRoomTemplate from '@/templates/newsroom/Newsroom'
1718

1819
const TopicPage = dynamic(() => import('@/templates/topic/TopicPage'))
1920

20-
export async function generateStaticParams() {
21-
if (Flags.HAS_NEWSROOM) {
22-
return [{ locale: 'en-GB' }]
23-
}
24-
return []
25-
}
26-
27-
export async function generateMetadata({
28-
params,
29-
}: {
30-
params: Promise<{ locale: string }>
31-
}): Promise<Metadata> {
32-
const { locale } = await params
21+
export async function generateMetadata(): Promise<Metadata> {
22+
const locale = await rootLocale()
3323
const pageSlug = newsSlug[getNameFromIso(locale)]
3424
if (Flags.HAS_NEWSROOM) {
3525
const { data: metaData }: { data: any } = await routeSanityFetch({
@@ -47,48 +37,41 @@ export async function generateMetadata({
4737
return constructSanityMetadata(pageSlug, locale, undefined)
4838
}
4939

50-
const getInitialResponse = unstable_cache(
51-
// this gets revalidated by path
52-
async (locale: string) => {
53-
const envPrefix = Flags.IS_GLOBAL_PROD ? 'prod' : 'dev'
54-
const indexName = `${envPrefix}_NEWS_${locale}`
40+
export default async function NewsroomPage(_: PageProps<'/[locale]/news'>) {
41+
const locale = await rootLocale()
5542

56-
console.log(
57-
new Date(),
58-
'Fetching initial response for',
59-
indexName,
60-
'after revalidation',
61-
)
62-
const searchClient = algoliasearch(
63-
algolia.applicationId,
64-
algolia.searchApiKey,
65-
)
66-
const response = await searchClient.searchSingleIndex({
67-
indexName: indexName,
68-
searchParams: {
69-
hitsPerPage: 50,
70-
facetFilters: ['type:news', 'topicTags:-Crude Oil Assays'],
71-
facetingAfterDistinct: true,
72-
facets: ['countryTags', 'topicTags', 'year'],
73-
},
74-
})
75-
return response
76-
},
77-
undefined,
78-
{
79-
tags: [`newsroom_en-GB`],
80-
},
81-
)
82-
83-
export default async function NewsroomPage({
84-
params,
85-
}: {
86-
params: Promise<{ slug: string; locale: string }>
87-
}) {
88-
const { locale, slug } = await params
89-
// Enable static rendering
90-
setRequestLocale(locale)
43+
const getInitialResponse = unstable_cache(
44+
// this gets revalidated by path
45+
async () => {
46+
const envPrefix = Flags.IS_GLOBAL_PROD ? 'prod' : 'dev'
47+
const indexName = `${envPrefix}_NEWS_${locale}`
9148

49+
console.log(
50+
new Date(),
51+
'Fetching initial response for',
52+
indexName,
53+
'after revalidation',
54+
)
55+
const searchClient = algoliasearch(
56+
algolia.applicationId,
57+
algolia.searchApiKey,
58+
)
59+
const response = await searchClient.searchSingleIndex({
60+
indexName: indexName,
61+
searchParams: {
62+
hitsPerPage: 50,
63+
facetFilters: ['type:news', 'topicTags:-Crude Oil Assays'],
64+
facetingAfterDistinct: true,
65+
facets: ['countryTags', 'topicTags', 'year'],
66+
},
67+
})
68+
return response
69+
},
70+
undefined,
71+
{
72+
tags: [`newsroom`, await locale],
73+
},
74+
)
9275
const [siteMenuResult, pageResults] = await Promise.all([
9376
routeSanityFetch({
9477
query: Flags.HAS_FANCY_MENU ? globalMenuQuery : simpleMenuQuery,
@@ -97,7 +80,7 @@ export default async function NewsroomPage({
9780
},
9881
}),
9982
getPage({
100-
slug: slug ?? newsSlug[getNameFromIso(locale)],
83+
slug: newsSlug[getNameFromIso(locale)],
10184
locale,
10285
tags: ['newsroom'],
10386
}),
@@ -106,9 +89,10 @@ export default async function NewsroomPage({
10689
const { headerData, pageData } = pageResults
10790
const { data: siteMenuData } = siteMenuResult || {}
10891

109-
const response = Flags.HAS_NEWSROOM
110-
? await getInitialResponse(locale)
111-
: undefined
92+
const response =
93+
Flags.HAS_NEWSROOM && locale in ['en-GB', 'nb-NO']
94+
? await getInitialResponse()
95+
: undefined
11296

11397
return (
11498
<>

web/app/[locale]/(pages)/nyheter/page.tsx

Lines changed: 0 additions & 123 deletions
This file was deleted.

0 commit comments

Comments
 (0)