Skip to content

Conversation

@peterbud
Copy link
Contributor

@peterbud peterbud commented Nov 1, 2025

🔗 Linked issue

Contributes to #30930

📚 Description

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

@peterbud peterbud requested a review from danielroe as a code owner November 1, 2025 13:31
@bolt-new-by-stackblitz
Copy link

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

@coderabbitai
Copy link

coderabbitai bot commented Nov 1, 2025

Walkthrough

This pull request expands and restructures documentation for five composables within the API reference: useHeadSafe, useHead, useHydration, useLazyAsyncData, and useLazyFetch. The changes introduce consistent structural improvements across all files, including dedicated Usage sections with Vue code examples, Type signatures, Parameters tables, and Return Values sections. Notable additions include explicit security rationale and allowed attributes whitelist for useHeadSafe, reactive usage patterns for useHead, and clarifications on lazy-loading behaviour for useLazyAsyncData and useLazyFetch. One type signature correction addresses a stray character in the useHydration function signature, changing set: (value: T) => v to the correct set: (value: T) => void. All changes are documentation-only with no alterations to public API declarations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

  • Type signature correction in use-hydration.md (the vvoid fix) should be verified for accuracy
  • Vue code examples across all five files should be checked for syntax correctness and practical applicability
  • Security-related content in use-head-safe.md (XSS rationale and attribute whitelist) warrants verification against actual implementation
  • Consistency of structural patterns (Usage, Type, Parameters, Return Values sections) across the five files should be spot-checked for completeness

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title "docs: enhance documentation for Nuxt composables" accurately reflects the primary change in the pull request. The raw summary confirms that all five modified files (use-head-safe.md, use-head.md, use-hydration.md, use-lazy-async-data.md, and use-lazy-fetch.md) contain comprehensive documentation enhancements including expanded guides, restructured content, code examples, and corrected type signatures. The title is concise, specific, and clearly communicates that this is a documentation improvement PR focused on composables, meeting the standard for a well-scoped PR title.
Description Check ✅ Passed The description is clearly related to the changeset. It explicitly states the PR is "improving the documentation for a few Nuxt composables according to the discussion at #30930," which directly aligns with the raw summary showing extensive documentation rewrites and enhancements across multiple composable documentation files. The reference to the linked issue provides appropriate context for the changes. Although the description is brief, it contains sufficient detail to relate to the actual changes being made.
✨ Finishing touches
🧪 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

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 456cc36 and 4f5e1e6.

📒 Files selected for processing (5)
  • docs/3.api/2.composables/use-head-safe.md (3 hunks)
  • docs/3.api/2.composables/use-head.md (2 hunks)
  • docs/3.api/2.composables/use-hydration.md (3 hunks)
  • docs/3.api/2.composables/use-lazy-async-data.md (1 hunks)
  • docs/3.api/2.composables/use-lazy-fetch.md (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-09-10T14:42:56.647Z
Learnt from: Tofandel
Repo: nuxt/nuxt PR: 33192
File: test/nuxt/use-async-data.test.ts:366-373
Timestamp: 2025-09-10T14:42:56.647Z
Learning: In the Nuxt useAsyncData test "should watch params deeply in a non synchronous way", the foo watcher intentionally updates both params.foo and params.locale using locale.value, simulating a scenario where one watcher consolidates multiple reactive values into a shared params object for testing debounced/non-synchronous behavior.

Applied to files:

  • docs/3.api/2.composables/use-lazy-async-data.md
📚 Learning: 2024-11-05T20:04:39.622Z
Learnt from: Tofandel
Repo: nuxt/nuxt PR: 26468
File: packages/nuxt/src/components/runtime/client-delayed-component.ts:62-62
Timestamp: 2024-11-05T20:04:39.622Z
Learning: In Vue components, when typing the `hydrate` prop for hydration strategies like `hydrateOnInteraction`, use `type: null as PropType<Arguments<typeof hydrateOnInteraction>[0]>` to get the type directly from Vue's hydration methods. Also, remember that `HTMLElementEventMap` is not a type but an object; use `keyof HTMLElementEventMap` when defining prop types for events.

Applied to files:

  • docs/3.api/2.composables/use-hydration.md
🪛 LanguageTool
docs/3.api/2.composables/use-lazy-async-data.md

[uncategorized] ~12-~12: Loose punctuation mark.
Context: ...y setting the lazy option to true. ::note By default, [useAsyncData](/docs...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~14-~14: Loose punctuation mark.
Context: ...a fetching continues in the background. :: ## Usage ```vue [app/pages/index.vue...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~34-~34: Loose punctuation mark.
Context: ...ctly within your component's template. ::warning useLazyAsyncData is a reserve...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~36-~36: Loose punctuation mark.
Context: ...e your own function useLazyAsyncData. :: ## Type ```ts [Signature] export fun...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~59-~59: Loose punctuation mark.
Context: ...yoption automatically set totrue`. :read-more{to="/docs/4.x/api/composables/...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~65-~65: Loose punctuation mark.
Context: ...s/4.x/api/composables/use-async-data). :read-more{to="/docs/4.x/api/composables/...

(UNLIKELY_OPENING_PUNCTUATION)

docs/3.api/2.composables/use-head-safe.md

[uncategorized] ~30-~30: Loose punctuation mark.
Context: ..."0;javascript:alert(1)"> </script> ``` ::warning When using useHeadSafe, poten...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~32-~32: Loose punctuation mark.
Context: ...re working with user-generated content. :: ## Type ```ts [Signature] export fun...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~61-~61: Loose punctuation mark.
Context: ... detailed types. ## Parameters input: A MaybeComputedRef<HeadSafe> object c...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~85-~85: Loose punctuation mark.
Context: ...sanitized }, ], }) </script> ``` ::read-more{to="https://unhead.unjs.io/do...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~87-~87: Loose punctuation mark.
Context: ...ead more on the Unhead documentation. ::

(UNLIKELY_OPENING_PUNCTUATION)

docs/3.api/2.composables/use-head.md

[uncategorized] ~29-~29: Loose punctuation mark.
Context: ...('Hello world')' }] }) </script> ``` ::warning If the data comes from a user o...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~31-~31: Loose punctuation mark.
Context: ...ocs/4.x/api/composables/use-head-safe). :: ::note The properties of useHead ca...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~33-~33: Loose punctuation mark.
Context: ...4.x/api/composables/use-head-safe). :: ::note The properties of useHead can be...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~35-~35: Loose punctuation mark.
Context: ...ect to make the entire object reactive. :: ## Type ```ts [Signature] export fun...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~61-~61: Loose punctuation mark.
Context: ...e detailed types. ## Parameters meta: An object accepting head metadata prope...

(UNLIKELY_OPENING_PUNCTUATION)


[style] ~66-~66: To form a complete sentence, be sure to include a subject or ‘there’.
Context: ...c template to customize the page title. Can be a string with %s placeholder or a ...

(MISSING_IT_THERE)


[misspelling] ~69-~69: This word is normally spelled as one.
Context: ...butes. | | meta | Meta[] | Array of meta objects. Each element is mapped to a <meta> t...

(EN_COMPOUNDS_META_OBJECTS)


[uncategorized] ~168-~168: Loose punctuation mark.
Context: ...ss: 'themed-page' } }) </script> ``` :read-more{to="/docs/4.x/getting-started/...

(UNLIKELY_OPENING_PUNCTUATION)

docs/3.api/2.composables/use-hydration.md

[uncategorized] ~11-~11: Possible missing comma found.
Context: ...eive that data on the client side. This way useHydration allows you to take full ...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~12-~12: Loose punctuation mark.
Context: ...e full control of the hydration cycle. ::note This is an advanced composable, pr...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~24-~24: Loose punctuation mark.
Context: ...g redundant computations or API calls. ::code-group ```ts [With useHydration] e...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~70-~70: Possible missing article found.
Context: ...ted only on the client (called when initial Vue instance is created) to receive the...

(AI_HYDRA_LEO_MISSING_THE)

docs/3.api/2.composables/use-lazy-fetch.md

[uncategorized] ~33-~33: Loose punctuation mark.
Context: ...-> ``` ::note useLazyFetch has the same signat...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~35-~35: Loose punctuation mark.
Context: ...](/docs/4.x/api/composables/use-fetch). :: ::warning Awaiting useLazyFetch onl...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~37-~37: Loose punctuation mark.
Context: ...ocs/4.x/api/composables/use-fetch). :: ::warning Awaiting useLazyFetch only en...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~39-~39: Loose punctuation mark.
Context: ...ngstate in your component's template. :: ::warninguseLazyFetch` is a reserve...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~41-~41: Loose punctuation mark.
Context: ...state in your component's template. :: ::warning useLazyFetch is a reserved fu...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~43-~43: Loose punctuation mark.
Context: ... name your own function useLazyFetch. :: ## Type ```ts [Signature] export fun...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~54-~54: Loose punctuation mark.
Context: ... Promise<AsyncData<DataT, ErrorT>> ``` ::note useLazyFetch is equivalent to `u...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~56-~56: Loose punctuation mark.
Context: ...s/use-fetch) for full type definitions. :: ## Parameters useLazyFetch accepts...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~65-~65: Loose punctuation mark.
Context: ...th lazy automatically set to true. :read-more{to="/docs/4.x/api/composables/...

(UNLIKELY_OPENING_PUNCTUATION)


[uncategorized] ~80-~80: Loose punctuation mark.
Context: ...`, and cancels any pending requests. | :read-more{to="/docs/4.x/api/composables/...

(UNLIKELY_OPENING_PUNCTUATION)

🔇 Additional comments (3)
docs/3.api/2.composables/use-hydration.md (2)

11-11: Minor grammar: missing article in parameter description.

Line 11 contains accurate information, but the static analysis flag for line 70 is legitimate.


61-61: Type signature correction is accurate.

The fix from set: (value: T) => v to set: (value: T) => void is correct and necessary. The incorrect v was a typo that would have caused confusion. ✓

docs/3.api/2.composables/use-lazy-async-data.md (1)

1-90: Solid documentation enhancement with clear structure and accurate technical content.

The restructured documentation effectively communicates the purpose and usage of useLazyAsyncData through well-organized sections. The Vue usage example (lines 19–31) correctly demonstrates proper destructuring of status and data properties, whilst the template shows appropriate conditional rendering for pending and error states. The type signatures are presented clearly, the compiler warning about naming conventions is appropriate and useful, and cross-references to the parent useAsyncData composable maintain consistency without repeating detailed parameter documentation.

The static analysis warnings flagged are false positives related to Markdown syntax elements (::-delimited blocks and :read-more{} components), which are correct documentation formatting.

Comment on lines +63 to +66
| Property | Type | Description |
| --- | --- | --- |
| `title` | `string` | Sets the page title. |
| `titleTemplate` | `string \| ((title?: string) => string)` | Configures a dynamic template to customize the page title. Can be a string with `%s` placeholder or a function. |
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Minor grammar: sentence lacks subject in parameters table.

Line 66 should include a subject pronoun. Current text: "Can be a string with…" should be: "It can be a string with %s placeholder or a function."

Apply this diff:

-| `titleTemplate` | `string \| ((title?: string) => string)` | Configures a dynamic template to customize the page title. Can be a string with `%s` placeholder or a function. |
+| `titleTemplate` | `string \| ((title?: string) => string)` | Configures a dynamic template to customise the page title. It can be a string with `%s` placeholder or a function. |
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
| Property | Type | Description |
| --- | --- | --- |
| `title` | `string` | Sets the page title. |
| `titleTemplate` | `string \| ((title?: string) => string)` | Configures a dynamic template to customize the page title. Can be a string with `%s` placeholder or a function. |
| Property | Type | Description |
| --- | --- | --- |
| `title` | `string` | Sets the page title. |
| `titleTemplate` | `string \| ((title?: string) => string)` | Configures a dynamic template to customise the page title. It can be a string with `%s` placeholder or a function. |
🧰 Tools
🪛 LanguageTool

[style] ~66-~66: To form a complete sentence, be sure to include a subject or ‘there’.
Context: ...c template to customize the page title. Can be a string with %s placeholder or a ...

(MISSING_IT_THERE)

🤖 Prompt for AI Agents
In docs/3.api/2.composables/use-head.md around lines 63 to 66, the parameters
table entry for titleTemplate uses the fragment "Can be a string with `%s`
placeholder or a function." — update that sentence to include a subject pronoun
by changing it to "It can be a string with `%s` placeholder or a function." so
the sentence is grammatically complete.

Comment on lines +66 to +70
| Parameter | Type | Description |
| --- | --- | --- |
| `key` | `string` | A unique key that identifies the data in your Nuxt application. |
| `get` | `() => T` | A function executed **only on the server** (called when SSR rendering is done) to set the initial value. |
| `set` | `(value: T) => void` | A function executed **only on the client** (called when initial Vue instance is created) to receive the data. |
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Minor grammar: add missing article in parameter table.

Line 70 should read: "A function executed only on the client (called when the initial Vue instance is created)…"

Apply this diff:

-| `set` | `(value: T) => void` | A function executed **only on the client** (called when initial Vue instance is created) to receive the data. |
+| `set` | `(value: T) => void` | A function executed **only on the client** (called when the initial Vue instance is created) to receive the data. |
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
| Parameter | Type | Description |
| --- | --- | --- |
| `key` | `string` | A unique key that identifies the data in your Nuxt application. |
| `get` | `() => T` | A function executed **only on the server** (called when SSR rendering is done) to set the initial value. |
| `set` | `(value: T) => void` | A function executed **only on the client** (called when initial Vue instance is created) to receive the data. |
| Parameter | Type | Description |
| --- | --- | --- |
| `key` | `string` | A unique key that identifies the data in your Nuxt application. |
| `get` | `() => T` | A function executed **only on the server** (called when SSR rendering is done) to set the initial value. |
| `set` | `(value: T) => void` | A function executed **only on the client** (called when the initial Vue instance is created) to receive the data. |
🧰 Tools
🪛 LanguageTool

[uncategorized] ~70-~70: Possible missing article found.
Context: ...ted only on the client (called when initial Vue instance is created) to receive the...

(AI_HYDRA_LEO_MISSING_THE)

🤖 Prompt for AI Agents
In docs/3.api/2.composables/use-hydration.md around lines 66 to 70, the "set"
parameter description is missing the article "the"; update the text so it reads:
"A function executed **only on the client** (called when the initial Vue
instance is created) to receive the data." Replace the existing sentence
accordingly to include the article "the".

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 c620f47 into nuxt:main Nov 3, 2025
9 of 10 checks passed
@github-actions github-actions bot mentioned this pull request Nov 3, 2025
@peterbud peterbud deleted the docs-composables branch November 3, 2025 20:16
@github-actions github-actions bot mentioned this pull request Nov 6, 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