Skip to content

docs: enhance documentation for Nuxt composables #32218

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

Merged
merged 7 commits into from
Jun 24, 2025
Merged

Conversation

peterbud
Copy link
Contributor

🔗 Linked issue

Contributes to #30930

📚 Description

Improving the documentation for a few Nuxt composables according to the discussion at #30930

@Copilot Copilot AI review requested due to automatic review settings May 27, 2025 11:41
@peterbud peterbud requested a review from danielroe as a code owner May 27, 2025 11:41
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request updates and enhances the documentation for several Nuxt composables. The changes include restructured parameter and return value sections, updated examples, and improved clarity in the documentation across four files.

  • Enhanced documentation for useFetch with parameter and return value tables.
  • Revised usage and type definitions for useError.
  • Updated examples and expanded details for useCookie.
  • Clarified the usage of onPrehydrate with improved type signatures and advanced key options.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
docs/3.api/2.composables/use-fetch.md Reorganized Parameters and Return Values sections with a new table format.
docs/3.api/2.composables/use-error.md Improved wording and type definitions with added Usage and Type sections.
docs/3.api/2.composables/use-cookie.md Updated document structure with clearer examples and parameter tables.
docs/3.api/2.composables/on-prehydrate.md Revised language and type annotations to clarify prehydrate usage.

}

type AsyncDataRequestStatus = 'idle' | 'pending' | 'success' | 'error'
```

## Parameters
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

Consider adding a brief introductory sentence immediately before the Parameters section to explain the role of the parameters and how they affect the fetch behavior, which may help users quickly understand what to configure.

Copilot uses AI. Check for mistakes.


```ts
interface {
// HTTP response status code
interface NuxtError<DataT = unknown> {
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding brief inline comments for the optional 'data' and 'error' fields within the NuxtError interface to further clarify their intended usage.

Copilot uses AI. Check for mistakes.


Cookie composable accepts several options which let you modify the behavior of cookies.
`options`: Options to control cookie behavior. The object can have the following properties:
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider explicitly stating that each option supports static values, refs, or computed values to reinforce the composable’s reactivity features.

Copilot uses AI. Check for mistakes.

::note
This is an advanced utility and should be used with care. For example, [`nuxt-time`](https://github.com/danielroe/nuxt-time/pull/251) and [`@nuxtjs/color-mode`](https://github.com/nuxt-modules/color-mode/blob/main/src/script.js) manipulate the DOM to avoid hydration mismatches.
::

## Usage

`onPrehydrate` can be called directly in the setup function of a Vue component (for example, in `<script setup>`), or in a plugin.
It will only have an effect when it is called on the server, and it will not be included in your client build.
Call `onPrehydrate` in the setup function of a Vue component (e.g., in `<script setup>`) or in a plugin. It only has an effect when called on the server and will not be included in your client build.
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding a note that the provided callback should avoid external dependencies as reiterated later, to prevent unexpected behavior before the Nuxt runtime initializes.

Copilot uses AI. Check for mistakes.

Copy link

coderabbitai bot commented May 27, 2025

Warning

Rate limit exceeded

@danielroe has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 56 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 8299bc7 and 0635c77.

📒 Files selected for processing (3)
  • docs/3.api/2.composables/use-cookie.md (5 hunks)
  • docs/3.api/2.composables/use-error.md (1 hunks)
  • docs/3.api/2.composables/use-fetch.md (1 hunks)

Walkthrough

The documentation for several composable functions was revised to enhance clarity, detail, and structure. The onPrehydrate documentation now includes consolidated descriptions, overload TypeScript signatures, a parameter table, and clarified return values. The useCookie documentation was extensively restructured, featuring a detailed options table, explicit TypeScript signatures, and reorganised usage examples. The useError documentation was expanded with a comprehensive usage explanation, explicit type definitions, and example code. The useFetch documentation was reformatted for consistency, with detailed parameter and return value tables, but no changes to TypeScript signatures or core examples. No functional code changes were made.

✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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

🧹 Nitpick comments (2)
docs/3.api/2.composables/on-prehydrate.md (2)

26-29: Refine TypeScript overload signatures.
Consider making the second overload’s return type strictly string and requiring the key parameter to avoid overload ambiguity. For example:

export function onPrehydrate(callback: (el: HTMLElement) => void): void;
export function onPrehydrate(callback: string | ((el: HTMLElement) => void), key: string): string;

49-52: Clarify example comment wording.
To explicitly indicate client-side prehydrate execution, consider rephrasing:

- // Run code before Nuxt hydrates
+ // Run this callback on the client immediately before hydration
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f6b8cd8 and b8a2eea.

📒 Files selected for processing (1)
  • docs/3.api/2.composables/on-prehydrate.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/3.api/2.composables/on-prehydrate.md

[uncategorized] ~15-~15: Loose punctuation mark.
Context: ...ediately before Nuxt hydrates the page. ::note This is an advanced utility and sh...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~17-~17: Loose punctuation mark.
Context: ... the DOM to avoid hydration mismatches. :: ## Usage Call onPrehydrate in the ...

(UNLIKELY_OPENING_PUNCTUATION)

🔇 Additional comments (5)
docs/3.api/2.composables/on-prehydrate.md (5)

15-15: Concise hook description.
The one-line overview clearly explains the purpose of onPrehydrate.

🧰 Tools
🪛 LanguageTool

[uncategorized] ~15-~15: Loose punctuation mark.
Context: ...ediately before Nuxt hydrates the page. ::note This is an advanced utility and sh...

(UNLIKELY_OPENING_PUNCTUATION)


22-22: Usage section is precise.
It correctly notes server-side registration and exclusion from the client bundle.


33-37: Parameter table is comprehensive and clear.
The descriptions clearly state the requirements and limitations for both callback and key. Nice work!


54-58: Example for root element access is clear.
The snippet effectively demonstrates how to inspect the element passed to the callback.


60-60: Advanced usage note is helpful.
The comment appropriately signals the advanced nature of manually handling the data-prehydrate-id.

Copy link

@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

♻️ Duplicate comments (1)
docs/3.api/2.composables/use-cookie.md (1)

57-71: Re-emphasise that option values can be static or reactive

It is still not obvious that every property in the options object may be passed as a static literal or as a ref/computed for full reactivity at runtime. An explicit sentence (as suggested previously) would avoid any ambiguity for newcomers.

🧹 Nitpick comments (2)
docs/3.api/2.composables/use-cookie.md (2)

90-96: Avoid implicit ref reassignment in the template snippet

counter is a Ref, and Vue’s template compiler rewrites counter++/counter = null to counter.value++/counter.value = null internally.
That magic is handy, but showing the explicit .value access keeps the example unambiguous for readers who copy-paste the code into plain JS/TS (e.g. inside composables or composable helpers) where the rewrite does not happen.

-<button @click="counter = null">reset</button>
-<button @click="counter--">-</button>
-<button @click="counter++">+</button>
+<button @click="counter.value = null">reset</button>
+<button @click="counter.value--">-</button>
+<button @click="counter.value++">+</button>

62-62: Minor grammar – add a hyphen to “top-level”

- i.e. data changes for only top level properties
+ i.e. data changes for only top-level properties
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b8a2eea and 8299bc7.

📒 Files selected for processing (1)
  • docs/3.api/2.composables/use-cookie.md (5 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/3.api/2.composables/use-cookie.md

[uncategorized] ~24-~24: Loose punctuation mark.
Context: ... and deserialize cookie values to JSON. :: # Type ```ts [Signature] import type...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~51-~51: Loose punctuation mark.
Context: ...: CookieRef ``` # Parameters name: The name of the cookie. `options`: Opt...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~53-~53: Loose punctuation mark.
Context: ...ame: The name of the cookie. options`: Options to control cookie behavior. The...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~62-~62: If this is a compound adjective that modifies the following noun, use a hyphen.
Context: ...allow watch, i.e. data changes for only top level properties, false to disable.
*...

(EN_COMPOUND_ADJECTIVE_INTERNAL)


[uncategorized] ~62-~62: A punctuation mark might be missing here.
Context: ...manually when a cookie has changed with [refreshCookie](/docs/api/utils/refresh-...

(AI_EN_LECTOR_MISSING_PUNCTUATION)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: lint-docs

Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

thank you ❤

@danielroe danielroe merged commit 6ff7850 into nuxt:main Jun 24, 2025
7 of 8 checks passed
@github-actions github-actions bot mentioned this pull request Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy