Skip to content
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

fix!: only handle promise input when opted in #445

Merged
merged 3 commits into from
Jan 7, 2025
Merged

Conversation

harlan-zw
Copy link
Collaborator

@harlan-zw harlan-zw commented Jan 7, 2025

πŸ”— Linked issue

#368

❓ 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)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Promise support was initially added to Unhead to support lazy resolved file paths using Vite imports.

useServerHead({
  link: [
    {
      // promises supported
      href: import('~/assets/MyFont.css?url'),
      rel: 'stylesheet',
      type: 'text/css'
    }
  ]
})

While this feature did somewhat work it only did for the above example and was not used as far as I'm aware.

Promises add a lot of overhead in terms of performance optimization and extra weight to handle. To simplify the on-going maintenance of the package we drop support for them.

⚠️ Breaking Change

If you have promises as input they will no longer be resolved, either await the promise before passing it along or register the optional promises plugin.

Option 1: Await Promise

useHead({
  link: [
    {
-     href: import('~/assets/MyFont.css?url'),
+     href: await import('~/assets/MyFont.css?url'),
      rel: 'stylesheet',
      type: 'text/css'
    }
  ]
})

Option 2: Promise Plugin

import { PromisePlugin } from 'unhead/optionalPlugins'

const unhead = createHead({
  plugins: [PromisePlugin]
})

@harlan-zw harlan-zw changed the title fix!: drop promise input support fix!: only handle promises when opted in Jan 7, 2025
@harlan-zw harlan-zw changed the title fix!: only handle promises when opted in fix!: only handle promise input when opted in Jan 7, 2025
@harlan-zw harlan-zw mentioned this pull request Jan 7, 2025
16 tasks
@harlan-zw harlan-zw merged commit af0afbf into main Jan 7, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant