Skip to content

feat(head): improved Unhead integration - #19302

Closed
harlan-zw wants to merge 21 commits into
mainfrom
feat/improved-unhead-integration
Closed

feat(head): improved Unhead integration#19302
harlan-zw wants to merge 21 commits into
mainfrom
feat/improved-unhead-integration

Conversation

@harlan-zw

@harlan-zw harlan-zw commented Feb 27, 2023

Copy link
Copy Markdown
Contributor

🔗 Linked issue

unjs/unhead#116, #15668

❓ 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

Unhead v1.1.0 was recently released.

With the dep update, I figure it's a good time to improve the integration:

PR To Do

  • benchmark v1.1
  • test treeshaking

Features

Dropping @vueuse/head dependency

To avoid breaking a bunch of third-party packages, the dependency was kept on @vueuse/head, which acted as a simple compatibility wrapper for Unhead. While we still need some support for this, Unhead now exports the compatibility layer directly.

This gives finer control over what's imported, allowing for better tree-shaking. For example, @unhead/dom should be treeshaken from the server build now.

Support app.head.options

While there are minimal build-time options available for Unhead, this is needed to enable experimentalHashHydration which I'm going to enable for nuxt-unhead. It will be enabled in the future by default but want to test it out a bit first.

SSR: Skip app.head entry client-side

This provides a performance improvement for SSR apps, fixes the bug unjs/unhead#116 and allows for experimentalHashHydration.

export default defineNuxtConfig({
  app: {
    head: {
      options: {
        experimentalHashHydration: true
      }
    }
  }
})

New composables

useServerSeoMeta - Basically what was already available but it provides a { mode: 'server' } which allows for the experimental hash hydration

useHeadSafe / useServerHeadSafe - Bit verbose having both but we need the server function for the above and to treeshake it from the client build (once the vite plugin is implemented)

Unhead Unplugin

  • Treeshakes server components
  • Transforms useSeoMeta (saves ~2kb gzipd)

Todo (subsequent PRs?)

The following items are things I'd like to solve but I don't think can exist within this PR.

Expose Unhead Hooks

These are pretty easy to implement but not sure if this PR is the best spot for them. They're currently not documented within the Unhead docs so should probably sort that out first.

Document Template Params

These are mainly used for lower-level integrations at this point.

📝 Checklist

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

@codesandbox

codesandbox Bot commented Feb 27, 2023

Copy link
Copy Markdown

CodeSandbox logoCodeSandbox logo  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

} else {
head = createHead<HeadAugmentations>(headOptions)
// only in SPA mode do we need to push the appHead client side
if (nuxtApp.ssrContext?.noSSR) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is this the correct way to check for SPA?

@harlan-zw harlan-zw changed the title feat(head): improved Unhead 1.1.x integration feat(head): improved Unhead integration Feb 27, 2023
@danielroe

Copy link
Copy Markdown
Member

@harlan-zw I think a fair amount of this has been merged in other PRs. But I think there's still some stuff here we would want to merge in, right?

@harlan-zw

Copy link
Copy Markdown
Contributor Author

Thanks for the ping. I'll close for now and create separate PRs where appropriate.

@harlan-zw harlan-zw closed this Mar 20, 2023
@danielroe
danielroe deleted the feat/improved-unhead-integration branch September 3, 2024 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants