Skip to content

Commit

Permalink
fix(core): dedupe requests in webpages
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemoya committed Jan 24, 2025
1 parent 157ea54 commit 12581d2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-impalas-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

Dedupe requests in "webpages" by properly caching/memoizing the fetch function per page render.
14 changes: 7 additions & 7 deletions core/app/[locale]/(default)/(auth)/change-password/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import { redirect } from '~/i18n/routing';

import { changePassword } from './_actions/change-password';

interface Props {
searchParams: Promise<{
c?: string;
t?: string;
}>;
}

export async function generateMetadata(): Promise<Metadata> {
const t = await getTranslations('ChangePassword');

Expand All @@ -15,13 +22,6 @@ export async function generateMetadata(): Promise<Metadata> {
};
}

interface Props {
searchParams: Promise<{
c?: string;
t?: string;
}>;
}

export default async function ChangePassword({ searchParams }: Props) {
const { c: customerEntityId, t: token } = await searchParams;
const t = await getTranslations('ChangePassword');
Expand Down
5 changes: 3 additions & 2 deletions core/app/[locale]/(default)/webpages/[id]/contact/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { getTranslations, setRequestLocale } from 'next-intl/server';
import { cache } from 'react';

import { Breadcrumb } from '@/vibes/soul/primitives/breadcrumbs';
import { ButtonLink } from '@/vibes/soul/primitives/button-link';
Expand Down Expand Up @@ -41,7 +42,7 @@ const fieldMapping = {

type ContactField = keyof typeof fieldMapping;

async function getWebPage(id: string): Promise<ContactPage> {
const getWebPage = cache(async (id: string): Promise<ContactPage> => {
const data = await getWebpageData({ id: decodeURIComponent(id) });
const reCaptchaSettings = data.site.settings?.reCaptcha ?? null;
const webpage = data.node?.__typename === 'ContactPage' ? data.node : null;
Expand All @@ -62,7 +63,7 @@ async function getWebPage(id: string): Promise<ContactPage> {
seo: webpage.seo,
reCaptchaSettings,
};
}
});

async function getWebPageBreadcrumbs(id: string): Promise<Breadcrumb[]> {
const webpage = await getWebPage(id);
Expand Down
5 changes: 3 additions & 2 deletions core/app/[locale]/(default)/webpages/[id]/normal/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { cache } from 'react';

import { Breadcrumb } from '@/vibes/soul/primitives/breadcrumbs';
import {
Expand All @@ -15,7 +16,7 @@ interface Props {
params: Promise<{ id: string }>;
}

async function getWebPage(id: string): Promise<WebPageData> {
const getWebPage = cache(async (id: string): Promise<WebPageData> => {
const data = await getWebpageData({ id: decodeURIComponent(id) });
const webpage = data.node?.__typename === 'NormalPage' ? data.node : null;

Expand All @@ -31,7 +32,7 @@ async function getWebPage(id: string): Promise<WebPageData> {
content: webpage.htmlBody,
seo: webpage.seo,
};
}
});

async function getWebPageBreadcrumbs(id: string): Promise<Breadcrumb[]> {
const webpage = await getWebPage(id);
Expand Down

0 comments on commit 12581d2

Please sign in to comment.