8000 docs: fix useHead return type by huang-julien · Pull Request #33857 · nuxt/nuxt · GitHub
[go: up one dir, main page]

Skip to content

docs: fix useHead return type#33857

Merged
danielroe merged 1 commit intomainfrom
docs/use-head-return-type
Dec 11, 2025
Merged

docs: fix useHead return type#33857
danielroe merged 1 commit intomainfrom
docs/use-head-return-type

Conversation

@huang-julien
Copy link
Member

🔗 Linked issue

fix #33834 (comment)

📚 Description

@bolt-new-by-stackblitz
Copy link

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

@coderabbitai
Copy link
Contributor
coderabbitai bot commented Dec 11, 2025

Walkthrough

The useHead composable return type has been changed from void to ActiveHeadEntry<UseHeadInput>. A new ActiveHeadEntry<Input> interface has been introduced, providing two methods: patch() for updating entries whilst clearing previous side effects, and dispose() for removing entries and queuing removal side effects. The MetaObject interface has been expanded to include additional properties such as titleTemplate, base, link, meta, style, script, noscript, htmlAttrs, and bodyAttrs, whilst retaining existing fields.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'docs: fix useHead return type' accurately summarises the main change documented in the PR, which updates the useHead composable return type from void to ActiveHeadEntry.
Description check ✅ Passed The PR description references the linked issue (#33834) and indicates the change is documentation-focused, relating to fixing the useHead return type issue.
Linked Issues check ✅ Passed Issue #33834 describes inability to remove link tags via useHead on CSR. The PR adds ActiveHeadEntry with patch() and dispose() methods, enabling tag removal through the dispose() function, directly addressing the core issue.
Out of Scope Changes check ✅ Passed All changes are directly related to expanding useHead's API with return type and new methods to enable link tag removal, aligning with the stated objective of issue #33834.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch docs/use-head-return-type

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

Caution

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

⚠️ Outside diff range comments (1)
docs/4.api/2.composables/use-head.md (1)

91-93: Update the Return Values section—current documentation contradicts the function signature.

Line 93 states "This composable does not return any value", but the signature on line 41 clearly returns ActiveHeadEntry<UseHeadInput>. This is outdated and misleading, especially since the new dispose() method directly addresses the linked issue (#33834) about removing link tags on CSR navigation.

Apply this diff to document the return value and new methods:

 ## Return Values

-This composable does not return any value. It registers the head metadata with Unhead, which manages the actual DOM updates.
+The composable returns an `ActiveHeadEntry<MetaObject>` object with the following methods:
+
+- **`patch(input: MetaObject): void`** — Updates the entry with new input. Clears any side effects for previous input before applying new changes.
+- **`dispose(): void`** — Removes the entry from the active head and queues side effects for removal. Useful for cleaning up tags when navigating away or when they should no longer appear.

Then add an example demonstrating dispose() to address the linked issue:

 ### Body and HTML Attributes

 ```vue [app/pages/themed.vue]
 <script setup lang="ts">
 const isDark = ref(true)

 useHead({
   htmlAttrs: {
     lang: 'en',
     class: computed(() => isDark.value ? 'dark' : 'light'),
   },
   bodyAttrs: {
     class: 'themed-page',
   },
 })
 </script>

+### Managing and Removing Entries
+
+```vue [app/pages/canonical.vue]
+<script setup lang="ts">
+// Capture the return value to manage the entry
+const headEntry = useHead(() => ({

  • link: [
  • {
  •  rel: 'canonical',
    
  •  href: route.fullPath,
    
  • },
  • {
  •  rel: 'alternate',
    
  •  hreflang: 'fr',
    
  •  href: route.fullPath.replace('/en/', '/fr/'),
    
  • },
  • ],
    +}))

+// When navigating or when tags should be removed:
+const removeCanonical = () => {

  • headEntry.dispose() // Removes all associated link tags
    +}

+// Or update the entry while clearing previous side effects:
+const updateCanonical = (newHref: string) => {

  • headEntry.patch({
  • link: [
  •  {
    
  •    rel: 'canonical',
    
  •    href: newHref,
    
  •  },
    
  • ],
  • })
    +}
    +</script>
    +```
🧹 Nitpick comments (1)
docs/4.api/2.composables/use-head.md (1)

40-70: Clarify the UseHeadInput type reference.

Line 41 uses a generic type UseHeadInput that is not defined in the documentation. Is this an alias for MetaObject, or a distinct type? This should be made explicit for users consuming the return value.

Consider adding a type alias definition or clarifying the relationship:

type UseHeadInput = MetaObject

or update the signature to directly reference MetaObject:

-export function useHead (meta: MaybeComputedRef<MetaObject>): ActiveHeadEntry<UseHeadInput>
+export function useHead (meta: MaybeComputedRef<MetaObject>): ActiveHeadEntry<MetaObject>
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c1b3590 and 9f9559e.

📒 Files selected for processing (1)
  • docs/4.api/2.composables/use-head.md (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: link-checker
🔇 Additional comments (2)
docs/4.api/2.composables/use-head.md (2)

74-89: Parameters section is comprehensive and accurate.

The parameter table correctly documents all properties of the MetaObject interface and provides clear descriptions for each. No changes needed.


95-182: Examples section demonstrates common use cases effectively.

All four examples correctly illustrate typical useHead() usage patterns. However, they do not demonstrate the new return value API. Once the Return Values section is updated with usage examples for dispose() and patch(), the documentation will be complete.

@danielroe danielroe merged commit 672880b into main Dec 11, 2025
8 of 9 checks passed
@danielroe danielroe deleted the docs/use-head-return-type branch December 11, 2025 23:10
@github-actions github-actions bot mentioned this pull request Dec 11, 2025
danielroe pushed a commit that referenced this pull request Dec 15, 2025
This was referenced Dec 15, 2025
@github-actions github-actions bot mentioned this pull request Jan 21, 2026
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.

Nuxt 3 | useHead - remove link-Tag (for example rel alternate or canonical)

2 participants

0