Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 Improve performance #1059 #2102

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions sanityv3/schemas/documents/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
6 changes: 6 additions & 0 deletions sanityv3/schemas/documents/routeHomepage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
30 changes: 30 additions & 0 deletions web/common/helpers/getPaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
BorghildSelle marked this conversation as resolved.
Show resolved Hide resolved
return data
}

const getDocumentsForLocale = async (type: 'news' | 'localNews' | 'magazine', locale: string) => {
const lang = getNameFromLocale(locale)
Expand Down Expand Up @@ -64,6 +81,19 @@ export type PathType = {
locale: string
}

export const getStaticBuildRoutePaths = async (locales: string[]): Promise<PathType[]> => {
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<PathType[]> => {
const fetchPaths = locales.map(async (locale) => {
const pages = await getTopicRoutesForLocale(locale)
Expand Down
2 changes: 1 addition & 1 deletion web/components/src/Link/ButtonLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const ButtonLink = forwardRef<HTMLAnchorElement, ButtonLinkProps>(functio
ref,
) {
return (
<NextLink href={href} locale={locale}>
<NextLink href={href} locale={locale} prefetch={false}>
<StyledButtonLink color="secondary" variant="outlined" ref={ref} {...rest}>
{children}
</StyledButtonLink>
Expand Down
5 changes: 3 additions & 2 deletions web/components/src/Link/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>(function Link(
) {
if (variant === 'contentLink') {
return (
<ContentLink href={href} ref={ref} {...rest}>
<ContentLink href={href} prefetch={false} ref={ref} {...rest}>
{children} <Icon data={getIconData(type)} />
</ContentLink>
)
} else if (variant === 'readMore') {
return (
<ReadMoreLink href={href} ref={ref} {...rest}>
<ReadMoreLink href={href} prefetch={false} ref={ref} {...rest}>
{children} <Icon data={getIconData(type)} />
</ReadMoreLink>
)
Expand All @@ -140,6 +140,7 @@ export const Link = forwardRef<HTMLAnchorElement, LinkProps>(function Link(
} as CSSProperties
}
$textDecoration={underline ? 'underline' : 'none'}
prefetch={false}
{...rest}
>
{children} {type === 'externalUrl' ? <Icon data={external_link} size={16} /> : null}
Expand Down
10 changes: 10 additions & 0 deletions web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion web/pageComponents/cards/FeaturedEventCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const FeaturedEventCard = ({ data, fitToContent = false, ...rest }: FeaturedEven
const plainTitle = title ? toPlainText(title as PortableTextBlock[]) : ''

return (
<StyledLink href={slug} {...rest}>
<StyledLink href={slug} {...rest} prefetch={false}>
<StyledCard
style={
{
Expand Down
2 changes: 1 addition & 1 deletion web/pageComponents/cards/MagazineCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const MagazineCard = ({ data, fitToContent = false, ...rest }: MagazineCardProp)
if (!thumbnail) return null

return (
<StyledLink href={slug} {...rest}>
<StyledLink href={slug} prefetch={false} {...rest}>
<StyledCard
style={
{
Expand Down
2 changes: 1 addition & 1 deletion web/pageComponents/cards/NewsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const NewsCard = ({ data, fitToContent = false, ...rest }: NewsCardProp) => {
if (!heroImage) return null

return (
<StyledLink href={slug} {...rest}>
<StyledLink href={slug} prefetch={false} {...rest}>
<StyledCard
style={
{
Expand Down
2 changes: 1 addition & 1 deletion web/pageComponents/cards/SimpleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function getLink(linkData: MenuLinkData, label: string) {
const SimpleCard = ({ data }: SimpleCardData) => {
const { id, label, image } = data
return (
<CardLink key={id} href={getLink(data, label)}>
<CardLink key={id} href={getLink(data, label)} prefetch={false}>
<StyledCard
style={
{
Expand Down
2 changes: 1 addition & 1 deletion web/pageComponents/cards/TopicPageCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const TopicPageCard = ({ data, fitToContent = false, ...rest }: TopicPageCardPro
const pageTitle = title ? toPlainText(title as PortableTextBlock[]) : ''

return (
<StyledLink href={slug} {...rest}>
<StyledLink href={slug} prefetch={false} {...rest}>
<StyledCard
style={
{
Expand Down
2 changes: 1 addition & 1 deletion web/pageComponents/pageTemplates/newsroom/Hit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const Hit = ({ hit }: { hit: any }) => {
const pageTitle = Array.isArray(hit.pageTitle) ? toPlainText(hit.pageTitle as PortableTextBlock[]) : hit.pageTitle

return (
<StyledHitLink href={hit.slug}>
<StyledHitLink href={hit.slug} prefetch={false}>
<article>
<Date>{hit.publishDateTime && <FormattedDate datetime={hit.publishDateTime} uppercase />}</Date>
<StyledHeading level="h3" size="md">
Expand Down
2 changes: 1 addition & 1 deletion web/pageComponents/search/EventHit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const EventHit = ({ hit }: HitProps) => {
// @TODO: A more generic Hit component for more than events. Or multiple components???
return (
<article>
<StyledHitLink href={slug}>
<StyledHitLink href={slug} prefetch={false}>
{eventDate && <StyledFormattedDate datetime={eventDate} uppercase></StyledFormattedDate>}
<HitHeading level="h2" size="sm">
<Highlight hit={hit} attribute="title" />
Expand Down
2 changes: 1 addition & 1 deletion web/pageComponents/search/MagazineHit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const MagazineHit = ({ hit }: HitProps) => {

return (
<article>
<StyledHitLink href={slug}>
<StyledHitLink href={slug} prefetch={false}>
<HitHeading level="h2" size="sm">
<Highlight hit={hit} attribute="pageTitle" />
</HitHeading>
Expand Down
2 changes: 1 addition & 1 deletion web/pageComponents/search/NewsHit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const NewsHit = ({ hit }: HitProps) => {

return (
<article>
<StyledHitLink href={slug}>
<StyledHitLink href={slug} prefetch={false}>
{hit.publishDateTime && <StyledFormattedDate datetime={hit.publishDateTime} uppercase />}
<HitHeading level="h2" size="sm">
<Highlight hit={hit} attribute="pageTitle" />
Expand Down
2 changes: 1 addition & 1 deletion web/pageComponents/search/TopicHit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const TopicHit = ({ hit }: HitProps) => {
// @TODO: A more generic Hit component for more than events. Or multiple components???
return (
<article>
<StyledHitLink href={slug}>
<StyledHitLink href={slug} prefetch={false}>
<HitHeading level="h2" size="sm">
<Highlight hit={hit} attribute="pageTitle" />
</HitHeading>
Expand Down
2 changes: 1 addition & 1 deletion web/pageComponents/shared/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const Footer = forwardRef<HTMLDivElement, FooterProps>(function Footer({ footerD
const icon = type === 'someLink' && someType ? getSomeSvg(someType) : null

return (
<FooterLink key={id} href={url || getLink(link)}>
<FooterLink key={id} href={url || getLink(link)} prefetch={false}>
{icon && <SomeIcon aria-hidden={true}>{icon}</SomeIcon>}
{label}
</FooterLink>
Expand Down
4 changes: 2 additions & 2 deletions web/pageComponents/shared/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const HeadTags = ({ slugs }: { slugs: AllSlugsType }) => {
const AllSites = () => {
const allSitesURL = getAllSitesLink('external')
return (
<StyledAllSites href={allSitesURL}>
<StyledAllSites href={allSitesURL} prefetch={false}>
<FormattedMessage id="all_sites" defaultMessage="All Sites" />
</StyledAllSites>
)
Expand Down Expand Up @@ -172,7 +172,7 @@ const Header = ({ slugs, menuData }: HeaderProps) => {
>
{hasSearch && (
<ControlChild>
<NextLink href="/search">
<NextLink href="/search" prefetch={false}>
<StyledSearchButton variant="ghost_icon" aria-expanded="true" aria-label="Search">
<Icon size={24} data={search} />
</StyledSearchButton>
Expand Down
13 changes: 11 additions & 2 deletions web/pageComponents/shared/Hero/LoopingVideo.tsx
Original file line number Diff line number Diff line change
@@ -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<React.ComponentProps<typeof HLSPlayer>>(
() => import('../../../components/src/HLSPlayer').then((mod) => mod.HLSPlayer),
BorghildSelle marked this conversation as resolved.
Show resolved Hide resolved
{
ssr: false,
loading: () => <p>Loading...</p>,
},
)

const Container = styled.div<{ $aspectRatio: LoopingVideoRatio }>`
position: relative;
${({ $aspectRatio }) =>
Expand All @@ -27,7 +36,7 @@ const StyledFigure = styled.figure`
position: absolute;
`

const StyledHLSPlayer = styled(HLSPlayer)`
const StyledHLSPlayer = styled(DynamicHLSVideoComponent)`
position: absolute;
width: 100%;
height: 100%;
Expand Down
2 changes: 1 addition & 1 deletion web/pageComponents/shared/LocalizationSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type LocaleLinkProps = {
const LocaleLink: React.FC<React.PropsWithChildren<LocaleLinkProps>> = ({ href, title, locale, active, children }) => {
if (!active) {
return (
<StyledLink href={href} locale={locale} aria-label={title}>
<StyledLink href={href} locale={locale} aria-label={title} prefetch={false}>
{children}
</StyledLink>
)
Expand Down
2 changes: 1 addition & 1 deletion web/pageComponents/shared/LogoLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type LogoLinkProps = AnchorHTMLAttributes<HTMLAnchorElement>

export const LogoLink = ({ ...rest }: LogoLinkProps) => {
return (
<StyledLogoLink href="/" aria-label="Equinor home page" {...rest} className="logo">
<StyledLogoLink href="/" aria-label="Equinor home page" {...rest} className="logo" prefetch={false}>
<AlignedLogoSecondary />
</StyledLogoLink>
)
Expand Down
14 changes: 12 additions & 2 deletions web/pageComponents/shared/VideoPlayer.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
/* eslint-disable jsx-a11y/media-has-caption */
import styled from 'styled-components'
import dynamic from 'next/dynamic'
import {
VideoControlsType,
VideoPlayerData,
VideoPlayerRatios,
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<React.ComponentProps<typeof HLSPlayer>>(
() => import('../../components/src/HLSPlayer').then((mod) => mod.HLSPlayer),
{
ssr: false,
loading: () => <p>Loading...</p>,
},
)

const StyledHeading = styled(TitleText)`
padding: 0 0 var(--space-large) 0;
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 3 additions & 1 deletion web/pageComponents/topicPages/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export const Breadcrumbs = ({
}
return (
<BreadcrumbsListItem key={item.slug}>
<StyledNextLink href={item.slug}>{item.label}</StyledNextLink>
<StyledNextLink href={item.slug} prefetch={false}>
{item.label}
</StyledNextLink>
</BreadcrumbsListItem>
)
})}
Expand Down
14 changes: 12 additions & 2 deletions web/pageComponents/topicPages/FullWidthVideo.tsx
Original file line number Diff line number Diff line change
@@ -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<React.ComponentProps<typeof HLSPlayer>>(
() => import('../../components/src/HLSPlayer').then((mod) => mod.HLSPlayer),
{
ssr: false,
loading: () => <p>Loading...</p>,
},
)

const Container = styled.div<{ $aspectRatio: FullWidthVideoRatio }>`
position: relative;
Expand Down Expand Up @@ -35,7 +45,7 @@ const StyledFigure = styled.figure`
position: absolute;
`

const StyledHLSPlayer = styled(HLSPlayer)`
const StyledHLSPlayer = styled(DynamicHLSVideoComponent)`
position: absolute;
top: 0;
left: 0;
Expand Down
5 changes: 3 additions & 2 deletions web/pages/[[...slug]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 },
Expand Down
Loading