Skip to content

fix: landing page plp and sort fallback - #3297

Merged
eduardoformiga merged 5 commits into
canary-v2from
fix/landing-page-plp-and-sort-fallback
May 6, 2026
Merged

eduardoformiga merged 5 commits into
canary-v2from
fix/landing-page-plp-and-sort-fallback

Conversation

@eduardoformiga

@eduardoformiga eduardoformiga commented May 5, 2026 •

Copy link
Copy Markdown
Member

What's the purpose of this pull request?

This pull request introduces improvements to the sorting component and fixes to landing page retrieval logic. The main changes include providing default sort options, making the sort label and options optional, and correcting how landing pages are matched and queried by slug.

Enhancements to sorting functionality:

  • Added a DEFAULT_OPTIONS object for sort options, making the label and options props of the Sort component optional and providing sensible defaults if they are not specified. (packages/core/src/components/search/Sort/Sort.tsx)
  • Ensured that the sort options fallback to defaults if a custom label or options are not provided, improving component usability and robustness. (packages/core/src/components/search/Sort/Sort.tsx)

Bug fixes for landing page slug matching:

  • Fixed the landing page lookup to correctly compare slugs by prepending a / to the input slug, ensuring accurate page retrieval. (packages/core/src/components/templates/LandingPage/LandingPage.tsx)
  • Corrected the filter structure in the landing page query to nest the slug filter inside a filters object, aligning with expected API requirements. (packages/core/src/components/templates/LandingPage/LandingPage.tsx)

Summary by CodeRabbit

  • Bug Fixes

    • Fixed landing page slug matching to ensure correct URL path resolution and page loading.
  • Refactor

    • Improved Sort control flexibility with sensible defaults and support for partial customization of sort options.
  • Chores

    • Standardized CMS content filtering and fetch behavior for more reliable content loading.
    • Tightened content API typings for consistent filter handling.
  • Style

    • Centered preview icon layout and removed fixed sizing for improved visual alignment.

@eduardoformiga
eduardoformiga requested a review from a team as a code owner May 5, 2026 21:21
@eduardoformiga
eduardoformiga requested review from hellofanny and ommeirelles and removed request for a team May 5, 2026 21:21
@coderabbitai

coderabbitai Bot commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f086634a-43c8-468c-814f-7ff32153cbf3

📥 Commits

Reviewing files that changed from the base of the PR and between a0d643c and cb42ea1.

📒 Files selected for processing (2)
  • packages/core/src/components/common/PreviewTag/section.module.scss
  • packages/core/src/server/content/types.ts
💤 Files with no reviewable changes (1)
  • packages/core/src/components/common/PreviewTag/section.module.scss

Walkthrough

Refactors the Sort component to accept optional label/options with DEFAULT_OPTIONS and dynamic option construction; updates LandingPage slug comparison and nests slug filters when querying content; changes CMS server types to use Record<string,string> for filters and passes filters as an explicit object; minor CSS centering tweak for PreviewTag.

Changes

Sort Component Optional Props with Defaults

Layer / File(s) Summary
Data Shape & Types
packages/core/src/components/search/Sort/Sort.tsx
Added DEFAULT_OPTIONS (8 sort keys), SORT_OPTIONS_KEYS, and SortOptionKeys type. SortProps now has label?: string and options?: Partial<Record<SortOptionKeys,string>>.
Function Signature
packages/core/src/components/search/Sort/Sort.tsx
Sort({ label = 'Sort by', options = DEFAULT_OPTIONS }: SortProps) — props defaulted.
Core Implementation & Wiring
packages/core/src/components/search/Sort/Sort.tsx
Builds optionsMap by iterating SORT_OPTIONS_KEYS, applying options overrides with fallback to DEFAULT_OPTIONS. SelectField options are built dynamically and update search state on change.
Tests / Docs
(none changed)
No test or doc changes in this PR.

LandingPage Slug Filter Structure

Layer / File(s) Summary
Imports
packages/core/src/components/templates/LandingPage/LandingPage.tsx
Adjusted import order (getStoreURL before contentService).
Slug Matching Logic
packages/core/src/components/templates/LandingPage/LandingPage.tsx
getLandingPageBySlug now compares \/${slug}`topage.settings?.seo?.slug`.
CMS Query Filter
packages/core/src/components/templates/LandingPage/LandingPage.tsx
Default content fetch supplies slug filter under nested filters object: { filters: { 'settings.seo.slug': '/${slug}' } }.

CMS Filters Type & Callsite Change

Layer / File(s) Summary
Types
packages/core/src/server/cms/index.ts, packages/core/src/server/content/types.ts
Removed ContentTypeOptions import. Options.filters and ContentParams.filters types changed to Record<string,string>.
Callsites / Wiring
packages/core/src/server/cms/index.ts
CMS client calls updated to pass filters as explicit { filters: options.filters, page, perPage } instead of spreading options.filters; applied to initial and paginated fetches.

PreviewTag Styling Adjustment

Layer / File(s) Summary
Styles
packages/core/src/components/common/PreviewTag/section.module.scss
[data-fs-icon] now uses display: flex; align-items: center; justify-content: center; and removed fixed width/height: 16px.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • vtex/faststore#3260: Related changes to getLandingPageBySlug and slug/filter handling in LandingPage.

Suggested reviewers

  • lemagnetic
  • ommeirelles
  • lucasfp13

Poem

Defaults planted in tidy rows, 🌱
Keys enumerated so fallback grows,
Slugs march forward with a leading slash,
Filters nested, calls passed as objects —
Tiny edits, steadier pages and flows.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: landing page plp and sort fallback' directly corresponds to the main changes: Sort component fallback enhancements and landing page slug matching fixes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/landing-page-plp-and-sort-fallback

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@eduardoformiga
eduardoformiga requested review from a team and lemagnetic May 5, 2026 21:21
@codesandbox-ci

codesandbox-ci Bot commented May 5, 2026 •

Copy link
Copy Markdown

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/core/src/components/search/Sort/Sort.tsx`:
- Around line 29-37: The current optionsMap build uses Object.hasOwn to only
include keys present on the caller-supplied options, which hides non-overridden
sort options; change the reducer (or replace with a simple map) to iterate
unconditionally over SORT_OPTIONS_KEYS and for each key set acc[key] =
options[key] ?? DEFAULT_OPTIONS[key] so every sort key is present and caller
values simply override defaults; update the logic around optionsMap (referencing
optionsMap, SORT_OPTIONS_KEYS, options, and DEFAULT_OPTIONS) to remove the
Object.hasOwn guard and always merge with DEFAULT_OPTIONS.

In `@packages/core/src/components/templates/LandingPage/LandingPage.tsx`:
- Around line 147-151: The filters object passed into getSingleContent in
LandingPage.tsx is double-nested so the service (which expects
filters['settings.seo.slug'] directly) ignores the slug; update the call site to
pass a flat filters Record instead of { filters: { ... } }—i.e., when
contentContext.previewData?.contentType !== 'landingPage', supply filters with
'settings.seo.slug' at the top level (reference getSingleContent and the filters
argument and contentContext.previewData in LandingPage.tsx).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: be565d84-39a7-42a8-a5b8-5ce38e11bfb8

📥 Commits

Reviewing files that changed from the base of the PR and between d18bee0 and f94eee5.

📒 Files selected for processing (2)
  • packages/core/src/components/search/Sort/Sort.tsx
  • packages/core/src/components/templates/LandingPage/LandingPage.tsx

eduardoformiga and others added 3 commits May 5, 2026 23:32
The getCMSPage function was spreading options.filters flat into the
getCMSPagesByContentType call, causing the filters to be ignored and
all landing pages to be returned unfiltered. This made any PLP slug
incorrectly render as a landing page when contentSource.type is CMS.
@hellofanny
hellofanny force-pushed the fix/landing-page-plp-and-sort-fallback branch from f94eee5 to a0d643c Compare May 6, 2026 02:58
@pkg-pr-new

pkg-pr-new Bot commented May 6, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@faststore/api

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/cli

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/components

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/core

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/diagnostics

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/lighthouse

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/sdk

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

@faststore/ui

yarn add https://pkg.pr.new/vtex/faststore/@faststore/[email protected]

commit: cb42ea1

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
packages/core/src/components/search/Sort/Sort.tsx (1)

29-37: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Partial options still drops default sort entries.

Object.hasOwn(options, key) makes partial overrides behave like an allowlist, so non-overridden options disappear from the select. Build optionsMap unconditionally from all keys and use override-or-default per key.

Proposed fix
   const optionsMap = SORT_OPTIONS_KEYS.reduce(
     (acc, key) => {
-      if (Object.hasOwn(options, key)) {
-        acc[key] = options[key] ?? DEFAULT_OPTIONS[key]
-      }
+      acc[key] = options[key] ?? DEFAULT_OPTIONS[key]
       return acc
     },
     {} as Record<SortOptionKeys, string>
   )

As per coding guidelines, "Prefer flat conditionals over nested ifs: combine conditions with && or use early returns to avoid deep nesting and improve readability."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/core/src/components/search/Sort/Sort.tsx` around lines 29 - 37, The
current optionsMap creation uses Object.hasOwn(options, key) which causes
non-overridden keys to be omitted; change the reducer for SORT_OPTIONS_KEYS so
it always assigns acc[key] = options[key] ?? DEFAULT_OPTIONS[key] for every key
(remove the Object.hasOwn check) so partial options correctly fall back to
DEFAULT_OPTIONS; update the reducer expression that builds optionsMap to
unconditionally set each key using the override-or-default logic (symbols:
optionsMap, SORT_OPTIONS_KEYS, options, DEFAULT_OPTIONS).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@packages/core/src/components/search/Sort/Sort.tsx`:
- Around line 29-37: The current optionsMap creation uses Object.hasOwn(options,
key) which causes non-overridden keys to be omitted; change the reducer for
SORT_OPTIONS_KEYS so it always assigns acc[key] = options[key] ??
DEFAULT_OPTIONS[key] for every key (remove the Object.hasOwn check) so partial
options correctly fall back to DEFAULT_OPTIONS; update the reducer expression
that builds optionsMap to unconditionally set each key using the
override-or-default logic (symbols: optionsMap, SORT_OPTIONS_KEYS, options,
DEFAULT_OPTIONS).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2b623080-9b79-4279-9eb3-f581808be477

📥 Commits

Reviewing files that changed from the base of the PR and between f94eee5 and a0d643c.

📒 Files selected for processing (3)
  • packages/core/src/components/search/Sort/Sort.tsx
  • packages/core/src/components/templates/LandingPage/LandingPage.tsx
  • packages/core/src/server/cms/index.ts

@hellofanny hellofanny left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've tested using CP and CMS as type source. It's working as expected.

PLP - CMS

Image

Landing Page - CMS

Image

PLP - CP

Image

Landing page - CP

Image

@eduardoformiga
eduardoformiga merged commit 400b098 into canary-v2 May 6, 2026
5 checks passed
@eduardoformiga
eduardoformiga deleted the fix/landing-page-plp-and-sort-fallback branch May 6, 2026 14:28
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.

2 participants