Skip to content

Safari: useHead() was called without provide context #5229

@tnld

Description

@tnld

Environment

Is this bug related to Nuxt or Vue?

Nuxt

Package

v4.x

Version

v4.0.1

Reproduction

I wasn't able to reproduce this error in a new repo yet. It also doesn't always seem to occur right away, but only after Safari has been open for some time.

I will add a reproduction if I find a way to always reproduce the error.

Description

When running our Nuxt 4 project locally with Nuxt UI 4.0.1, Safari (latest version on macOS and iOS) fails during page rendering with:

useHead() was called without provide context, ensure you call it through the setup() function.

The stack trace always points to Nuxt UI’s runtime/plugins/colors.js, specifically the useHead(headData) call. Chrome and Firefox work fine; only Safari exhibits the crash. The app shows a brief flash of the content and then a blank screen (or the error page if using the default Nuxt one without any UI components).

Additional context

Workaround/Notes
We temporarily worked around it by:

  • Delaying the useHead call until app:created.
  • Registering nuxt-ui-colors output via a custom plugin that runs after Nuxt’s head provider is definitely available.

Those hacks seem to fix it, but they suggest the built-in plugin sometimes runs before the head injection is established (Safari timing quirk).

Any guidance or patch to ensure the colors plugin waits for the head context would be much appreciated.

ui-head-delay.ts

Logs

useHead() was called without provide context, ensure you call it through the setup() function.

useHead@https://server.local:3000/_nuxt/@fs/Users/tnld/dev/project/node_modules/@unhead/vue/dist/shared/vue.Bm-NbY4b.mjs:31:58
@https://server.local:3000/_nuxt/@fs/Users/tnld/dev/project/node_modules/@nuxt/ui/dist/runtime/plugins/colors.js:53:10
runWithContext@https://server.local:3000/_nuxt/@fs/Users/tnld/dev/project/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js:4082:20
run@https://server.local:3000/_nuxt/@fs/Users/tnld/dev/project/node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js:67:18
@https://server.local:3000/_nuxt/@fs/Users/tnld/dev/project/node_modules/nuxt/dist/app/nuxt.js:138:53
applyPlugin@https://server.local:3000/_nuxt/@fs/Users/tnld/dev/project/node_modules/nuxt/dist/app/nuxt.js:136:35
@https://server.local:3000/_nuxt/@fs/Users/tnld/dev/project/node_modules/nuxt/dist/app/nuxt.js:157:34
executePlugin@https://server.local:3000/_nuxt/@fs/Users/tnld/dev/project/node_modules/nuxt/dist/app/nuxt.js:152:34
@https://server.local:3000/_nuxt/@fs/Users/tnld/dev/project/node_modules/nuxt/dist/app/nuxt.js:193:24

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageAwaiting initial review and prioritizationv4#4488

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions