Skip to content

feat: add sitemap filtering option#7368

Open
flip-it wants to merge 1 commit intoTanStack:mainfrom
flip-it:sitemap-filter-option
Open

feat: add sitemap filtering option#7368
flip-it wants to merge 1 commit intoTanStack:mainfrom
flip-it:sitemap-filter-option

Conversation

@flip-it
Copy link
Copy Markdown

@flip-it flip-it commented May 8, 2026

Pre-rendering with link crawling can pick up irrelevant pages not intended for the sitemap. Just as prerender has a filter option to exclude certain pages, I propose the same for sitemap.

Example intended usage

tanstackStart({
  prerender: {
    enabled: true,
    crawlLinks: true,
    filter: ({ path }) => !path.startsWith('/admin')
  },
  sitemap: {
    enabled: true,
    host: 'https://example.com',
    filter: ({ path }) => !path.startsWith('/admin') // <-- new option
  },
})

Summary by CodeRabbit

  • New Features

    • Sitemap generation now supports an optional filter function to exclude specific pages from the generated sitemap output during the build process
  • Documentation

    • Updated React framework SEO guide with sitemap filtering example
    • Updated Solid framework SEO guide with sitemap filtering example
  • Tests

    • Added comprehensive test suite for sitemap generation covering filtering, URL construction, metadata, and output validation

@github-actions github-actions Bot added documentation Everything documentation related package: start-plugin-core labels May 8, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 8, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds a filter function option to sitemap configuration, enabling users to exclude specific pages from generated sitemaps. Changes include schema extension, implementation logic in sitemap generation, documentation examples for React and Solid frameworks, and an extensive test suite covering error cases, filtering behavior, metadata emission, and output correctness.

Changes

Sitemap Filter Feature

Layer / File(s) Summary
Schema Definition
packages/start-plugin-core/src/schema.ts
Sitemap configuration extended with optional filter: (page: Page) => any function in the exported schema.
Filter Logic in Build
packages/start-plugin-core/src/build-sitemap.ts
buildSitemapJson accepts filter function and applies it during page selection; buildSitemap destructures filter from options and passes it through.
Documentation Examples
docs/start/framework/react/guide/seo.md, docs/start/framework/solid/guide/seo.md
Added sitemap.filter usage examples demonstrating exclusion of paths starting with /do-not-include-me.
Test Suite
packages/start-plugin-core/tests/build-sitemap.test.ts
New comprehensive Vitest suite covering infrastructure, helpers, error cases, URL generation, filter application, metadata emission, output file correctness, and edge cases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A filter blooms in sitemap's glade,
To shade the paths we'd rather fade—
With tests well-spun and docs so clear,
Exclusion's logic now appears! 🐰✨

🚥 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 'feat: add sitemap filtering option' accurately and concisely describes the main change—adding a new filter option to sitemap configuration.
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 unit tests (beta)
  • Create PR with unit tests

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Bundle Size Benchmarks

  • Commit: 4eed408f127b
  • Measured at: 2026-05-08T13:18:40.818Z
  • Baseline source: history:35e88f04996d
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Initial gzip Raw Brotli Trend
react-router.minimal 87.29 KiB +139 B (+0.16%) 87.15 KiB 274.07 KiB 75.81 KiB ▁▁▁▁▁▁▁▁▁▁▁█
react-router.full 90.82 KiB +141 B (+0.15%) 90.68 KiB 285.58 KiB 78.82 KiB ▁▁▁▁▁▁▁▁▁▁▁█
solid-router.minimal 35.51 KiB +126 B (+0.35%) 35.38 KiB 106.36 KiB 31.91 KiB ▁▁▁▁▁▁▁▁▁▁▁█
solid-router.full 40.23 KiB +127 B (+0.31%) 40.10 KiB 120.58 KiB 36.14 KiB ▁▁▁▁▁▁▁▁▁▁▁█
vue-router.minimal 53.28 KiB +131 B (+0.24%) 53.15 KiB 151.51 KiB 47.83 KiB ▁▁▁▁▁▁▁▁▁▁▁█
vue-router.full 58.41 KiB +133 B (+0.22%) 58.28 KiB 167.68 KiB 52.30 KiB ▁▁▁▁▁▁▁▁▁▁▁█
react-start.minimal 101.97 KiB +141 B (+0.14%) 101.84 KiB 322.51 KiB 88.13 KiB ▁▁▁▁▁▁▁▁▁▁▃█
react-start.full 105.41 KiB +140 B (+0.13%) 105.27 KiB 332.84 KiB 91.10 KiB ▁▁▁▁▁▁▁▁▁▁▄█
react-start.rsbuild.minimal 99.60 KiB +174 B (+0.17%) 99.43 KiB 316.97 KiB 85.65 KiB ▁▁▁▁▁▁▁▁▁▁▄█
react-start.rsbuild.full 102.89 KiB +174 B (+0.17%) 102.72 KiB 327.41 KiB 88.45 KiB ▁▁▁▁▁▁▁▁▁▁▃█
solid-start.minimal 49.61 KiB +131 B (+0.26%) 49.48 KiB 152.48 KiB 43.79 KiB ▁▁▁▁▁▁▁▁▁▁▄█
solid-start.full 55.40 KiB +133 B (+0.24%) 55.27 KiB 169.39 KiB 48.70 KiB ▁▁▁▁▁▁▁▁▁▁▄█

Current gzip tracks all emitted client JS chunks. Initial gzip tracks only the entry/import graph. Trend sparkline is historical current gzip ending with this PR measurement; lower is better.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/start-plugin-core/tests/build-sitemap.test.ts (1)

127-141: 💤 Low value

Optional: consolidate page setup inside makeStartConfig to match the rest of the suite.

Line 136 mutates startConfig.pages externally while every other test passes pages through makeStartConfig. The makeStartConfig helper already accepts a pages override, so this can be unified.

♻️ Proposed refactor
-    it('applies custom filter function', () => {
-      const startConfig = makeStartConfig({
-        sitemap: {
-          enabled: true,
-          host: 'https://example.com',
-          outputPath: 'sitemap.xml',
-          filter: (page: any) => page.path !== '/hidden',
-        },
-      })
-      startConfig.pages = [{ path: '/visible' }, { path: '/hidden' }]
-      buildSitemap({ startConfig, publicDir: '/dist' })
+    it('applies custom filter function', () => {
+      const startConfig = makeStartConfig({
+        pages: [{ path: '/visible' }, { path: '/hidden' }],
+        sitemap: {
+          enabled: true,
+          host: 'https://example.com',
+          outputPath: 'sitemap.xml',
+          filter: (page: any) => page.path !== '/hidden',
+        },
+      })
+      buildSitemap({ startConfig, publicDir: '/dist' })
🤖 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/start-plugin-core/tests/build-sitemap.test.ts` around lines 127 -
141, The test mutates startConfig.pages after creation; instead pass pages into
makeStartConfig to match other tests—update the test that calls
makeStartConfig({ sitemap: {...} }) so the pages array (e.g., [{ path:
'/visible' }, { path: '/hidden' }]) is provided as the pages override to
makeStartConfig, remove the external assignment to startConfig.pages, and leave
the subsequent call to buildSitemap and assertions unchanged (references:
makeStartConfig, buildSitemap).
🤖 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/start-plugin-core/src/build-sitemap.ts`:
- Around line 51-54: The current Array.filter predicate calls the user-provided
filter synchronously so async filters are ignored; change the predicate to be
async and await the filter result, e.g. make the callback async and replace the
check `if (filter && !filter(page)) return false` with `if (filter &&
!Boolean(await filter(page))) return false`, and add a JSDoc note to the
`filter` parameter (and update any schema/type for `filter` if present) to
clarify it may be async and should resolve to a truthy/falsey value; use the
same `filter` identifier in the surrounding function so the change is localized.

---

Nitpick comments:
In `@packages/start-plugin-core/tests/build-sitemap.test.ts`:
- Around line 127-141: The test mutates startConfig.pages after creation;
instead pass pages into makeStartConfig to match other tests—update the test
that calls makeStartConfig({ sitemap: {...} }) so the pages array (e.g., [{
path: '/visible' }, { path: '/hidden' }]) is provided as the pages override to
makeStartConfig, remove the external assignment to startConfig.pages, and leave
the subsequent call to buildSitemap and assertions unchanged (references:
makeStartConfig, buildSitemap).
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 23b58d2f-5746-4ef0-9b11-c0c010f7c6f3

📥 Commits

Reviewing files that changed from the base of the PR and between 4eed408 and 9961b52.

📒 Files selected for processing (5)
  • docs/start/framework/react/guide/seo.md
  • docs/start/framework/solid/guide/seo.md
  • packages/start-plugin-core/src/build-sitemap.ts
  • packages/start-plugin-core/src/schema.ts
  • packages/start-plugin-core/tests/build-sitemap.test.ts

Comment thread packages/start-plugin-core/src/build-sitemap.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Everything documentation related package: start-plugin-core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant