Skip to content

warmupStrategy: false still creates a preload link #826

Description

@lukas-pierce

🐛 The bug

When using useScript() with warmupStrategy: false, Nuxt Scripts still adds a <link rel="preload"> tag for the script.

In the reproduction, lodash is loaded only as an example script:

useScript(
  {
    src: 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js',
  },
  {
    warmupStrategy: false,
  }
)

Even though warmupStrategy is explicitly set to false, the page still contains a preload link for lodash.

The reproduction checks this with XPath and shows:

preloadFound: true

This seems inconsistent with the documented/type behavior where false should disable preloading.

I think the issue may be caused by this runtime check:

if (!options.warmupStrategy) {
  options.warmupStrategy = "preload";
}

Since false is a valid value for warmupStrategy, this condition treats false the same as an unset value and overrides it with "preload".
It probably should only apply the default when warmupStrategy is undefined.

🛠️ To reproduce

https://stackblitz.com/edit/nuxt-starter-duaxa3qz?file=pages%2Findex.vue

🌈 Expected behavior

When warmupStrategy: false is passed to useScript(), Nuxt Scripts should not add a <link rel="preload"> tag for that script.

Expected result in the reproduction:

preloadFound: false

ℹ️ Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions