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

feat: search page with SSR #2619

Merged
merged 8 commits into from
Jan 29, 2025
Merged

feat: search page with SSR #2619

merged 8 commits into from
Jan 29, 2025

Conversation

pedromtec
Copy link
Contributor

@pedromtec pedromtec commented Jan 21, 2025

(Don't merge!)

What's the purpose of this pull request?

This POC is an alternative to indexing search pages using server side rendering. As the search page is dynamic and we need to set the title and description based on the search term, we chose to use server side rendering as it is the most suitable for this type of situation.

Nextjs reference:

Like SSG, Server-Side Rendering (SSR) is pre-rendered, which also makes it great for SEO. Instead of being generated at build time, as in SSG, SSR's HTML is generated at request time. This is great for when you have pages that are very dynamic.
https://nextjs.org/learn-pages-router/seo/rendering-and-ranking/rendering-strategies

How it works?

We use the getServerSideProps function instead of getStaticProps. We added a cache header to the response so that it is possible to cache the return in a CDN.

How to test it?

Click on: https://storeframework-cm652ufll028lmgv665a6xv0g-polemunmz.b.vtex.app/s?q=headphone

Copy link

vercel bot commented Jan 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
faststore-site ✅ Ready (Inspect) Visit Preview Jan 29, 2025 1:26pm

@@ -54,13 +55,13 @@ const useSearchParams = ({
}, [asPath, defaultSort])
}

function Page({ page: searchContentType, globalSections }: Props) {
function Page({ page: searchContentType, globalSections, searchTerm }: Props) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk: Affected versions of next are vulnerable to Acceptance of Extraneous Untrusted Data With Trusted Data / Authorization Bypass Through User-Controlled Key.

Fix: Upgrade this library to at least version 13.5.7 at faststore/yarn.lock:13689.

Reference(s): GHSA-gp8f-8m3g-qvj9, CVE-2024-46982

💬 To ignore this, reply with:
/fp <comment> for false positive
/ar <comment> for acceptable risk
/other <comment> for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by ssc-adb055b9-fed0-4d70-a57d-eb9825b09449.

Copy link

codesandbox-ci bot commented Jan 21, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

title={title}
description={description}
title={`${searchTerm}`}
description={`${searchTerm}: em promoção que você procura? Na Americanas você encontra as melhores ofertas de produtos com entrega rápida. Vem!`}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dúvida, esse conteúdo aqui o merchant consegue customizar no repositorio dele sem reescrever toda a pagina?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Em teoria sim, mas preciso validar. Pretendo mudar isso no código antes de mergear.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

acho que aqui podemos fazer algo similar ao que o NextSeo faz com title e titleTemplate para tornar dinâmico, mas adaptando para description (e criando um desciptionTemplate) com replace.

templateDescription.replace(/%s/g, () => updatedDescription);

packages/core/src/pages/s.tsx Outdated Show resolved Hide resolved
packages/core/src/pages/s.tsx Outdated Show resolved Hide resolved
title={title}
description={description}
title={`${searchTerm}`}
description={`${searchTerm}: em promoção que você procura? Na Americanas você encontra as melhores ofertas de produtos com entrega rápida. Vem!`}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

acho que aqui podemos fazer algo similar ao que o NextSeo faz com title e titleTemplate para tornar dinâmico, mas adaptando para description (e criando um desciptionTemplate) com replace.

templateDescription.replace(/%s/g, () => updatedDescription);

@pedromtec pedromtec force-pushed the feat/poc-seo-search branch 5 times, most recently from 4bea98c to 235056a Compare January 27, 2025 21:41
function Page({ page: searchContentType, globalSections }: Props) {
type StoreConfig = typeof storeConfig

function generateSEOData(storeConfig: StoreConfig, searchTerm?: string) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Risk: Affected versions of next are vulnerable to Acceptance of Extraneous Untrusted Data With Trusted Data / Authorization Bypass Through User-Controlled Key.

Fix: Upgrade this library to at least version 13.5.7 at faststore/yarn.lock:13689.

Reference(s): GHSA-gp8f-8m3g-qvj9, CVE-2024-46982

💬 To ignore this, reply with:
/fp <comment> for false positive
/ar <comment> for acceptable risk
/other <comment> for all other reasons
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by ssc-adb055b9-fed0-4d70-a57d-eb9825b09449.

@pedromtec pedromtec force-pushed the feat/poc-seo-search branch from 00ed554 to 8a93cbb Compare January 28, 2025 13:29
@pedromtec pedromtec changed the title feat: next seo poc feat: search page with SSR Jan 28, 2025
@pedromtec pedromtec marked this pull request as ready for review January 28, 2025 13:49
@pedromtec pedromtec requested a review from a team as a code owner January 28, 2025 13:49
@pedromtec pedromtec requested review from hellofanny, eduardoformiga and gabpaladino and removed request for a team and gabpaladino January 28, 2025 13:49
Copy link
Member

@eduardoformiga eduardoformiga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
I left some small comments, but it is not blocking.

It looks like worked as expected in the starter.
Screenshot 2025-01-28 at 17 27 41
Screenshot 2025-01-28 at 17 28 08

packages/cli/src/utils/generate.ts Outdated Show resolved Hide resolved
packages/cli/src/utils/generate.ts Show resolved Hide resolved
? searchSeo.descriptionTemplate.replace(/%s/g, () => searchTerm)
: seo.description

const canonical = searchTerm
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add the canonical when isSSREnabled as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have access to search term in getStaticProps

packages/core/src/pages/s.tsx Outdated Show resolved Hide resolved
@pedromtec pedromtec force-pushed the feat/poc-seo-search branch from bb99769 to bcb8926 Compare January 29, 2025 13:23
@pedromtec pedromtec merged commit 6fd2d0d into main Jan 29, 2025
8 checks passed
@pedromtec pedromtec deleted the feat/poc-seo-search branch January 29, 2025 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants