Skip to content

fix(queryCollectionSearchSections): fix options types#3705

Merged
farnabaz merged 3 commits intonuxt:mainfrom
hendrikheil:fix/search-sections/options-types
Feb 6, 2026
Merged

fix(queryCollectionSearchSections): fix options types#3705
farnabaz merged 3 commits intonuxt:mainfrom
hendrikheil:fix/search-sections/options-types

Conversation

@hendrikheil
Copy link
Copy Markdown
Contributor

@hendrikheil hendrikheil commented Jan 28, 2026

🔗 Linked issue


❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This PR updates the server and client types for queryCollectionSearchSections. It adds missing options like minHeading, maxHeading and extraFields and removes an unused options separators, which had no effect on the actual query.

I've also added a test for the extraFields behavior to ensure it actually works as expected.

It might be useful to export the options of generateSearchSections as a type so that they don't have to be duplicated two additional times?

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel
Copy link
Copy Markdown

vercel bot commented Jan 28, 2026

@hendrikheil is attempting to deploy a commit to the Nuxt Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 28, 2026

📝 Walkthrough

Walkthrough

The PR introduces a new exported type GenerateSearchSectionsOptions (including extraFields, ignoredTags, minHeading, maxHeading) and updates generateSearchSections to accept it. queryCollectionSearchSections in both client and server runtimes is now generic over T extends keyof PageCollections and uses GenerateSearchSectionsOptions for its options. Documentation was updated to show the extraFields option, and a unit test was added to verify that extra fields (e.g., author) are included in generated sections.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing the options types for queryCollectionSearchSections function.
Description check ✅ Passed The description is directly related to the changeset, explaining the type fixes, added options, removed unused options, and test coverage.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Copy Markdown

@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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
docs/content/docs/4.utils/4.query-collection-search-sections.md (1)

26-26: Type signature in documentation is incomplete.

The function signature in the Type section doesn't include extraFields in the options, but the API section below documents it. Update the type signature for consistency:

📝 Suggested fix
-function queryCollectionSearchSections(collection: keyof Collections, opts?: { ignoredTags?: string[], minHeading?: string, maxHeading?: string }): ChainablePromise<T, Section[]>
+function queryCollectionSearchSections(collection: keyof Collections, opts?: { ignoredTags?: string[], minHeading?: string, maxHeading?: string, extraFields?: string[] }): ChainablePromise<T, Section[]>
src/runtime/internal/search.ts (1)

30-40: Pipeline failure: Type error when spreading extraFields into select().

The widened type (string | symbol | number)[] for extraFields causes a TypeScript error at line 37 because select() expects keyof T. Since you're already casting extraFields as string[] at line 40, apply a similar cast when passing to select():

🔧 Proposed fix
   const documents = await queryBuilder
     .where('extension', '=', 'md')
-    .select('path', 'body', 'description', 'title', ...(extraFields || []))
+    .select('path', 'body', 'description', 'title', ...((extraFields || []) as string[]))
     .all()

@hendrikheil hendrikheil force-pushed the fix/search-sections/options-types branch from 379e0ec to 44050d8 Compare January 28, 2026 17:12
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Jan 28, 2026

npm i https://pkg.pr.new/@nuxt/content@3705

commit: e26fea6

Copy link
Copy Markdown

@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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/content/docs/4.utils/4.query-collection-search-sections.md (1)

48-55: Clarify that extraFields extends the section object properties.

The documentation for the return value (lines 49-55) lists the standard properties (id, title, titles, content, level) but doesn't mention that when extraFields is provided, those additional fields will also be present in each section object.

Consider adding a note like:

  - `extraFields`: An array of additional fields from the collection items to include in the section objects.
- Returns: A Promise that resolves to an array of searchable sections. Each section is an object with the following properties:
  - `id`: A unique identifier for the section.
  - `title`: The title of the section (usually the heading text).
  - `titles`: An array of parent section titles, representing the hierarchy.
  - `content`: The textual content of the section.
  - `level`: The heading level (1-6) of the section, where 1 is the highest level.
  - Any additional fields specified in the `extraFields` option will also be included in each section.

This helps users understand that the section objects are dynamically extended based on the extraFields option.

🧹 Nitpick comments (1)
docs/content/docs/4.utils/4.query-collection-search-sections.md (1)

26-26: Consider more specific types for heading level options.

The minHeading and maxHeading options are currently typed as string, which allows any string value. For better type safety and developer experience, consider using a union type:

minHeading?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'
maxHeading?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'

This would provide autocomplete suggestions and catch invalid values at compile time.

@farnabaz
Copy link
Copy Markdown
Member

farnabaz commented Feb 5, 2026

It might be useful to export the options of generateSearchSections as a type so that they don't have to be duplicated two additional times?

Thanks for the PR @hendrikheil
Could you create this type and update PR? :)

@hendrikheil
Copy link
Copy Markdown
Contributor Author

@farnabaz Done, not sure if there is a convention for the names?

Copy link
Copy Markdown
Member

@farnabaz farnabaz left a comment

Choose a reason for hiding this comment

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

Thanks 🌹

@farnabaz farnabaz merged commit b3fa025 into nuxt:main Feb 6, 2026
5 of 6 checks passed
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