Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

feat: @vueuse/head v1 #8908

Closed
wants to merge 12 commits into from
Closed

feat: @vueuse/head v1 #8908

wants to merge 12 commits into from

Conversation

harlan-zw
Copy link
Collaborator

@harlan-zw harlan-zw commented Nov 11, 2022

πŸ”— 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

Read the v1 @vueuse/head post for context https://harlanzw.com/blog/vue-use-head-v1

Nuxt & @vueuse/head

I have pushed this PR up to try and get it in before the v3 stable.

The DOM patching logic is more complex than the previous implementation and it's quite possible there are issues that won't be uncovered until wide testing. So while my personal testing has gone quite well, I'll leave this as a draft PR until I have a playground ready and can do some more testing.

Next Steps

In terms of development, once this is merged then I can look at implementing the rest of the new features unlocked by this:

  • add shortcut composables (includes useTagMetaFlat, solves the Meta SEO of this discussion)
  • add useServerHead, opens the door for 0kb runtime head
  • expose hooks, this will be powerful for module authors

Migration Guide

Migration Guide

(copied from the release notes)

⚠️ Breaking changes are minimal, but there are some changes to be aware of.

Please report any issues you find and they will fixed be promptly.

You may consider using @unhead/vue directly if you don't need @vueuse/head.

Verify your tags

The new DOM patching algorithm has not been tested in all possible scenarios, it's possible that there are unforeseen edge cases.

htmlAttrs and bodyAttrs merge strategy

If you had built your code around with the assumption that setting htmlAttrs or bodyAttrs would clear the old tags, this is now different.

// old
useHead({
  htmlAttrs: {
    class: 'my-class',
  },
})

useHead({
  htmlAttrs: {
    class: 'new-class',
  },
})

// <html class="new-class">
// new
useHead({
  htmlAttrs: {
    class: 'my-class',
  },
})

useHead({
  htmlAttrs: {
    class: 'new-class',
  },
})

// <html class="my-class new-class">

Check the documentation to learn more.

Duplicate tags in the same entry allowed

To make duplicate tag handling more intuitive, duplicate tags are now allowed in the same entry.

Having these metas across useHead's will still dedupe as before.

// old
useHead({
  meta: [
    { name: 'description', content: 'foo' },
    { name: 'description', content: 'bar' },
  ],
})

// only the last tag is rendered
// <meta name="description" content="bar">
// old
useHead({
  meta: [
    { name: 'description', content: 'foo' },
    { name: 'description', content: 'bar' },
  ],
})

// both are rendered
// <meta name="description" content="foo">
// <meta name="description" content="bar">

πŸ“ Checklist

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

@codesandbox
Copy link

codesandbox bot commented Nov 11, 2022

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

@netlify
Copy link

netlify bot commented Nov 11, 2022

βœ… Deploy Preview for nuxt3-docs canceled.

Name Link
πŸ”¨ Latest commit 0bf2cc9
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/636f5754f022f800070a365c

@@ -29,70 +29,3 @@ export type AppHeadMetaObject = MetaObjectRaw & {
*/
viewport?: string
}

export interface MetaObject {
Copy link
Collaborator Author

@harlan-zw harlan-zw Nov 11, 2022

Choose a reason for hiding this comment

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

I couldn't figure out why this needed to be exposed by @nuxt/schema exactly. The reactive object is only passed used as an argument for the useHead function, nuxt.config.ts uses the non-reactive schema.

The nuxt app itself exposes it as well. If we remove it then we don't need to depend on import the full module for the types

@harlan-zw
Copy link
Collaborator Author

Will need to revisit this tomorrow. Tests are looking good still but issues with this CI and getting a module up for a playground

@harlan-zw harlan-zw changed the title feat: @vueuse/head next feat: @vueuse/head v1 Nov 12, 2022
@harlan-zw
Copy link
Collaborator Author

I figured that having a proper v1 of @vueuse/head would help move this PR along, so it's now released.

The first draft of documentation for https://unhead.harlanzw.com/ is complete.

What's remaining is for me to spin up a playground and do some final nuxt-specific testing with edge cases, I hope to have that done by this time tomorrow. Aim to have it in a RC if the code is good

@harlan-zw
Copy link
Collaborator Author

Looks like I goofed up with the v1 release, didn't realise the constraint would jump from rc to 1.0.0. So in fact the nuxt core is now using v1 @vueuse/head for any new installs.

I updated it to be fully backwards compatible to unblock any users, so this PR will now just be switching over from the deprecated functions

@harlan-zw harlan-zw closed this Nov 14, 2022
@manniL
Copy link
Member

manniL commented Nov 14, 2022

@harlan-zw Will you release a v2 shortly then removing backwards compat?

@harlan-zw
Copy link
Collaborator Author

@harlan-zw Will you release a v2 shortly then removing backwards compat?

Nope, seems a backwards compat build for v3 stable is ideal, there are some ecosystem dependencies that also rely on the old API. (vuetify)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants