From b6f1ba6db87bedd001e6f05a9a0c3d2b614c77d0 Mon Sep 17 00:00:00 2001 From: Borghild Date: Wed, 7 Feb 2024 09:19:59 +0100 Subject: [PATCH 1/3] :art: Improve performance --- sanityv3/schemas/documents/route.tsx | 7 +++++ sanityv3/schemas/documents/routeHomepage.tsx | 6 ++++ web/common/helpers/getPaths.ts | 30 +++++++++++++++++++ web/components/src/Link/ButtonLink.tsx | 2 +- web/components/src/Link/Link.tsx | 1 + web/next.config.js | 10 +++++++ .../pageTemplates/newsroom/Hit.tsx | 2 +- web/pageComponents/shared/Footer.tsx | 2 +- web/pageComponents/shared/Header.tsx | 4 +-- .../shared/Hero/LoopingVideo.tsx | 13 ++++++-- .../shared/LocalizationSwitch.tsx | 2 +- web/pageComponents/shared/LogoLink.tsx | 2 +- web/pageComponents/shared/VideoPlayer.tsx | 14 +++++++-- web/pageComponents/topicPages/Breadcrumbs.tsx | 4 ++- .../topicPages/FullWidthVideo.tsx | 14 +++++++-- web/pages/[[...slug]].tsx | 5 ++-- 16 files changed, 102 insertions(+), 16 deletions(-) diff --git a/sanityv3/schemas/documents/route.tsx b/sanityv3/schemas/documents/route.tsx index 48594c9a9..e4a0a0f7b 100644 --- a/sanityv3/schemas/documents/route.tsx +++ b/sanityv3/schemas/documents/route.tsx @@ -118,6 +118,13 @@ export default (isoCode: string, title: string) => { type: 'excludeFromSearch', name: 'excludeFromSearch', }, + { + type: 'boolean', + name: 'includeInBuild', + title: 'Include in static build', + description: 'Enable this if this route should be generated at build time', + initialValue: false, + }, ], preview: { select: { diff --git a/sanityv3/schemas/documents/routeHomepage.tsx b/sanityv3/schemas/documents/routeHomepage.tsx index 9d354fa59..3e6b743c1 100644 --- a/sanityv3/schemas/documents/routeHomepage.tsx +++ b/sanityv3/schemas/documents/routeHomepage.tsx @@ -34,7 +34,13 @@ export default (isoCode: string, title: string) => ({ readOnly: true, initialValue: { current: '/', _type: 'slug' }, }, + { + name: 'includeInBuild', + type: 'boolean', + initialValue: true, + }, ], + preview: { select: { title: 'content.title', diff --git a/web/common/helpers/getPaths.ts b/web/common/helpers/getPaths.ts index 683c48796..b023fd7ad 100644 --- a/web/common/helpers/getPaths.ts +++ b/web/common/helpers/getPaths.ts @@ -26,6 +26,23 @@ const getTopicRoutesForLocale = async (locale: string) => { ) return data } +const getTopicRoutesForLocaleToStaticallyBuild = async (locale: string) => { + const lang = getNameFromLocale(locale) + // Empty array as fallback for satelittes + const blacklist = topicSlugBlackList[lang as keyof typeof topicSlugBlackList] || [] + const data: { slug: string; _updatedAt: string }[] = await sanityClient.fetch( + groq`*[_type match "route_" + $lang + "*" && (!(slug.current in $blacklist)) && includeInBuild && defined(slug.current) && !(_id in path("drafts.**"))][] { + _updatedAt, + "slug": slug.current, + }`, + { + lang, + blacklist, + }, + ) + console.log('data', data) + return data +} const getDocumentsForLocale = async (type: 'news' | 'localNews' | 'magazine', locale: string) => { const lang = getNameFromLocale(locale) @@ -64,6 +81,19 @@ export type PathType = { locale: string } +export const getStaticBuildRoutePaths = async (locales: string[]): Promise => { + const fetchPaths = locales.map(async (locale) => { + const pages = await getTopicRoutesForLocaleToStaticallyBuild(locale) + return pages.map((page) => ({ + slug: page.slug.split('/').filter((p) => p), + updatedAt: page._updatedAt, + locale, + })) + }) + + return (await Promise.all(fetchPaths)).flat() +} + export const getRoutePaths = async (locales: string[]): Promise => { const fetchPaths = locales.map(async (locale) => { const pages = await getTopicRoutesForLocale(locale) diff --git a/web/components/src/Link/ButtonLink.tsx b/web/components/src/Link/ButtonLink.tsx index c49975730..db6b77653 100644 --- a/web/components/src/Link/ButtonLink.tsx +++ b/web/components/src/Link/ButtonLink.tsx @@ -29,7 +29,7 @@ export const ButtonLink = forwardRef(functio ref, ) { return ( - + {children} diff --git a/web/components/src/Link/Link.tsx b/web/components/src/Link/Link.tsx index f52a16ce1..b50eb9e8f 100644 --- a/web/components/src/Link/Link.tsx +++ b/web/components/src/Link/Link.tsx @@ -140,6 +140,7 @@ export const Link = forwardRef(function Link( } as CSSProperties } $textDecoration={underline ? 'underline' : 'none'} + prefetch={false} {...rest} > {children} {type === 'externalUrl' ? : null} diff --git a/web/next.config.js b/web/next.config.js index 4ee5544a0..4c8f412f9 100644 --- a/web/next.config.js +++ b/web/next.config.js @@ -39,6 +39,16 @@ export default withBundle( experimental: { largePageDataBytes: 300 * 1000, scrollRestoration: true, + optimizePackageImports: [ + '@components', + '@chakra-ui', + '@chakra-ui/skip-nav', + '@emotion/react', + '@emotion/styled', + '@equinor/eds-core-react', + '@equinor/eds-icons', + 'hls.js', + ], }, eslint: { // Warning: Dangerously allow production builds to successfully complete even if diff --git a/web/pageComponents/pageTemplates/newsroom/Hit.tsx b/web/pageComponents/pageTemplates/newsroom/Hit.tsx index 1029a2583..f3c096544 100644 --- a/web/pageComponents/pageTemplates/newsroom/Hit.tsx +++ b/web/pageComponents/pageTemplates/newsroom/Hit.tsx @@ -47,7 +47,7 @@ const Hit = ({ hit }: { hit: any }) => { const pageTitle = Array.isArray(hit.pageTitle) ? toPlainText(hit.pageTitle as PortableTextBlock[]) : hit.pageTitle return ( - +
{hit.publishDateTime && } diff --git a/web/pageComponents/shared/Footer.tsx b/web/pageComponents/shared/Footer.tsx index 3fae08049..290bc4351 100644 --- a/web/pageComponents/shared/Footer.tsx +++ b/web/pageComponents/shared/Footer.tsx @@ -144,7 +144,7 @@ const Footer = forwardRef(function Footer({ footerD const icon = type === 'someLink' && someType ? getSomeSvg(someType) : null return ( - + {icon && {icon}} {label} diff --git a/web/pageComponents/shared/Header.tsx b/web/pageComponents/shared/Header.tsx index 235577f24..7e35ae78c 100644 --- a/web/pageComponents/shared/Header.tsx +++ b/web/pageComponents/shared/Header.tsx @@ -130,7 +130,7 @@ const HeadTags = ({ slugs }: { slugs: AllSlugsType }) => { const AllSites = () => { const allSitesURL = getAllSitesLink('external') return ( - + ) @@ -172,7 +172,7 @@ const Header = ({ slugs, menuData }: HeaderProps) => { > {hasSearch && ( - + diff --git a/web/pageComponents/shared/Hero/LoopingVideo.tsx b/web/pageComponents/shared/Hero/LoopingVideo.tsx index 55b815253..88315a2e3 100644 --- a/web/pageComponents/shared/Hero/LoopingVideo.tsx +++ b/web/pageComponents/shared/Hero/LoopingVideo.tsx @@ -1,10 +1,19 @@ -import { HLSPlayer } from '@components' +import { HLSPlayer } from '../../../components/src/HLSPlayer' import { useSanityLoader } from '../../../lib/hooks/useSanityLoader' import styled from 'styled-components' import { LoopingVideoData, LoopingVideoRatio } from '../../../types' +import dynamic from 'next/dynamic' const DEFAULT_MAX_WIDTH = 1920 +const DynamicHLSVideoComponent = dynamic>( + () => import('../../../components/src/HLSPlayer').then((mod) => mod.HLSPlayer), + { + ssr: false, + loading: () =>

Loading...

, + }, +) + const Container = styled.div<{ $aspectRatio: LoopingVideoRatio }>` position: relative; ${({ $aspectRatio }) => @@ -27,7 +36,7 @@ const StyledFigure = styled.figure` position: absolute; ` -const StyledHLSPlayer = styled(HLSPlayer)` +const StyledHLSPlayer = styled(DynamicHLSVideoComponent)` position: absolute; width: 100%; height: 100%; diff --git a/web/pageComponents/shared/LocalizationSwitch.tsx b/web/pageComponents/shared/LocalizationSwitch.tsx index 850d6338d..bfcf71b54 100644 --- a/web/pageComponents/shared/LocalizationSwitch.tsx +++ b/web/pageComponents/shared/LocalizationSwitch.tsx @@ -97,7 +97,7 @@ type LocaleLinkProps = { const LocaleLink: React.FC> = ({ href, title, locale, active, children }) => { if (!active) { return ( - + {children} ) diff --git a/web/pageComponents/shared/LogoLink.tsx b/web/pageComponents/shared/LogoLink.tsx index 5c2822679..978070ef7 100644 --- a/web/pageComponents/shared/LogoLink.tsx +++ b/web/pageComponents/shared/LogoLink.tsx @@ -29,7 +29,7 @@ type LogoLinkProps = AnchorHTMLAttributes export const LogoLink = ({ ...rest }: LogoLinkProps) => { return ( - + ) diff --git a/web/pageComponents/shared/VideoPlayer.tsx b/web/pageComponents/shared/VideoPlayer.tsx index 7c082d2c9..fb77d1dda 100644 --- a/web/pageComponents/shared/VideoPlayer.tsx +++ b/web/pageComponents/shared/VideoPlayer.tsx @@ -1,5 +1,6 @@ /* eslint-disable jsx-a11y/media-has-caption */ import styled from 'styled-components' +import dynamic from 'next/dynamic' import { VideoControlsType, VideoPlayerData, @@ -7,11 +8,20 @@ import { VideoType, VideoDesignOptionsType, } from '../../types/types' -import { BackgroundContainer, HLSPlayer } from '@components' +import { BackgroundContainer } from '@components' import TitleText from '../shared/portableText/TitleText' import { urlFor } from '../../common/helpers' import IngressText from './portableText/IngressText' import { ButtonLink } from './ButtonLink' +import { HLSPlayer } from '../../components/src/HLSPlayer' + +const DynamicHLSVideoComponent = dynamic>( + () => import('../../components/src/HLSPlayer').then((mod) => mod.HLSPlayer), + { + ssr: false, + loading: () =>

Loading...

, + }, +) const StyledHeading = styled(TitleText)` padding: 0 0 var(--space-large) 0; @@ -84,7 +94,7 @@ const ButtonWrapper = styled.div` margin-bottom: var(--space-xLarge); ` -const StyledHLSPlayer = styled(HLSPlayer)` +const StyledHLSPlayer = styled(DynamicHLSVideoComponent)` object-fit: cover; width: inherit; diff --git a/web/pageComponents/topicPages/Breadcrumbs.tsx b/web/pageComponents/topicPages/Breadcrumbs.tsx index db037ac09..d7c8ff0d7 100644 --- a/web/pageComponents/topicPages/Breadcrumbs.tsx +++ b/web/pageComponents/topicPages/Breadcrumbs.tsx @@ -94,7 +94,9 @@ export const Breadcrumbs = ({ } return ( - {item.label} + + {item.label} + ) })} diff --git a/web/pageComponents/topicPages/FullWidthVideo.tsx b/web/pageComponents/topicPages/FullWidthVideo.tsx index 3cecb1761..cf8f527be 100644 --- a/web/pageComponents/topicPages/FullWidthVideo.tsx +++ b/web/pageComponents/topicPages/FullWidthVideo.tsx @@ -1,6 +1,16 @@ import { FullWidthVideoData, FullWidthVideoRatio } from '../../types/types' import styled from 'styled-components' -import { BackgroundContainer, HLSPlayer } from '@components' +import { BackgroundContainer } from '@components' +import { HLSPlayer } from '../../components/src/HLSPlayer' +import dynamic from 'next/dynamic' + +const DynamicHLSVideoComponent = dynamic>( + () => import('../../components/src/HLSPlayer').then((mod) => mod.HLSPlayer), + { + ssr: false, + loading: () =>

Loading...

, + }, +) const Container = styled.div<{ $aspectRatio: FullWidthVideoRatio }>` position: relative; @@ -35,7 +45,7 @@ const StyledFigure = styled.figure` position: absolute; ` -const StyledHLSPlayer = styled(HLSPlayer)` +const StyledHLSPlayer = styled(DynamicHLSVideoComponent)` position: absolute; top: 0; left: 0; diff --git a/web/pages/[[...slug]].tsx b/web/pages/[[...slug]].tsx index 4afc6ea83..0a3e107b8 100644 --- a/web/pages/[[...slug]].tsx +++ b/web/pages/[[...slug]].tsx @@ -11,7 +11,7 @@ import { defaultLanguage } from '../languages' import Header from '../pageComponents/shared/Header' import { FormattedMessage } from 'react-intl' import getIntl from '../common/helpers/getIntl' -import { getRoutePaths } from '../common/helpers/getPaths' +import { getStaticBuildRoutePaths } from '../common/helpers/getPaths' import getPageSlugs from '../common/helpers/getPageSlugs' import { getComponentsData } from '../lib/fetchData' import { useContext, useEffect } from 'react' @@ -123,7 +123,8 @@ export const getStaticProps: GetStaticProps = async ({ params, preview = false, } export const getStaticPaths: GetStaticPaths = async ({ locales = [] }) => { - const routePaths = await getRoutePaths(locales) + // Not changing getRoutePaths(locales) because its used in sitemap.xml + const routePaths = await getStaticBuildRoutePaths(locales) const paths = routePaths.map((path) => ({ params: { slug: path.slug }, From e6a6c39f997233479fe8e4359464eb7f31dccbe6 Mon Sep 17 00:00:00 2001 From: Borghild Date: Mon, 12 Feb 2024 08:58:26 +0100 Subject: [PATCH 2/3] :art: set prefetch false on more links --- web/components/src/Link/Link.tsx | 4 ++-- web/pageComponents/cards/FeaturedEventCard.tsx | 2 +- web/pageComponents/cards/MagazineCard.tsx | 2 +- web/pageComponents/cards/NewsCard.tsx | 2 +- web/pageComponents/cards/SimpleCard.tsx | 2 +- web/pageComponents/cards/TopicPageCard.tsx | 2 +- web/pageComponents/search/EventHit.tsx | 2 +- web/pageComponents/search/MagazineHit.tsx | 2 +- web/pageComponents/search/NewsHit.tsx | 2 +- web/pageComponents/search/TopicHit.tsx | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/web/components/src/Link/Link.tsx b/web/components/src/Link/Link.tsx index b50eb9e8f..0451820d8 100644 --- a/web/components/src/Link/Link.tsx +++ b/web/components/src/Link/Link.tsx @@ -117,13 +117,13 @@ export const Link = forwardRef(function Link( ) { if (variant === 'contentLink') { return ( - + {children} ) } else if (variant === 'readMore') { return ( - + {children} ) diff --git a/web/pageComponents/cards/FeaturedEventCard.tsx b/web/pageComponents/cards/FeaturedEventCard.tsx index 18217894a..7d5892811 100644 --- a/web/pageComponents/cards/FeaturedEventCard.tsx +++ b/web/pageComponents/cards/FeaturedEventCard.tsx @@ -58,7 +58,7 @@ const FeaturedEventCard = ({ data, fitToContent = false, ...rest }: FeaturedEven const plainTitle = title ? toPlainText(title as PortableTextBlock[]) : '' return ( - + + { if (!heroImage) return null return ( - + { const { id, label, image } = data return ( - + + { // @TODO: A more generic Hit component for more than events. Or multiple components??? return (
- + {eventDate && } diff --git a/web/pageComponents/search/MagazineHit.tsx b/web/pageComponents/search/MagazineHit.tsx index 103075adb..8ab8ffee9 100644 --- a/web/pageComponents/search/MagazineHit.tsx +++ b/web/pageComponents/search/MagazineHit.tsx @@ -52,7 +52,7 @@ const MagazineHit = ({ hit }: HitProps) => { return (
- + diff --git a/web/pageComponents/search/NewsHit.tsx b/web/pageComponents/search/NewsHit.tsx index 68fede26b..9f6833f96 100644 --- a/web/pageComponents/search/NewsHit.tsx +++ b/web/pageComponents/search/NewsHit.tsx @@ -60,7 +60,7 @@ const NewsHit = ({ hit }: HitProps) => { return (
- + {hit.publishDateTime && } diff --git a/web/pageComponents/search/TopicHit.tsx b/web/pageComponents/search/TopicHit.tsx index c85685864..d65bce1cb 100644 --- a/web/pageComponents/search/TopicHit.tsx +++ b/web/pageComponents/search/TopicHit.tsx @@ -37,7 +37,7 @@ const TopicHit = ({ hit }: HitProps) => { // @TODO: A more generic Hit component for more than events. Or multiple components??? return (
- + From 55de457c19fa31e4cae9bb2c1d4d1f1907d56fcb Mon Sep 17 00:00:00 2001 From: Borghild Date: Tue, 13 Feb 2024 08:45:07 +0100 Subject: [PATCH 3/3] :art: Remove console log --- web/common/helpers/getPaths.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/web/common/helpers/getPaths.ts b/web/common/helpers/getPaths.ts index b023fd7ad..892d5b786 100644 --- a/web/common/helpers/getPaths.ts +++ b/web/common/helpers/getPaths.ts @@ -40,7 +40,6 @@ const getTopicRoutesForLocaleToStaticallyBuild = async (locale: string) => { blacklist, }, ) - console.log('data', data) return data }